Skip to main content

acctf

acctfは、銀行や証券会社をスクレイピングして入出金履歴、株や投信の保有数や取得価額、現在価格を取得するライブラリです。

下記の銀行や証券会社等に対応しています。

証券会社

  • SBI証券
    • 円建て
      • 株式
        • 株式(現物)
      • 投信
        • 投資信託(金額/特定預り)
        • 投資信託(金額/NISA預り(つみたて投資枠))
        • 投資信託(金額/旧つみたてNISA預り)
    • 外貨建て(USのみ)
      • 株式
        • 株式(現物)

銀行

  • みずほ銀行(円のみ)
    • 預金
    • 入出金履歴
  • 住信SBIネット銀行
    • 預金(ハイブリッド含む)(円のみ)
    • 入出金履歴
      • 代表口座
      • ハイブリッド預金口座
      • 目的別口座

その他

  • WealthNavi(円表示のみ)
    • 各資産クラス

利用方法

インストール

pip install acctf

サンプル

証券会社

from acctf.securities.sbi import SBI
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)

sbi = SBI(driver=driver).login("<ユーザID>", "<パスワード>")
stocks = sbi.get_stock_specific()
print("銘柄, 数量, 取得単価, 現在値")
for s in stocks:
  print(f"{s.name}, {s.amount}, {s.acquisition_value}, {s.current_value}")

sbi.logout()
sbi.close()
銘柄, 数量, 取得単価, 現在値
0000 銘柄1, 1000, 1234, 2345
1111 銘柄2, 1500, 789, 987
2222 銘柄3, 2000, 3450, 3456

銀行

預金

from acctf.bank.mizuho import Mizuho
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)

mizuho = Mizuho(driver=driver).login("<ユーザID>", "<パスワード>")
b = mizuho.get_balance("7654321")
print(f"口座番号, 店舗, 残高, 口座タイプ")
print(f"{b[0].account_number}, {b[0].branch_name}, {b[0].value}, {b[0].deposit_type}")

mizuho.logout()
mizuho.close()
口座番号, 店舗, 残高, 口座タイプ
7654321, 本店, 1234567.0, DepositType.ordinary

入出金履歴

下記はみずほ銀行の例です。

from acctf.bank.mizuho import Mizuho
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)

mizuho = Mizuho(driver=driver).login("<ユーザID>", "<パスワード>")
hist = mizuho.get_transaction_history("7654321")
# You can also specify the start/end date.
# hist = mizuho.get_transaction_history("7654321", date(2023, 12, 1), date(2023, 12, 31))
print(f"日付, 取引内容, 金額")
for h in hist:
  print(f"{h.date}, {h.content}, {h.value}")

mizuho.logout()
mizuho.close()
日付, 取引内容, 金額
2023-12-01, ATM引き出し, -10000.0
2024-12-20, 給与, 200000.0

住信SBIネット銀行はUIの変更に伴い、履歴のCSVをダウンロードしてデータを取得する方式に変更しました。そのため、ドライバの設定時にダウンロードディレクトリを指定してください。 また、ダウンロードしたCSVファイルはデータ取得後に削除されます。

from pathlib import Path

from acctf.bank.sbi import SBI
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from datetime import date

from acctf.bank.sbi import AccountName
from acctf.bank import CurrencyType

download_directory = str(Path.cwd()) + "/tmp"
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_experimental_option("prefs", {
  "download.default_directory": download_directory,
})
driver = webdriver.Chrome(options=options)

# Firefoxを利用する場合
# options = webdriver.FirefoxOptions()
# options.add_argument("-headless")
# options.set_preference("browser.download.folderList", 2)
# options.set_preference("browser.download.dir", download_directory)
# service = webdriver.FirefoxService()
# driver = webdriver.Firefox(service=service, options=options)

sbi = SBI(driver=driver).login("<ユーザID>", "<パスワード>")
hist = sbi.get_transaction_history(
  "7654321",
  date(2023, 12, 1),
  date(2023, 12, 31),
  download_directory=download_directory,
  currency=CurrencyType.jpy,
  account_name=AccountName.Representative # 代表口座
)
hist += sbi.get_transaction_history(
  "7654321",
  date(2023, 12, 1),
  date(2023, 12, 31),
  download_directory=download_directory,
  currency=CurrencyType.jpy,
  account_name=AccountName.Hybrid # ハイブリッド預金口座
)

print(f"日付, 取引内容, 金額")
for h in hist:
  print(f"{h.date}, {h.content}, {h.value}")

sbi.logout()
sbi.close()

その他

WealthNavi

from acctf.other.wealthnavi import WealthNavi
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(options=options)

w = WealthNavi(driver=driver).login("<ユーザID>", "<パスワード>", "<TOTP>")
# Time-based One Time Passwordを設定していない場合
# w = WealthNavi().login("<ユーザID>", "<パスワード>")
print("資産クラス, 現在価格, 損益")
for h in w.get_valuation():
  print(f"{h.name}, {h.value}, {h.pl_value}")

w.logout()
w.close()
資産クラス, 現在価格, 損益
米国株(VTI), 123456.0, 12345.0
日欧株(VEA), 123456.0, 12345.0
新興国株(VWO), 123456.0, 12345.0
債券(AGG), 123456.0, 12345.0
金(GLD), 123456.0, 12345.0
金(IAU), 123456.0, 12345.0
不動産(IYR), 123456.0, 12345.0
現金, 123456.0, 0.0

Metadata

Release files for acctf 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acctf 0.5.2
File Size Uploaded Provenance Actions
acctf-0.5.2.tar.gz 13.7 kB Without provenance Details for acctf-0.5.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for acctf 0.5.2
File Interpreter ABI Platform Actions
acctf-0.5.2-py3-none-any.whl Python 3 none any Details for acctf-0.5.2-py3-none-any.whl

Total release size: 30.2 kB

Release files / acctf-0.5.2.tar.gz

Download URL acctf-0.5.2.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1c5ea7d4cb0595c47d48c14b2dcb8374f8370cddc426f47b7146c336e30b3997
BLAKE2b-256 checksum
How to use checksums
8e91d8262ea41a6274f23976bec17c5957d7bd04db019b35a46f02521978b07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / acctf-0.5.2-py3-none-any.whl

Download URL acctf-0.5.2-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c05eb9b301795c301cba1ac8520dfa65d6649a8100250feea45bbe2040d7eb4
BLAKE2b-256 checksum
How to use checksums
09206f68709e197e01fd645dbbb6f2b818bd36f9d213f416af47dc413d02aa89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for acctf 0.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page