Metadata-Version: 2.4
Name: insighta-sbi-parser
Version: 0.1.0
Summary: SBI証券の取引データをパースするPythonライブラリ
Project-URL: Repository, https://github.com/insighta-cloud/insighta-sbi-parser
Project-URL: Issues, https://github.com/insighta-cloud/insighta-sbi-parser/issues
Author-email: "insighta cloud Inc." <tech@insighta.cloud>
License-Expression: MIT
License-File: LICENSE
Keywords: japan,parser,portfolio,sbi,securities,trading
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.10
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: pandas>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# insighta-sbi-parser

[![PyPI](https://img.shields.io/pypi/v/insighta-sbi-parser)](https://pypi.org/project/insighta-sbi-parser/)
[![Python](https://img.shields.io/pypi/pyversions/insighta-sbi-parser)](https://pypi.org/project/insighta-sbi-parser/)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

SBI証券からダウンロードした取引データ（HTML/CSV）を構造化されたPythonオブジェクトに変換するライブラリです。

## インストール

```bash
pip install insighta-sbi-parser
```

## 使い方

### ディレクトリ一括パース

```python
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})")
```

### 為替レート付きパース

```python
result = process_sbi_dir("path/to/sbi_files/", rate_file="rate.csv")
```

`rate.csv` 形式:
```csv
date,rate
2024/01/15,148.50
2024/01/16,149.20
```

### ファイル個別パース

```python
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()` |

## データモデル

```python
@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サイトから以下の手順でダウンロードできます:

1. **注文履歴HTML**: 外国株式 → 注文照会 → ページをHTMLとして保存
2. **保有銘柄HTML**: 外国株式 → 口座管理 → ページをHTMLとして保存
3. **約定履歴CSV**: 外国株式 → 取引履歴 → CSVダウンロード
4. **入出金CSV**: 入出金・振替 → 操作履歴 → CSVダウンロード

## Contributing

```bash
git clone https://github.com/insighta-cloud/insighta-sbi-parser.git
cd insighta-sbi-parser
pip install -e ".[dev]"
pytest
```

## License

MIT
