Install
openclaw skills install quant-trading-apiProfessional quantitative trading API integration for Chinese securities. Supports major Chinese brokers (华泰, 银河, 广发, 中信建投) with order management, position tracking, real-time market data, and automated trading workflows.
openclaw skills install quant-trading-apiProfessional trading API for Chinese securities brokers.
| Broker | Status | Features |
|---|---|---|
| 华泰证券 (Huatai) | ✅ | Full API |
| 银河证券 (Galaxy) | ✅ | Full API |
| 广发证券 (GF) | ✅ | Full API |
| 中信建投 (CITIC) | ✅ | Full API |
| 同花顺 (iFinD) | ✅ | 通用接口 |
pip install requests pycryptodome websocket-client
# config.py
BROKER_CONFIG = {
'broker': 'huatai', # huatai, galaxy, gf, citic, tonghuashun
'account': '123456789',
'password': 'your_password',
'server': 'trade.htsc.com.cn', # Trading server
'market': 'sz' # sh, sz
}
from quant_trading import TradingAPI
api = TradingAPI(
broker='huatai',
account='123456789',
password='your_password'
)
# Login
api.login()
print(f"Login successful: {api.account_info['account_name']}")
# Real-time quote
quote = api.get_quote('600519')
print(f"Price: {quote['price']}, Volume: {quote['volume']}")
# K-line data
kline = api.get_kline('000858', period='60min', count=100)
print(kline.tail())
# Buy stock
order = api.buy(
symbol='600519',
price=1850.0,
volume=100
)
print(f"Order ID: {order['order_id']}")
# Sell stock
order = api.sell(
symbol='600519',
price=1900.0,
volume=100
)
# Cancel order
api.cancel_order(order_id='123456')
# Get order status
status = api.get_order(order_id='123456')
print(f"Status: {status['status']}")
# Get all orders
orders = api.get_orders(status='pending')
# Get positions
positions = api.get_positions()
for pos in positions:
print(f"{pos['symbol']}: {pos['volume']} shares, P&L: {pos['pnl']}")
# Get account balance
balance = api.get_balance()
print(f"Total Assets: {balance['total_assets']}")
print(f"Available Cash: {balance['available']}")
| Method | Description |
|---|---|
login() | Login to broker |
logout() | Logout |
heartbeat() | Keep connection alive |
| Method | Description |
|---|---|
get_quote(symbol) | Get real-time quote |
get_kline(symbol, period, count) | Get K-line data |
get_orderbook(symbol) | Get order book |
get_trading_calendar(start, end) | Get trading days |
| Method | Description |
|---|---|
buy(symbol, price, volume) | Place buy order |
sell(symbol, price, volume) | Place sell order |
cancel_order(order_id) | Cancel order |
get_order(order_id) | Get order status |
get_orders(status) | Get all orders |
| Method | Description |
|---|---|
get_positions() | Get current positions |
get_trades() | Get today's trades |
get_history(start, end) | Historical records |
| Method | Description |
|---|---|
get_balance() | Get account balance |
get_margin() | Get margin info |
from quant_trading import TradingAPI, Strategy
class MomentumStrategy(Strategy):
def __init__(self, api):
self.api = api
def on_bar(self, bar):
# Check signal
if self.check_signal(bar):
# Place order
self.api.buy(bar['symbol'], bar['close'], 100)
def check_signal(self, bar):
# Your logic
return bar['volume'] > 1000000
# Run strategy
api = TradingAPI(...)
strategy = MomentumStrategy(api)
api.run_strategy(strategy)
# Execute at specific time
api.schedule_order(
symbol='600519',
direction='buy',
price=1850.0,
volume=100,
execute_time='09:35:00'
)
# Set stop loss
api.set_stop_loss(
symbol='600519',
entry_price=1850.0,
stop_loss_pct=0.05 # 5% stop loss
)
# Set take profit
api.set_take_profit(
symbol='600519',
entry_price=1850.0,
take_profit_pct=0.15 # 15% take profit
)
try:
order = api.buy('600519', 1850.0, 100)
except OrderError as e:
print(f"Order failed: {e.message}")
if e.code == 'INSUFFICIENT_BALANCE':
print("Insufficient balance")
elif e.code == 'LIMIT_UP':
print("Stock hit limit up")
elif e.code == 'SUSPENDED':
print("Stock suspended")
| Code | Description |
|---|---|
SUCCESS | Order successful |
INSUFFICIENT_BALANCE | Insufficient cash |
INSUFFICIENT_POSITION | Insufficient shares |
LIMIT_UP | Stock at limit up |
LIMIT_DOWN | Stock at limit down |
SUSPENDED | Stock suspended |
NOT_TRADING | Outside trading hours |
INVALID_PRICE | Price out of range |