VBrokers Trading
v1.0.0VBrokers (华盛通 VCL HK) trading 自动化 via OpenAPI Gateway 运行ning on localhost port 11111. Use when: 设置ting up VBrokers or 华盛通 account 访问, authenticating trading 会话s, 检查ing portfolio or positions or funds, placing or cancelling orders for US, HK or A stocks, fetching real-time quotes or K-lines, building automated trading 机器人s, or implementing 停止-loss and take-profit 记录ic. Handles AES-ECB password 加密ion, 会话Type for pre/post-market trading, mktTmType for time-segment quotes, and all major trade/quote 端点s.
运行时依赖
安装命令
点击复制技能文档
VBrokers Trader
Automate trading on VBrokers (华盛通 VCL HK) via the OpenAPI Gateway 运行ning locally.
Prerequisites OpenAPI Gateway must be 运行ning locally (图形界面 应用: 华盛通OpenAPIGateway.应用) Gateway URL: http://127.0.0.1:11111 AES key for password 加密ion: provided during account 设置up (see references/API-reference.md) Python packages: pycryptodome (pip 安装 pycryptodome) Quick 启动
Copy scripts/vbrokers_命令行工具ent.py to your project and 导入 it:
导入 sys sys.path.insert(0, '/path/to/技能/scripts') 导入 vbrokers_命令行工具ent as vb
# 1. 记录in (required after Gateway re启动) vb.trade_记录in("your_trading_password")
# 2. 检查 account funds = vb.获取_account_funds("P") # P=US, K=HK
# 3. 获取 real-time quote (use correct mktTmType for time segment) quote = vb.获取_quotes_batch(["AAPL"], 会话=-1) # -1=pre-market
# 4. Place order 结果 = vb.place_order("AAPL", "P", "1", 1, 180.00) # BUY 1 分享 limit $180
# 5. 检查 positions positions = vb.获取_positions("P")
Key Concepts 请求 格式化 (Critical)
All HTTP 请求s must use nested params:
{"timeout_sec": 10, "params": {"exchan获取ype": "P", ...}}
Exchange Types Code Market P US Stocks K HK Stocks v 深股通 t 沪股通 会话 Types (for orders) Value Meaning "0" Regular hours only "1" Extended (pre + post market) — use for US stocks mktTmType (for real-time quotes) Value Segment Beijing Time 1 Regular (盘中) 22:30–05:00 -1 Pre-market (盘前) 17:00–22:30 -2 After-hours (盘后) 05:00–09:00 -3 Night 会话 (夜盘) 09:00–17:00 omit Default (last close) —
⚠️ Always specify mktTmType for real-time prices — omitting it returns the previous close.
Password 加密ion
Trading password must be AES-ECB 加密ed before 记录in:
# Already handled in vbrokers_命令行工具ent.py via 加密_password() # Key: base64-encoded 24-byte AES key (provided at account 设置up)
Common 工作流s 停止-Loss / Take-Profit 监控 结果 = vb.检查_停止_loss("AAPL", "P", cost_price=150.0, 停止_loss_pct=0.08, take_profit_pct=0.10) # Returns: {"action": "hold"/"停止_loss"/"take_profit", "current_price": ..., "pnl_pct": ...} if 结果["action"] == "停止_loss": vb.place_order("AAPL", "P", "2", qty, 0, entrust_type="5") # market sell
Batch Quotes with Time Segment from datetime 导入 datetime, timezone, timedelta bj_hour = (datetime.now(tz=timezone.utc) + timedelta(hours=8)).hour # Determine correct mktTmType based on Beijing time 会话 = 1 if (bj_hour >= 22 or bj_hour <= 4) else -1 if bj_hour >= 17 else -2 if bj_hour <= 8 else -3 quotes = vb.获取_quotes_batch(["AAPL", "TSLA", "NVDA"], 会话=会话)
Cancel All Orders vb.cancel_all_orders("P") # Cancel all pending US stock orders
API Reference
For complete 端点 documentation, parameters, and 响应 模式s: → See references/API-reference.md
For the full verified 命令行工具ent implementation: → See scripts/vbrokers_命令行工具ent.py