Skip to content
Cass-ettePublic

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

ETF CLI

A simple CLI tool for real-time A-share ETF quotes and OTC fund context, designed for AI-assisted long-term trading analysis.

ETF primary data source: Eastmoney (东方财富) ETF fallback: Tencent (腾讯) OTC fund source: Tiantian Fund estimate API (天天基金估值接口) Holdings-based proxy: Eastmoney fund detail page (东方财富基金持仓)

Install

cd etf
pip3 install -r requirements.txt
pip3 install -e .

Or use the install script:

./install.sh

Usage

Get quote for single exchange-traded ETF

etf get 562500
etf get 562500 --json
etf get 562500 --ai

Get quote for OTC fund

etf fund 018344
etf fund 018344 --json
etf fund 018344 --ai

Smart lookup

etf smart robot
etf smart 562500
etf smart 018344
etf smart robot --copy

Manage ETF / OTC fund pairs

etf pair add robot 562500 018344
etf pair list
etf pair get robot
etf pair get robot --ai
etf pair remove robot

Manage OTC fund watchlist

# Add fund with optional reference ETF
etf fundw add 020404 --ref 159540
etf fundw add 009447

# List watchlist
etf fundw list

# Batch intraday estimate for all funds
etf fundw watch
etf fundw watch --json

# Remove fund
etf fundw remove 020404

One-click estimate

# Show all fund watchlist + all pairs in one view
etf est

Manage holding amounts and portfolio PnL

# Set current holding amount by code
etf holding set 020404 561.89
etf holding set 159887 12150.50
etf holding set cash 7125.69

# List/remove holdings
etf holding list
etf holding remove 020404

# Estimate whole portfolio intraday gain/loss
etf pnl
etf pnl --json

etf pnl reports both:

  • Total asset return: today's estimated gain/loss divided by all configured holdings, including cash/repo
  • Risk asset return: today's estimated gain/loss divided only by non-cash holdings

etf pnl uses the best available intraday estimate:

  1. Exchange-traded ETF quote for ETF codes
  2. Official OTC fund estimate when available
  3. Reference ETF if bound through fundw add --ref
  4. Holdings-based proxy estimate when needed
  5. cash, repo, reverse_repo, 现金, 逆回购 are treated as 0% change

Update holdings after buy/sell

# Sell 200 yuan of bank ETF
etf holding adjust 159887 -200

# Buy 500 yuan of Nasdaq fund
etf holding adjust 270042 +500

# Also works for cash changes
etf holding adjust cash -500

Portfolio history and terminal equity curve

# Save a snapshot of current portfolio (run daily after close)
etf snapshot

# Draw terminal line curve from saved snapshots
etf curve
etf curve --last 90

# Show bar/area chart instead
etf curve --bar

Snapshots are stored in ~/.etf/snapshots.jsonl. The curve shows total assets, return percentage, and max drawdown.

Manage ETF watchlist

etf add 562500
etf list
etf remove 562500
etf watch

How it works

Exchange-traded ETF vs OTC fund

Type Example What the tool shows
Exchange-traded ETF 562500 Real-time market price from Eastmoney
OTC linked fund 018344 NAV + estimated NAV from Tiantian Fund
Active/mixed fund 009447 NAV estimate + holdings-based proxy estimate

Holdings-based proxy estimation

For active/mixed funds where Tiantian Fund estimate is unavailable or unreliable:

  1. Fetches top 10 holdings and their weights from Eastmoney fund detail page
  2. Fetches intraday change for each holding stock
  3. Calculates weighted average change as proxy estimate
  4. Shows holdings coverage percentage as confidence indicator

Accuracy: directional reference only. Top holdings are from latest quarterly report and may be stale.

Reference ETF binding

When you add a fund to the watchlist with --ref, the tool also shows the reference ETF's intraday change alongside the fund estimate. This helps when:

  • The fund estimate is unavailable (e.g. 020404)
  • You want to cross-validate the estimate against the actual traded market

Data Sources

  • Eastmoney: ETF quotes (primary), fund holdings data
  • Tencent: ETF quotes (fallback)
  • Tiantian Fund: OTC fund NAV and estimated NAV

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages