tzzb 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tzzb-0.2.0/PKG-INFO +167 -0
- tzzb-0.2.0/README.md +154 -0
- tzzb-0.2.0/pyproject.toml +27 -0
- tzzb-0.2.0/setup.cfg +4 -0
- tzzb-0.2.0/src/tzzb/__init__.py +18 -0
- tzzb-0.2.0/src/tzzb/auth.py +474 -0
- tzzb-0.2.0/src/tzzb/cli.py +1107 -0
- tzzb-0.2.0/src/tzzb/client.py +632 -0
- tzzb-0.2.0/src/tzzb/config.py +90 -0
- tzzb-0.2.0/src/tzzb/mcp.py +210 -0
- tzzb-0.2.0/src/tzzb/models.py +86 -0
- tzzb-0.2.0/src/tzzb.egg-info/PKG-INFO +167 -0
- tzzb-0.2.0/src/tzzb.egg-info/SOURCES.txt +16 -0
- tzzb-0.2.0/src/tzzb.egg-info/dependency_links.txt +1 -0
- tzzb-0.2.0/src/tzzb.egg-info/entry_points.txt +3 -0
- tzzb-0.2.0/src/tzzb.egg-info/requires.txt +4 -0
- tzzb-0.2.0/src/tzzb.egg-info/top_level.txt +1 -0
- tzzb-0.2.0/tests/test_tzzb.py +54 -0
tzzb-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tzzb
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python SDK, CLI and MCP server for Tonghuashun Investment Ledger (同花顺投资账本)
|
|
5
|
+
Author: brwchen
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: websocket-client>=1.8.0
|
|
10
|
+
Requires-Dist: mcp>=1.0.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Requires-Dist: rich>=13.0.0
|
|
13
|
+
|
|
14
|
+
# tzzb
|
|
15
|
+
|
|
16
|
+
Python SDK, CLI tool, and Model Context Protocol (MCP) server for **Tonghuashun Investment Ledger (同花顺投资账本)**.
|
|
17
|
+
|
|
18
|
+
Provides programmatic access to multi-broker positions, intraday trades & T+0 arbitrage breakdown, historical transaction ledger, asset curves, monthly profit calendars, individual stock profit contribution rankings, and time-share curves with zero token overhead for Python apps and seamless AI Agent integration.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Key Features
|
|
23
|
+
|
|
24
|
+
- **Direct Python SDK (`TzzbClient`)**: Native Python calls for automated financial pipelines, SQLite sync, and quantitative tracking returning raw JSON-serializable dictionaries.
|
|
25
|
+
- **Rich Terminal CLI**: Beautiful, high-density terminal tables with TrueColor RGB opacity control and compact financial layouts.
|
|
26
|
+
- **Intraday T+0 (做T) Arbitrage Analysis**: Automatically detects same-day buy and sell executions per stock, computes hedged T-volume, buy/sell average prices, price spreads, net T-profits, and remaining position changes.
|
|
27
|
+
- **Monthly Profit Calendar & Win Rates**: Computes daily profit & loss, yield %, trading days, winning days, and monthly win rate summary.
|
|
28
|
+
- **Stock Profit Contribution Leaderboard**: Ranks winning and losing stocks by year, holding period, month, or intraday.
|
|
29
|
+
- **Intraday Time-Share Curve**: Monitors minute-by-minute profit curves and key time checkpoints (e.g. 09:30, 10:30, 11:30, 14:00, 15:00).
|
|
30
|
+
- **Multi-Account Auto Aggregation**: Automatically aggregates multiple securities brokers, manual accounts, and margin (融资融券) accounts across all data endpoints.
|
|
31
|
+
- **Global Configuration**: Configurable color display and terminal opacity (`~/.tzzb/config.json`).
|
|
32
|
+
- **Model Context Protocol (MCP)**: Native FastMCP server for Claude Desktop, Copilot, and custom AI agents.
|
|
33
|
+
- **Chrome CDP Bridge**: Connects to isolated Chrome instance over DevTools Protocol, automatically attaching dynamic `hexin-v` anti-bot headers with persistent session cookies (`~/.tzzb_cookies.json`).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install tzzb
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or install from source in editable mode:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/brwchen/tzzb.git
|
|
47
|
+
cd tzzb
|
|
48
|
+
pip install -e .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
### 1. Python SDK
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from tzzb import TzzbClient
|
|
59
|
+
|
|
60
|
+
client = TzzbClient()
|
|
61
|
+
|
|
62
|
+
# Check authentication status
|
|
63
|
+
status = client.get_login_status()
|
|
64
|
+
print(f"Logged in: {status.logged_in}, User ID: {status.userid}")
|
|
65
|
+
|
|
66
|
+
# Asset & profit overview
|
|
67
|
+
overview = client.get_overview()
|
|
68
|
+
|
|
69
|
+
# Multi-account positions
|
|
70
|
+
positions = client.get_positions()
|
|
71
|
+
|
|
72
|
+
# Today's executions & T+0 trading flows
|
|
73
|
+
today_trades = client.get_today_trades()
|
|
74
|
+
|
|
75
|
+
# Monthly profit calendar (e.g. '2026-10')
|
|
76
|
+
calendar = client.get_profit_calendar("2026-10")
|
|
77
|
+
|
|
78
|
+
# Profit contribution rankings (rank_type: 'year' | 'hold' | 'month' | 'today')
|
|
79
|
+
rankings = client.get_rankings(rank_type="year")
|
|
80
|
+
|
|
81
|
+
# Intraday minute time-share profit checkpoints
|
|
82
|
+
time_share = client.get_time_share()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 2. Command Line Interface (CLI)
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Authentication & Status
|
|
89
|
+
tzzb status
|
|
90
|
+
tzzb login
|
|
91
|
+
tzzb logout
|
|
92
|
+
|
|
93
|
+
# Overview & Accounts
|
|
94
|
+
tzzb overview # alias: tzzb ov
|
|
95
|
+
tzzb accounts # alias: tzzb acc
|
|
96
|
+
|
|
97
|
+
# Positions
|
|
98
|
+
tzzb positions # alias: tzzb pos (compact view)
|
|
99
|
+
tzzb positions -d # detailed view with costs, market values, profit ratios
|
|
100
|
+
|
|
101
|
+
# Intraday Trades & T+0 Arbitrage
|
|
102
|
+
tzzb t # alias: tzzb today-trades, tzzb trades, tzzb t0
|
|
103
|
+
tzzb t 600519 # filter trades and T-arbitrage by stock code
|
|
104
|
+
|
|
105
|
+
# Profit Calendar & Win Rates
|
|
106
|
+
tzzb calendar # alias: tzzb cal (current month)
|
|
107
|
+
tzzb calendar 2026-09 # specify historical month
|
|
108
|
+
|
|
109
|
+
# Profit Contribution Rankings
|
|
110
|
+
tzzb rank # alias: tzzb ranking (annual rankings)
|
|
111
|
+
tzzb rank --by hold # ranking by holding period
|
|
112
|
+
tzzb rank --by month # ranking by monthly profit
|
|
113
|
+
|
|
114
|
+
# Intraday Time-Share Curve
|
|
115
|
+
tzzb timeshare # alias: tzzb ts
|
|
116
|
+
|
|
117
|
+
# Global Configuration
|
|
118
|
+
tzzb config # view current config
|
|
119
|
+
tzzb config set color true # enable/disable colors
|
|
120
|
+
tzzb config set opacity 0.8 # set terminal opacity (0.0 - 1.0)
|
|
121
|
+
tzzb config reset # reset to defaults
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 3. Model Context Protocol (MCP)
|
|
125
|
+
|
|
126
|
+
Add `tzzb-mcp` to your MCP configuration (e.g. `claude_desktop_config.json` or Copilot MCP settings):
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"mcpServers": {
|
|
131
|
+
"tzzb": {
|
|
132
|
+
"command": "tzzb-mcp"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Exposed MCP Tools:
|
|
139
|
+
- `tzzb_get_status`: Get current authentication and user status.
|
|
140
|
+
- `tzzb_login` / `tzzb_logout`: QR login or session logout.
|
|
141
|
+
- `tzzb_get_overview`: Total asset, market value, cash balance, and profits.
|
|
142
|
+
- `tzzb_get_accounts`: List all bound brokerage and manual accounts.
|
|
143
|
+
- `tzzb_get_positions`: Real-time stock holdings, shares, costs, and profit percentages.
|
|
144
|
+
- `tzzb_get_today_trades`: Intraday order executions and T+0 arbitrage data.
|
|
145
|
+
- `tzzb_get_profit_calendar`: Monthly daily PnL and win rate statistics.
|
|
146
|
+
- `tzzb_get_rankings`: Stock profit contribution rankings.
|
|
147
|
+
- `tzzb_get_time_share`: Intraday minute profit checkpoints.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
Configuration file is automatically created at `~/.tzzb/config.json`:
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"color": true,
|
|
158
|
+
"opacity": 1.0
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|
|
167
|
+
|
tzzb-0.2.0/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# tzzb
|
|
2
|
+
|
|
3
|
+
Python SDK, CLI tool, and Model Context Protocol (MCP) server for **Tonghuashun Investment Ledger (同花顺投资账本)**.
|
|
4
|
+
|
|
5
|
+
Provides programmatic access to multi-broker positions, intraday trades & T+0 arbitrage breakdown, historical transaction ledger, asset curves, monthly profit calendars, individual stock profit contribution rankings, and time-share curves with zero token overhead for Python apps and seamless AI Agent integration.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Direct Python SDK (`TzzbClient`)**: Native Python calls for automated financial pipelines, SQLite sync, and quantitative tracking returning raw JSON-serializable dictionaries.
|
|
12
|
+
- **Rich Terminal CLI**: Beautiful, high-density terminal tables with TrueColor RGB opacity control and compact financial layouts.
|
|
13
|
+
- **Intraday T+0 (做T) Arbitrage Analysis**: Automatically detects same-day buy and sell executions per stock, computes hedged T-volume, buy/sell average prices, price spreads, net T-profits, and remaining position changes.
|
|
14
|
+
- **Monthly Profit Calendar & Win Rates**: Computes daily profit & loss, yield %, trading days, winning days, and monthly win rate summary.
|
|
15
|
+
- **Stock Profit Contribution Leaderboard**: Ranks winning and losing stocks by year, holding period, month, or intraday.
|
|
16
|
+
- **Intraday Time-Share Curve**: Monitors minute-by-minute profit curves and key time checkpoints (e.g. 09:30, 10:30, 11:30, 14:00, 15:00).
|
|
17
|
+
- **Multi-Account Auto Aggregation**: Automatically aggregates multiple securities brokers, manual accounts, and margin (融资融券) accounts across all data endpoints.
|
|
18
|
+
- **Global Configuration**: Configurable color display and terminal opacity (`~/.tzzb/config.json`).
|
|
19
|
+
- **Model Context Protocol (MCP)**: Native FastMCP server for Claude Desktop, Copilot, and custom AI agents.
|
|
20
|
+
- **Chrome CDP Bridge**: Connects to isolated Chrome instance over DevTools Protocol, automatically attaching dynamic `hexin-v` anti-bot headers with persistent session cookies (`~/.tzzb_cookies.json`).
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install tzzb
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or install from source in editable mode:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/brwchen/tzzb.git
|
|
34
|
+
cd tzzb
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### 1. Python SDK
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from tzzb import TzzbClient
|
|
46
|
+
|
|
47
|
+
client = TzzbClient()
|
|
48
|
+
|
|
49
|
+
# Check authentication status
|
|
50
|
+
status = client.get_login_status()
|
|
51
|
+
print(f"Logged in: {status.logged_in}, User ID: {status.userid}")
|
|
52
|
+
|
|
53
|
+
# Asset & profit overview
|
|
54
|
+
overview = client.get_overview()
|
|
55
|
+
|
|
56
|
+
# Multi-account positions
|
|
57
|
+
positions = client.get_positions()
|
|
58
|
+
|
|
59
|
+
# Today's executions & T+0 trading flows
|
|
60
|
+
today_trades = client.get_today_trades()
|
|
61
|
+
|
|
62
|
+
# Monthly profit calendar (e.g. '2026-10')
|
|
63
|
+
calendar = client.get_profit_calendar("2026-10")
|
|
64
|
+
|
|
65
|
+
# Profit contribution rankings (rank_type: 'year' | 'hold' | 'month' | 'today')
|
|
66
|
+
rankings = client.get_rankings(rank_type="year")
|
|
67
|
+
|
|
68
|
+
# Intraday minute time-share profit checkpoints
|
|
69
|
+
time_share = client.get_time_share()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Command Line Interface (CLI)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Authentication & Status
|
|
76
|
+
tzzb status
|
|
77
|
+
tzzb login
|
|
78
|
+
tzzb logout
|
|
79
|
+
|
|
80
|
+
# Overview & Accounts
|
|
81
|
+
tzzb overview # alias: tzzb ov
|
|
82
|
+
tzzb accounts # alias: tzzb acc
|
|
83
|
+
|
|
84
|
+
# Positions
|
|
85
|
+
tzzb positions # alias: tzzb pos (compact view)
|
|
86
|
+
tzzb positions -d # detailed view with costs, market values, profit ratios
|
|
87
|
+
|
|
88
|
+
# Intraday Trades & T+0 Arbitrage
|
|
89
|
+
tzzb t # alias: tzzb today-trades, tzzb trades, tzzb t0
|
|
90
|
+
tzzb t 600519 # filter trades and T-arbitrage by stock code
|
|
91
|
+
|
|
92
|
+
# Profit Calendar & Win Rates
|
|
93
|
+
tzzb calendar # alias: tzzb cal (current month)
|
|
94
|
+
tzzb calendar 2026-09 # specify historical month
|
|
95
|
+
|
|
96
|
+
# Profit Contribution Rankings
|
|
97
|
+
tzzb rank # alias: tzzb ranking (annual rankings)
|
|
98
|
+
tzzb rank --by hold # ranking by holding period
|
|
99
|
+
tzzb rank --by month # ranking by monthly profit
|
|
100
|
+
|
|
101
|
+
# Intraday Time-Share Curve
|
|
102
|
+
tzzb timeshare # alias: tzzb ts
|
|
103
|
+
|
|
104
|
+
# Global Configuration
|
|
105
|
+
tzzb config # view current config
|
|
106
|
+
tzzb config set color true # enable/disable colors
|
|
107
|
+
tzzb config set opacity 0.8 # set terminal opacity (0.0 - 1.0)
|
|
108
|
+
tzzb config reset # reset to defaults
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. Model Context Protocol (MCP)
|
|
112
|
+
|
|
113
|
+
Add `tzzb-mcp` to your MCP configuration (e.g. `claude_desktop_config.json` or Copilot MCP settings):
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"mcpServers": {
|
|
118
|
+
"tzzb": {
|
|
119
|
+
"command": "tzzb-mcp"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Exposed MCP Tools:
|
|
126
|
+
- `tzzb_get_status`: Get current authentication and user status.
|
|
127
|
+
- `tzzb_login` / `tzzb_logout`: QR login or session logout.
|
|
128
|
+
- `tzzb_get_overview`: Total asset, market value, cash balance, and profits.
|
|
129
|
+
- `tzzb_get_accounts`: List all bound brokerage and manual accounts.
|
|
130
|
+
- `tzzb_get_positions`: Real-time stock holdings, shares, costs, and profit percentages.
|
|
131
|
+
- `tzzb_get_today_trades`: Intraday order executions and T+0 arbitrage data.
|
|
132
|
+
- `tzzb_get_profit_calendar`: Monthly daily PnL and win rate statistics.
|
|
133
|
+
- `tzzb_get_rankings`: Stock profit contribution rankings.
|
|
134
|
+
- `tzzb_get_time_share`: Intraday minute profit checkpoints.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Configuration
|
|
139
|
+
|
|
140
|
+
Configuration file is automatically created at `~/.tzzb/config.json`:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"color": true,
|
|
145
|
+
"opacity": 1.0
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT
|
|
154
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tzzb"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Python SDK, CLI and MCP server for Tonghuashun Investment Ledger (同花顺投资账本)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "brwchen" }
|
|
12
|
+
]
|
|
13
|
+
license = "MIT"
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"websocket-client>=1.8.0",
|
|
17
|
+
"mcp>=1.0.0",
|
|
18
|
+
"pydantic>=2.0.0",
|
|
19
|
+
"rich>=13.0.0",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
tzzb = "tzzb.cli:main"
|
|
24
|
+
tzzb-mcp = "tzzb.mcp:main"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.packages.find]
|
|
27
|
+
where = ["src"]
|
tzzb-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""tzzb — Python SDK, CLI, and MCP Server for Tonghuashun Investment Ledger (同花顺投资账本)."""
|
|
2
|
+
|
|
3
|
+
from .client import TzzbClient, TzzbError
|
|
4
|
+
from .config import TzzbConfig, config
|
|
5
|
+
from .models import Account, AssetTrendPoint, LoginStatus, Position, TradeRecord
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"TzzbClient",
|
|
9
|
+
"TzzbError",
|
|
10
|
+
"TzzbConfig",
|
|
11
|
+
"config",
|
|
12
|
+
"Account",
|
|
13
|
+
"AssetTrendPoint",
|
|
14
|
+
"LoginStatus",
|
|
15
|
+
"Position",
|
|
16
|
+
"TradeRecord",
|
|
17
|
+
]
|
|
18
|
+
__version__ = "0.1.0"
|