Skip to main content

TigerOpen Python SDK

PyPI Python License

老虎证券 OpenAPI Python SDK — 行情、交易、账户、推送一站式接入
Tiger Brokers OpenAPI Python SDK — Market data, trading, account & push in one package

中文 | English


中文文档

目录

简介

TigerOpen 是老虎证券开放平台的官方 Python SDK,为个人开发者和机构客户提供完整的证券交易接口服务:

  • 行情数据 — 股票/期权/期货实时行情、K 线、逐笔成交、盘口深度
  • 交易服务 — 下单、改单、撤单,支持市价/限价/止损/跟踪止损/算法订单 (TWAP/VWAP)
  • 账户管理 — 资产查询、持仓管理、成交记录
  • 实时推送 — WebSocket 行情推送、订单状态、持仓与资产变动
  • AI 工具链 — CLI 命令行、MCP Server、AI Skills,支持 Cursor / Claude Code / Trae 等 AI 编程工具

开通老虎证券账户并入金后即可免费使用 OpenAPI。

支持市场

市场 股票/ETF 期权 期货 窝轮/牛熊证
美国
香港
新加坡
澳大利亚

安装

Python 3.8+

# 一键安装(自动检测 uv/pipx/pip)
curl -fsSL https://raw.githubusercontent.com/tigerfintech/openapi-python-sdk/master/install.sh | sh

# 或手动安装:
# 推荐:使用 uv(高速 Python 包管理器)
uv pip install tigeropen

# 或使用 pip
pip install tigeropen

# 或使用 Conda
conda install -c conda-forge tigeropen

# 从源码安装
git clone https://github.com/tigerfintech/openapi-python-sdk.git
cd openapi-python-sdk
pip install -e .

# 卸载
tigeropen uninstall

快速开始

1. 注册开发者

前往 开发者信息页 注册并获取:

  • tiger_id — 开发者 ID
  • private_key — RSA 私钥(Python SDK 使用 PKCS#1 格式)
  • account — 交易账户号

2. 配置

方式一:配置文件

创建 tiger_openapi_config.properties

tiger_id=your_tiger_id
private_key_pk1=your_pkcs1_private_key
account=your_account
from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig(props_path='~/.tigeropen/')

方式二:代码直接配置

from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig()
config.tiger_id = 'your_tiger_id'
config.account = 'your_account'
config.private_key = 'your_private_key_content'

3. 查询行情

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.common.consts import Market

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
client = QuoteClient(config)

# 实时报价
briefs = client.get_stock_briefs(['AAPL', 'TSLA'])
print(briefs)

# K 线数据
bars = client.get_bars(['AAPL'], period='day', limit=10)
print(bars)

# 市场状态
status = client.get_market_status(Market.US)
print(status)

逐笔成交 cond 字段说明

trade_tick 接口和 push 层返回的 cond 字段已由 SDK 转换为可读字符串,含义如下:

美股(US)

含义
US_REGULAR_SALE 常规交易(Regular Sale)
US_BUNCHED_TRADE 批量交易(Bunched Trade)
US_CASH_TRADE 现金交易(Cash Trade)
US_INTERMARKET_SWEEP 跨市场交易(Intermarket Sweep)
US_BUNCHED_SOLD_TRADE 批量卖出(Bunched Sold Trade)
US_PRICE_VARIATION_TRADE 离价交易(Price Variation Trade)
US_ODD_LOT_TRADE 碎股交易(Odd Lot Trade)
US_RULE_127_OR_155_TRADE 纽交所第 127/155 条交易
US_SOLD_LAST 延迟交易(Sold Last)
US_MARKET_CENTER_CLOSE_PRICE 中央收市价(Market Center Close Price)
US_NEXT_DAY_TRADE 隔日交易(Next Day Trade)
US_MARKET_CENTER_OPENING_TRADE 中央开盘价交易(Market Center Opening Trade)
US_PRIOR_REFERENCE_PRICE 前参考价(Prior Reference Price)
US_MARKET_CENTER_OPEN_PRICE 中央开盘价(Market Center Open Price)
US_SELLER 卖方(Seller)
US_FORM_T 盘前盘后交易(Form T)
US_EXTENDED_TRADING_HOURS 延长交易时段(Extended Trading Hours)
US_CONTINGENT_TRADE 合单交易(Contingent Trade)
US_AVERAGE_PRICE_TRADE 均价交易(Average Price Trade)
US_CROSS_TRADE 跨市场交易(Cross Trade)
US_SOLD_OUT_OF_SEQUENCE 场外售出(Sold Out of Sequence)
US_DERIVATIVELY_PRICED 衍生工具定价(Derivatively Priced)
US_QUALIFIED_CONTINGENT_TRADE 合单交易(Qualified Contingent Trade)

港股(HK)

含义
HK_AUTOMATCH_NORMAL 自动对盘(Automatch Normal)
HK_ODD_LOT_TRADE 碎股交易(Odd Lot Trade)
HK_AUCTION_TRADE 竞价交易(Auction Trade)
HK_OVERSEAS_TRADE 场外交易(Overseas Trade)
HK_LATE_TRADE_OFF_EXCHG 开市前成交(Late Trade Off Exchange)
HK_NON_DIRECT_OFF_EXCHG_TRADE 非自动对盘(Non-Direct Off Exchange Trade)
HK_DIRECT_OFF_EXCHG_TRADE 同券商自动对盘(Direct Off Exchange Trade)
HK_AUTOMATIC_INTERNALIZED 同券商非自动对盘(Automatic Internalized)

4. 下单交易

from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
client = TradeClient(config)

# 创建合约和订单
contract = stock_contract('AAPL', 'USD')
order = limit_order(client._account, contract, 'BUY', 1, 150.0)

# 预览订单
preview = client.preview_order(order)
print(preview)

# 下单
order_id = client.place_order(order)
print(f'Order ID: {order_id}')

5. 实时推送

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
protocol, host, port = config.socket_host_port

def on_quote_changed(symbol, items, hour_trading):
    print(f'{symbol}: {items}')

push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))
push_client.quote_changed = on_quote_changed
push_client.connect(config.tiger_id, config.private_key)
push_client.subscribe_quote(['AAPL', 'TSLA'])

CLI 命令行工具

安装 SDK 后自动获得 tigeropen 命令行工具,无需编码即可查询行情、管理订单。

初始化配置

tigeropen config init    # 交互式配置 tiger_id / account / private_key
tigeropen config show    # 查看当前配置(私钥已脱敏)

行情查询

# 实时报价
tigeropen quote briefs AAPL TSLA

# K 线数据
tigeropen quote bars AAPL --period day --limit 10

# 分时数据
tigeropen quote timeline AAPL

# 市场状态
tigeropen quote market-status

# 期权链
tigeropen quote option expirations AAPL
tigeropen quote option chain AAPL 2026-06-19

# 期货
tigeropen quote future exchanges
tigeropen quote future contracts CME

交易操作

# 查看持仓
tigeropen trade position list

# 查看订单
tigeropen trade order list --status Filled

# 预览订单
tigeropen trade order preview --symbol AAPL --action BUY --quantity 100 --limit-price 150

# 下单(会提示确认)
tigeropen trade order place --symbol AAPL --action BUY --quantity 100 --limit-price 150

# 撤单
tigeropen trade order cancel 12345678

账户信息

tigeropen account assets
tigeropen account info

输出格式

# 表格(默认)
tigeropen quote briefs AAPL

# JSON
tigeropen quote briefs AAPL --format json

# CSV
tigeropen quote briefs AAPL --format csv

命令总览

tigeropen
├── config    — init / show / set / path
├── quote     — briefs / bars / timeline / ticks / depth / market-status / symbols
│   ├── option      — expirations / chain / briefs / bars
│   ├── future      — exchanges / contracts / briefs / bars
│   ├── capital     — flow / distribution
│   └── fundamental — financial / dividend / earnings
├── trade
│   ├── order       — list / get / place / preview / modify / cancel
│   ├── position    — list
│   └── transaction — list
├── account   — info / assets / analytics
├── push      — quote / order / position / asset
└── version

MCP Server (AI 集成)

TigerOpen 提供 MCP (Model Context Protocol) Server,可与 Cursor、Claude Code、Trae 等 AI 编程工具集成,通过自然语言查询行情和管理交易。

安装

# 需要先安装 uv
pip install uv
# 或
brew install uv

配置

在 AI 工具的 MCP 配置中添加:

个人账户:

{
  "mcpServers": {
    "tigermcp": {
      "command": "uvx",
      "args": ["tigermcp"],
      "env": {
        "TIGEROPEN_TIGER_ID": "your_tiger_id",
        "TIGEROPEN_PRIVATE_KEY": "your_private_key",
        "TIGEROPEN_ACCOUNT": "your_account"
      }
    }
  }
}

机构账户:

{
  "mcpServers": {
    "tigermcp": {
      "command": "uvx",
      "args": ["tigermcp"],
      "env": {
        "TIGEROPEN_TIGER_ID": "your_tiger_id",
        "TIGEROPEN_PRIVATE_KEY": "your_private_key",
        "TIGEROPEN_ACCOUNT": "your_account",
        "TIGEROPEN_SECRET_KEY": "your_secret_key",
        "TIGEROPEN_TOKEN": "your_token"
      }
    }
  }
}

只读模式: 添加 "TIGERMCP_READONLY": "true"env 中,禁止下单操作。

macOS 12 用户: 若遇到 realpath 错误,需安装 coreutils:brew install coreutils

使用示例

在 AI 工具中直接用自然语言:

  • "查询 AAPL 的实时报价"
  • "帮我看看 TSLA 最近 5 天的 K 线"
  • "查询我的持仓"
  • "以 150 美元限价买入 100 股 AAPL"

AI Skills (智能编程助手)

TigerOpen 提供 Agent Skills 规范的技能包,为 Claude Code 等 AI 编程工具提供 Tiger OpenAPI 的专业知识。

技能模块

技能 说明
quickstart 环境搭建与 SDK 配置
quote 行情接口使用指导
trade 交易接口使用指导
option 期权接口使用指导
push 实时推送接口使用指导
mcp MCP Server 配置指导

安装方式

方式一:Claude Code 插件市场

claude install-plugin tigerfintech/openapi-python-sdk/tigeropen/examples/ai/skills

方式二:全局安装

cp -r tigeropen/examples/ai/skills/ ~/.claude/skills/tigeropen/

方式三:项目级安装

cp -r tigeropen/examples/ai/skills/ .claude/skills/tigeropen/

更多安装方式详见 Skills README

示例代码

更多示例代码位于 tigeropen/examples/ 目录。

文档与支持

License

Apache License 2.0


English Documentation

Table of Contents

Introduction

TigerOpen is the official Python SDK for Tiger Brokers' Open Platform, providing developers and institutional clients with comprehensive securities trading interfaces:

  • Market Data — Real-time quotes, candlesticks, tick data, order book depth for stocks, options & futures
  • Trading — Place, modify, cancel orders; supports market/limit/stop/trailing-stop/algo orders (TWAP/VWAP)
  • Account Management — Asset queries, position tracking, transaction history
  • Real-time Push — WebSocket streaming for quotes, order status, position & asset changes
  • AI Toolchain — CLI, MCP Server, AI Skills; integrates with Cursor / Claude Code / Trae

OpenAPI is free to use after opening and funding a Tiger Brokers account.

Supported Markets

Market Stocks/ETFs Options Futures Warrants/CBBCs
US
Hong Kong
Singapore
Australia

Installation

Python 3.8+

# One-line install (auto-detects uv/pipx/pip)
curl -fsSL https://raw.githubusercontent.com/tigerfintech/openapi-python-sdk/master/install.sh | sh

# Or install manually:
# Recommended: use uv (fast Python package manager)
uv pip install tigeropen

# Or use pip
pip install tigeropen

# Or use Conda
conda install -c conda-forge tigeropen

# Install from source
git clone https://github.com/tigerfintech/openapi-python-sdk.git
cd openapi-python-sdk
pip install -e .

# Uninstall
tigeropen uninstall

Quick Start

1. Register as a Developer

Go to the Developer Portal to obtain:

  • tiger_id — Developer ID
  • private_key — RSA private key (Python SDK uses PKCS#1 format)
  • account — Trading account number

2. Configuration

Option A: Properties file

Create tiger_openapi_config.properties:

tiger_id=your_tiger_id
private_key_pk1=your_pkcs1_private_key
account=your_account
from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig(props_path='~/.tigeropen/')

Option B: Direct configuration

from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig()
config.tiger_id = 'your_tiger_id'
config.account = 'your_account'
config.private_key = 'your_private_key_content'

3. Query Market Data

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.common.consts import Market

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
client = QuoteClient(config)

# Real-time quotes
briefs = client.get_stock_briefs(['AAPL', 'TSLA'])
print(briefs)

# Candlestick data
bars = client.get_bars(['AAPL'], period='day', limit=10)
print(bars)

# Market status
status = client.get_market_status(Market.US)
print(status)

4. Place Orders

from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
client = TradeClient(config)

# Create contract and order
contract = stock_contract('AAPL', 'USD')
order = limit_order(client._account, contract, 'BUY', 1, 150.0)

# Preview order
preview = client.preview_order(order)
print(preview)

# Place order
order_id = client.place_order(order)
print(f'Order ID: {order_id}')

5. Real-time Push

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import TigerOpenClientConfig

config = TigerOpenClientConfig(props_path='~/.tigeropen/')
protocol, host, port = config.socket_host_port

def on_quote_changed(symbol, items, hour_trading):
    print(f'{symbol}: {items}')

push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))
push_client.quote_changed = on_quote_changed
push_client.connect(config.tiger_id, config.private_key)
push_client.subscribe_quote(['AAPL', 'TSLA'])

CLI Tool

After installing the SDK, you get the tigeropen CLI — query market data and manage orders without writing code.

Initialize Configuration

tigeropen config init    # Interactive setup for tiger_id / account / private_key
tigeropen config show    # Show current config (private key masked)

Market Data

# Real-time quotes
tigeropen quote briefs AAPL TSLA

# Candlestick data
tigeropen quote bars AAPL --period day --limit 10

# Intraday timeline
tigeropen quote timeline AAPL

# Market status
tigeropen quote market-status

# Option chain
tigeropen quote option expirations AAPL
tigeropen quote option chain AAPL 2026-06-19

# Futures
tigeropen quote future exchanges
tigeropen quote future contracts CME

Trading

# View positions
tigeropen trade position list

# View orders
tigeropen trade order list --status Filled

# Preview order
tigeropen trade order preview --symbol AAPL --action BUY --quantity 100 --limit-price 150

# Place order (confirmation required)
tigeropen trade order place --symbol AAPL --action BUY --quantity 100 --limit-price 150

# Cancel order
tigeropen trade order cancel 12345678

Account

tigeropen account assets
tigeropen account info

Output Formats

# Table (default)
tigeropen quote briefs AAPL

# JSON
tigeropen quote briefs AAPL --format json

# CSV
tigeropen quote briefs AAPL --format csv

Command Reference

tigeropen
├── config    — init / show / set / path
├── quote     — briefs / bars / timeline / ticks / depth / market-status / symbols
│   ├── option      — expirations / chain / briefs / bars
│   ├── future      — exchanges / contracts / briefs / bars
│   ├── capital     — flow / distribution
│   └── fundamental — financial / dividend / earnings
├── trade
│   ├── order       — list / get / place / preview / modify / cancel
│   ├── position    — list
│   └── transaction — list
├── account   — info / assets / analytics
├── push      — quote / order / position / asset
└── version

MCP Server (AI Integration)

TigerOpen provides an MCP (Model Context Protocol) Server that integrates with AI coding tools like Cursor, Claude Code, and Trae, enabling market queries and trade management via natural language.

Install

# Install uv first
pip install uv
# or
brew install uv

Configuration

Add to your AI tool's MCP settings:

Personal account:

{
  "mcpServers": {
    "tigermcp": {
      "command": "uvx",
      "args": ["tigermcp"],
      "env": {
        "TIGEROPEN_TIGER_ID": "your_tiger_id",
        "TIGEROPEN_PRIVATE_KEY": "your_private_key",
        "TIGEROPEN_ACCOUNT": "your_account"
      }
    }
  }
}

Institutional account:

{
  "mcpServers": {
    "tigermcp": {
      "command": "uvx",
      "args": ["tigermcp"],
      "env": {
        "TIGEROPEN_TIGER_ID": "your_tiger_id",
        "TIGEROPEN_PRIVATE_KEY": "your_private_key",
        "TIGEROPEN_ACCOUNT": "your_account",
        "TIGEROPEN_SECRET_KEY": "your_secret_key",
        "TIGEROPEN_TOKEN": "your_token"
      }
    }
  }
}

Read-only mode: Add "TIGERMCP_READONLY": "true" to env to disable order placement.

macOS 12 users: If you encounter a realpath error, install coreutils: brew install coreutils

Usage Examples

Use natural language in your AI tool:

  • "Get real-time quote for AAPL"
  • "Show me TSLA's daily candles for the last 5 days"
  • "Check my positions"
  • "Buy 100 shares of AAPL at $150 limit"

AI Skills

TigerOpen provides skill packs following the Agent Skills standard, giving AI coding tools like Claude Code expert knowledge of Tiger OpenAPI.

Skill Modules

Skill Description
quickstart Environment setup & SDK configuration
quote Market data API guidance
trade Trading API guidance
option Options API guidance
push Real-time push API guidance
mcp MCP Server configuration

Installation

Option 1: Claude Code Plugin Marketplace

claude install-plugin tigerfintech/openapi-python-sdk/tigeropen/examples/ai/skills

Option 2: Global installation

cp -r tigeropen/examples/ai/skills/ ~/.claude/skills/tigeropen/

Option 3: Project-level installation

cp -r tigeropen/examples/ai/skills/ .claude/skills/tigeropen/

See the Skills README for more installation methods.

Examples

More examples are available in the tigeropen/examples/ directory.

Documentation & Support

License

Apache License 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tigeropen-3.7.1.tar.gz (560.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tigeropen-3.7.1-py3-none-any.whl (600.2 kB view details)

Uploaded Python 3

File details

Details for the file tigeropen-3.7.1.tar.gz.

File metadata

  • Download URL: tigeropen-3.7.1.tar.gz
  • Upload date:
  • Size: 560.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for tigeropen-3.7.1.tar.gz
Algorithm Hash digest
SHA256 42177b55dc87048ac3e2b14441d9e2981d35873ae64db560cd0f911fb0f167b1
MD5 2da34b63eec88840cc8f5f14a268d117
BLAKE2b-256 e4bdd4f886bec9db0937cb7c3641c9d67e4a5d3e81cb5c74f6643ae3814da2fd

See more details on using hashes here.

File details

Details for the file tigeropen-3.7.1-py3-none-any.whl.

File metadata

  • Download URL: tigeropen-3.7.1-py3-none-any.whl
  • Upload date:
  • Size: 600.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for tigeropen-3.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64e11976b7b915d9b61045b33cbca755cc269d23ce678eca26a099ade5b56ff2
MD5 65a727e556c91fb66587fe775fc9e208
BLAKE2b-256 cd2322727e3cb7c86e45fa40a2dddbe0e18dba8f2236900c6654869511af9136

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.7.1 This release

2 files

3.7.0

2 files

3.6.0

2 files

3.5.9

2 files

3.5.8

1 file

3.5.7

1 file

3.5.6

1 file

3.5.5

1 file

3.5.4

1 file

3.5.3

1 file

3.5.2

1 file

3.5.1

1 file

3.5.0

1 file

3.4.9

1 file

3.4.8

1 file

3.4.7

1 file

3.4.6

1 file

3.4.5

1 file

3.4.4

1 file

3.4.3

1 file

3.4.2

1 file

3.4.1

1 file

3.4.0

1 file

3.3.9

1 file

3.3.8

1 file

3.3.7

1 file

3.3.6

1 file

3.3.5

1 file

3.3.4

1 file

3.3.3

1 file

3.3.2

1 file

3.3.1

1 file

3.3.0

1 file

3.2.9

1 file

3.2.8

1 file

3.2.7

1 file

3.2.6

1 file

3.2.5

1 file

3.2.4

1 file

3.2.3

1 file

3.2.2

1 file

3.2.1

1 file

3.2.0

1 file

3.1.9

1 file

3.1.8

1 file

3.1.7

1 file

3.1.6

1 file

3.1.5

1 file

3.1.4

1 file

3.1.3

1 file

3.1.2

1 file

3.1.1

1 file

3.1.0

1 file

3.0.9

1 file

3.0.8

1 file

3.0.7

1 file

3.0.6

1 file

3.0.5

1 file

3.0.4

1 file

3.0.3

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.4.0

1 file

2.3.9

1 file

2.3.8

1 file

2.3.7

1 file

2.3.6

1 file

2.3.5

1 file

2.3.4

1 file

2.3.3

1 file

2.3.2

1 file

2.3.1

1 file

2.3.0

1 file

2.2.9

1 file

2.2.8

1 file

2.2.7

1 file

2.2.6

1 file

2.2.5

1 file

2.2.4

1 file

2.2.3

1 file

2.2.2

1 file

2.2.1

1 file

2.2.0

1 file

2.1.9

1 file

2.1.8

1 file

2.1.7

1 file

2.1.6

1 file

2.1.5

1 file

2.1.4

1 file

2.1.3

1 file

2.1.2

1 file

2.1.1

1 file

2.1.0

1 file

2.0.9

1 file

2.0.8

1 file

2.0.7

1 file

2.0.6

1 file

2.0.5

1 file

2.0.4

1 file

2.0.3

1 file

2.0.2

1 file

2.0.1

1 file

2.0.0

1 file

1.4.1

1 file

1.4.0

1 file

1.2.1

1 file

1.2.0

1 file

1.1.10

1 file

1.1.9

1 file

1.1.7

1 file

1.1.6

1 file

1.1.5

1 file

1.1.4

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

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