PMEXS 支持 A股、港股、美股、币安 Binance 四大市场的数据与交易接入。以下步骤面向量化初学者,按顺序操作即可跑通。
PMEXS 的架构是“静态前端 + Cloudflare Worker 代理”。行情数据可直接调用公共 API;交易下单需要你在对应券商/交易所开通 API 权限,并把 Key 配置到 PMEXS 设置中(建议通过 Worker 代理,不要写死在前端)。
| 市场 | 数据 API | 交易 API | 难度 |
|---|---|---|---|
| A股 | Tushare / AkShare | 券商 QMT / 聚宽 | 中 |
| 港股 | LongPort / 富途 | LongPort / 富途 | 低 |
| 美股 | Yahoo Finance / Polygon | Interactive Brokers | 中 |
| 币安 | Binance Public API | Binance API Key | 低 |
pip install tushareimport tushare as ts
pro = ts.pro_api('your_token')
df = pro.daily(ts_code='000001.SZ', start_date='20240101', end_date='20241231')
print(df.head())
若需实时行情,可接入 AkShare(免费):
import akshare as ak
df = ak.stock_zh_a_spot_em() # 东方财富实时行情
print(df[['代码', '名称', '最新价', '涨跌幅']].head())
交易接口:A股实盘一般通过券商 QMT / PTrade 或聚宽、果仁等平台。将策略导出为 Python 脚本后在券商环境中运行。
pip install longport
from longport.openapi import TradeContext, Config
config = Config.from_env()
ctx = TradeContext(config)
print(ctx.account_balance())
yfinance 库:import yfinance as yf
data = yf.download('SPY', start='2024-01-01', end='2024-12-31')
print(data.tail())
ib_insync 连接 TWS 下单:from ib_insync import *
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)
contract = Stock('AAPL', 'SMART', 'USD')
order = MarketOrder('BUY', 100)
ib.placeOrder(contract, order)
pip install python-binance
from binance.client import Client
client = Client('api_key', 'api_secret')
print(client.get_symbol_ticker(symbol='BTCUSDT'))
前端可直接调用公共行情接口(无需 Key):
fetch('https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT')
.then(r => r.json())
.then(console.log)
NVIDIA_API_KEY。/api/ai,前端可直接调用。