TradingView Alert 消息模板
{ "action": "BUY", "symbol": "BTCUSDT", "amount_usd": 200}| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
action | enum | ✓ | BUY / SELL / CLOSE |
symbol | string | ✓ | Binance 合约 symbol,如 BTCUSDT |
amount_usd | number | one-of | 以美元计价的仓位大小 |
qty | number | one-of | 以 base asset 计价的数量(和 Binance quantity 一致) |
price | number | limit 必需 | 限价价格(不传=市价) |
reduce_only | bool | 可选 | 只减仓;action=CLOSE 时隐含 |
position_side | enum | 可选 | 双向模式:LONG / SHORT |
amount_usd 和 qty 二选一;都不传 = 用组合默认仓位大小。
Pine 策略示例
Section titled “Pine 策略示例”//@version=5strategy("panshi demo", overlay=true)
fast = ta.sma(close, 20)slow = ta.sma(close, 50)
msg_long = '{"action":"BUY", "symbol":"BTCUSDT","amount_usd":200}'msg_flat = '{"action":"CLOSE", "symbol":"BTCUSDT"}'
if ta.crossover(fast, slow) strategy.entry("L", strategy.long, alert_message=msg_long)if ta.crossunder(fast, slow) strategy.close("L", alert_message=msg_flat)
alertcondition( ta.crossover(fast, slow) or ta.crossunder(fast, slow), "panshi-sim", "")TradingView Alert 的 Message 栏填 {{strategy.order.alert_message}},Pine 拼好的 JSON 就会原样发到 webhook。
{"action":"CLOSE","symbol":"BTCUSDT"}可选附 reduce_only=true 明示。
多组合共享一个 Alert
Section titled “多组合共享一个 Alert”单个组合一个 webhook_token。若要一个 Alert 打给多个组合,建议:
- 在 panshi 端用 跟单 功能:主组合接 webhook,下游组合自动镜像;或
- TV 高级套餐下用多 webhook 同时发多个 URL
- Webhook 配置
- 速率限制
- ccxt 接入示例 — 程序化下单