Live Trading Interface¶
Version: v1.3.2
Last Updated: 2026-03-25
π‘ Overview¶
Trading Assistant provides free/low-barrier live trading data APIs, supporting A-shares, US stocks, and cryptocurrencies.
Core Features¶
- β Free APIs - Binance, CoinGecko, Sina Finance require no API Key
- β Simulated Trading - Test strategies risk-free
- β Multiple Data Sources - 5 sources with failover for stability
- β Real-Time Quotes - Millisecond-level latency
π― Data Source Comparison¶
Free APIs (Ready to Use)¶
| API | Market | Limit | Use | Status |
|---|---|---|---|---|
| Binance | Crypto | None | Ticker/K-line | β |
| CoinGecko | Crypto | 10-50/min | Prices | β |
| Sina Finance | A-Share/HK/US | None | Real-time quotes | β |
Optional API Keys¶
| API | Free Tier | Market | Use | Status |
|---|---|---|---|---|
| Twelve Data | 800/day | Global | Primary source | β |
| Alpha Vantage | 25/day | US Stocks | Backup source | β |
| Binance | Unlimited | Crypto | Live trading | β |
π Quick Start¶
1. Test Free APIs¶
Output Example:
π‘ Live Trading Interface Info
============================================================
β
Free APIs (Use Immediately):
β’ Binance - Crypto ticker/K-line
β’ CoinGecko - Crypto prices
β’ Sina Finance - A-Share/HK/US quotes
π§ͺ Testing APIs...
1. Binance BTC Ticker:
Price: $67,500.00
24h: +2.35%
2. CoinGecko BTC Price:
Price: $67,480.00
24h: +2.30%
3. Sina Finance Kweichow Moutai:
Kweichow Moutai: Β₯1685.00
Change: +0.93%
β
Test Complete
2. Configure API Keys (Optional)¶
Config File Location: ~/.trading_assistant/trading_config.json
Example Config:
{
"twelve_data_api_key": "your_api_key_here",
"alpha_vantage_api_key": "your_api_key_here",
"use_cache": true,
"cache_ttl_seconds": 300
}
π API Usage Guide¶
Binance (Crypto)¶
No API Key Required - Public endpoints
Get Ticker¶
from live_trading_interface import LiveTradingInterface
interface = LiveTradingInterface()
# Get 24h ticker
ticker = interface.get_binance_ticker('BTCUSDT')
print(f"Price: ${ticker['price']:,.2f}")
print(f"24h Change: {ticker['change_percent']:+.2f}%")
Get K-Line¶
# Get 60 days K-line
kline = interface.get_binance_kline('BTCUSDT', '1d', 60)
for k in kline[-5:]:
print(f"{k['timestamp']}: O:{k['open']} H:{k['high']} L:{k['low']} C:{k['close']}")
CoinGecko (Crypto)¶
Completely Free - No API Key required
Get Price¶
# Get BTC price
price = interface.get_coingecko_price('bitcoin')
print(f"BTC: ${price['price']:,.2f}")
print(f"24h Change: {price['change_24h']:+.2f}%")
Supported Coin IDs:
- bitcoin - BTC
- ethereum - ETH
- solana - SOL
- binancecoin - BNB
- cardano - ADA
Sina Finance (A-Share/HK/US)¶
Completely Free - No API Key required
Get A-Share Quote¶
# Kweichow Moutai (sh600519)
quote = interface.get_sina_quote('sh600519')
print(f"{quote['name']}: Β₯{quote['current']:.2f}")
print(f"Change: {quote['change_percent']:+.2f}%")
Get US Stock Quote¶
# Apple (gbAAPL)
quote = interface.get_sina_quote('gbAAPL')
print(f"{quote['name']}: ${quote['current']:.2f}")
print(f"Change: {quote['change_percent']:+.2f}%")
Symbol Prefixes:
- A-Share: sh (Shanghai) / sz (Shenzhen)
- HK Stock: hk
- US Stock: gb
π° Simulated Trading¶
Place Simulated Order¶
from live_trading_interface import LiveTradingInterface
interface = LiveTradingInterface()
# Simulated BUY 0.1 BTC
order = interface.place_simulated_order(
symbol='BTCUSDT',
side='BUY',
amount=0.1,
price=None # None = Market order
)
print(f"Order ID: {order['order_id']}")
print(f"Status: {order['status']}")
Simulated Account¶
# Get simulated balance
balance = interface.get_simulated_balance()
print(f"Available USDT: ${balance['usdt']:,.2f}")
print(f"Held BTC: {balance['btc']:.4f}")
π§ CLI Commands¶
Show API Info¶
Test APIs¶
Configure API Keys¶
Interactive Configuration:
π‘ Live Trading Interface - API Key Configuration
Select API to configure:
1. Twelve Data (Recommended - 800/day)
2. Alpha Vantage (25/day)
3. Binance (Live trading)
Enter choice [1-3]: 1
Enter API Key: ****************
β
Configuration saved: ~/.trading_assistant/trading_config.json
π Performance Comparison¶
API Latency¶
| API | Avg Latency | Stability | Rating |
|---|---|---|---|
| Binance | 50ms | 99.9% | βββββ |
| CoinGecko | 200ms | 99.5% | ββββ |
| Sina Finance | 100ms | 99.8% | βββββ |
| Twelve Data | 150ms | 99.7% | ββββ |
| Alpha Vantage | 300ms | 98.0% | βββ |
API Limit Comparison¶
| API | Free Tier | Paid Plan | Value |
|---|---|---|---|
| Binance | Unlimited | - | βββββ |
| CoinGecko | 10-50/min | $129/month | ββββ |
| Sina Finance | Unlimited | - | βββββ |
| Twelve Data | 800/day | $29/month (unlimited) | ββββ |
| Alpha Vantage | 25/day | $149.99/month | βββ |
β οΈ Considerations¶
API Limitations¶
- Rate Limits: Avoid excessive requests in short time
- Cache Strategy: System auto-caches for 5 minutes
- Error Handling: Auto-failover to backup sources
Live Trading Risks¶
- Market Risk: High crypto volatility
- Technical Risk: API may fail
- Fund Security: Use regulated exchanges
- Position Management: Don't go all-in on single asset
Best Practices¶
- Start with Simulation: Practice before live trading
- Small Tests: Verify with small amounts first
- Set Stop-Loss: Control risk
- Monitor Logs: Catch issues early
π Related Documents¶
- Technical Indicators - 10 advanced indicators
- Backtest Engine - Strategy backtesting
- Quantitative Strategies - Strategy library
π Support & Feedback¶
GitHub: https://github.com/XuXuClassMate/trading-assistant
Docs: https://xuxuclassmate.github.io/trading-assistant/
Issues: GitHub Issues
Last Updated: 2026-03-25 12:00 UTC
Version: v1.3.2
Data Sources: 5 (3 free + 2 optional)