SBI証券の取引データをパースするPythonライブラリ
Project description
insighta-sbi-parser
SBI証券からダウンロードした取引データ(HTML/CSV)を構造化されたPythonオブジェクトに変換するライブラリです。
インストール
pip install insighta-sbi-parser
使い方
ディレクトリ一括パース
from insighta_sbi_parser import process_sbi_dir
result = process_sbi_dir("path/to/sbi_files/")
for trade in result.trades:
print(f"{trade.dt} {trade.ticker} {trade.qty}株 @{trade.price}")
for holding in result.holdings:
print(f"{holding.ticker} {holding.qty}株 損益:{holding.pnl}")
for deposit in result.deposits:
print(f"{deposit.dt} {deposit.amount} {deposit.cur} ({deposit.type})")
為替レート付きパース
result = process_sbi_dir("path/to/sbi_files/", rate_file="rate.csv")
rate.csv 形式:
date,rate
2024/01/15,148.50
2024/01/16,149.20
ファイル個別パース
from insighta_sbi_parser import classify, parse_history_html, parse_yakujo_csv
# ファイル種類を自動判定
file_type = classify("some_file.csv") # → "history_csv", "deposit_transfer", etc.
# 個別パーサー
trades, skipped = parse_history_html("order_history.html")
対応フォーマット
| 種類 | 形式 | 関数 |
|---|---|---|
| 注文履歴 | HTML | parse_history_html() |
| 保有銘柄一覧 | HTML | parse_summary_html() |
| 約定履歴 | CSV (Shift_JIS) | parse_yakujo_csv() |
| 国内投信取引 | CSV (Shift_JIS) | parse_domestic_fund() |
| 入出金振替 | CSV (UTF-8) | parse_transfer() |
| 外貨入出金 | CSV (UTF-8) | parse_gaika_nyushukkin() |
| 為替取引 | CSV (Shift_JIS) | parse_exchange() |
| 配当金 | CSV (Shift_JIS) | parse_distribution() |
データモデル
@dataclass
class Trade:
dt: str # ISO 8601 (JST)
ticker: str # ティッカーシンボル
qty: int # 数量 (売りはマイナス)
acct: str # 口座区分 ("TT"=特定, "NISA")
price: Decimal # 現在値
avg: Decimal # 平均約定単価
cur: str # 決済通貨
base: str # 基準通貨
@dataclass
class Holding:
ticker: str
acct: str
qty: int
cost: Decimal # 取得単価
price: Decimal # 現在値
pnl: Decimal # 損益
@dataclass
class Deposit:
dt: str
amount: Decimal # 金額 (出金はマイナス)
cur: str # 通貨
type: str # "budget" | "dividend"
ticker: str # 関連銘柄 (任意)
rate: Decimal | None # 為替レート (任意)
ファイルの取得方法
SBI証券のWebサイトから以下の手順でダウンロードできます:
- 注文履歴HTML: 外国株式 → 注文照会 → ページをHTMLとして保存
- 保有銘柄HTML: 外国株式 → 口座管理 → ページをHTMLとして保存
- 約定履歴CSV: 外国株式 → 取引履歴 → CSVダウンロード
- 入出金CSV: 入出金・振替 → 操作履歴 → CSVダウンロード
Contributing
git clone https://github.com/insighta-cloud/insighta-sbi-parser.git
cd insighta-sbi-parser
pip install -e ".[dev]"
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file insighta_sbi_parser-0.1.0.tar.gz.
File metadata
- Download URL: insighta_sbi_parser-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f61bc8ea90b6f8183d9b63af6f3f7c8e25f7a0d5016bbac55486b0bf4bcd57a5
|
|
| MD5 |
92ca70f11169d430d0218fe0fd97236d
|
|
| BLAKE2b-256 |
737b72f5c41be187d087eaa6b02b1bbbee05d5f7d739f23844098620362afd29
|
Provenance
The following attestation bundles were made for insighta_sbi_parser-0.1.0.tar.gz:
Publisher:
publish.yml on insighta-cloud/insighta-sbi-parser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
insighta_sbi_parser-0.1.0.tar.gz -
Subject digest:
f61bc8ea90b6f8183d9b63af6f3f7c8e25f7a0d5016bbac55486b0bf4bcd57a5 - Sigstore transparency entry: 1679776235
- Sigstore integration time:
-
Permalink:
insighta-cloud/insighta-sbi-parser@4ae3274f9a51b817f18f952986c12aa8ea2b4dce -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/insighta-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ae3274f9a51b817f18f952986c12aa8ea2b4dce -
Trigger Event:
push
-
Statement type:
File details
Details for the file insighta_sbi_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: insighta_sbi_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dd8b95618968ddd0b433e5504722e266e647808597d418c5da20ed910a678b2
|
|
| MD5 |
4b2e55184d1065e23972ca80df2e88b6
|
|
| BLAKE2b-256 |
f7817f124ac939f3bae05c9e6c9971d129dfd1aaede95c2a871344979a57e8ac
|
Provenance
The following attestation bundles were made for insighta_sbi_parser-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on insighta-cloud/insighta-sbi-parser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
insighta_sbi_parser-0.1.0-py3-none-any.whl -
Subject digest:
0dd8b95618968ddd0b433e5504722e266e647808597d418c5da20ed910a678b2 - Sigstore transparency entry: 1679776314
- Sigstore integration time:
-
Permalink:
insighta-cloud/insighta-sbi-parser@4ae3274f9a51b817f18f952986c12aa8ea2b4dce -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/insighta-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ae3274f9a51b817f18f952986c12aa8ea2b4dce -
Trigger Event:
push
-
Statement type: