条件触发交易技能Skill triggers

这个技能用于设置和管理条件触发订单,在预测市场、期货和加密货币现货中自动执行交易,基于价格阈值实现自动化进出场。它支持创建触发订单、止损止盈、OCO订单等功能,适用于量化交易策略、算法交易和风险管理,帮助用户自动化交易执行并优化投资回报。关键词:触发订单、条件执行、量化交易、自动化策略、API交易、止损止盈、高频交易、风险管理。

算法交易 0 次安装 0 次浏览 更新于 3/9/2026

名称: 触发器 描述: “当价格阈值满足时自动执行的条件订单” emoji: “⚡”

触发器 - 完整API参考

设置条件订单,当价格条件满足时自动执行交易。适用于预测市场、期货和加密货币现货。


聊天命令

创建触发订单

/trigger buy poly "特朗普2028" YES 低于 0.40 数量 100
/trigger buy poly "美联储利率" NO 高于 0.60 数量 50
/trigger sell poly "特朗普2028" YES 高于 0.55 数量 全部

期货触发器

/trigger long binance BTCUSDT 低于 95000 数量 0.1 杠杆 10倍
/trigger short binance ETHUSDT 高于 4000 数量 1 杠杆 20倍
/trigger close binance BTCUSDT 高于 105000

加密货币现货触发器

/trigger buy sol SOL 低于 180 数量 100usdc
/trigger sell eth ETH 高于 4000 数量 0.5
/trigger swap arb USDC 到 ARB 低于 1.50 数量 500

管理触发器

/triggers                        列出所有活动触发器
/triggers pending                仅显示待处理
/triggers history                触发器订单历史
/trigger cancel <id>             取消触发器
/trigger cancel all              取消所有触发器

止损与止盈

/sl poly "特朗普" 在 0.35         持仓止损
/tp poly "特朗普" 在 0.65         持仓止盈
/trailing-stop poly "特朗普" 10%  追踪止损(从高点百分比)

TypeScript API 参考

创建触发器服务

import { createTriggerService } from 'clodds/triggers';

const triggers = createTriggerService({
  // 价格监控
  checkIntervalMs: 5000,  // 每5秒检查一次

  // 执行
  maxSlippagePercent: 2,
  retryAttempts: 3,

  // 存储
  storage: 'sqlite',
  dbPath: './triggers.db',
});

// 开始监控
await triggers.start();

创建预测市场触发器

// 当价格低于阈值时买入YES
const trigger = await triggers.create({
  type: 'entry',
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  direction: 'below',
  triggerPrice: 0.40,
  size: 100,  // $100
  orderType: 'limit',  // 'market' | 'limit'
  limitPrice: 0.41,    // 可选:限价单的最高价格
});

console.log(`触发器ID: ${trigger.id}`);
console.log(`状态: ${trigger.status}`);  // 'pending'

// 当价格高于阈值时卖出
await triggers.create({
  type: 'exit',
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  direction: 'above',
  triggerPrice: 0.55,
  size: 'all',  // 卖出全部持仓
});

创建期货触发器

// 当BTC跌破支撑时做多
await triggers.create({
  type: 'entry',
  platform: 'binance',
  symbol: 'BTCUSDT',
  side: 'long',
  direction: 'below',
  triggerPrice: 95000,
  size: 0.1,
  leverage: 10,

  // 成交后自动设置止损止盈
  stopLoss: 93000,
  takeProfit: 105000,
});

// 当ETH突破阻力时做空
await triggers.create({
  type: 'entry',
  platform: 'bybit',
  symbol: 'ETHUSDT',
  side: 'short',
  direction: 'above',
  triggerPrice: 4000,
  size: 1,
  leverage: 20,
});

// 当价格达到目标时平仓
await triggers.create({
  type: 'exit',
  platform: 'binance',
  symbol: 'BTCUSDT',
  direction: 'above',
  triggerPrice: 105000,
  size: 'all',
});

创建加密货币现货触发器

// 当SOL价格下跌时买入
await triggers.create({
  type: 'entry',
  platform: 'jupiter',  // Solana DEX
  tokenIn: 'USDC',
  tokenOut: 'SOL',
  direction: 'below',
  triggerPrice: 180,
  size: 100,  // 100 USDC
  slippagePercent: 1,
});

// 当ETH价格上涨时卖出
await triggers.create({
  type: 'exit',
  platform: 'uniswap',  // EVM DEX
  chain: 'ethereum',
  tokenIn: 'ETH',
  tokenOut: 'USDC',
  direction: 'above',
  triggerPrice: 4000,
  size: 0.5,
});

止损与止盈

// 设置现有持仓的止损
await triggers.setStopLoss({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  triggerPrice: 0.35,
  size: 'all',
});

// 设置止盈
await triggers.setTakeProfit({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  triggerPrice: 0.65,
  size: 'all',
});

// 追踪止损(跟随价格上涨,回调时触发)
await triggers.setTrailingStop({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  trailPercent: 10,  // 从高点下跌10%时触发
  size: 'all',
});

多条件触发器

// 仅当多个条件满足时触发
await triggers.create({
  type: 'entry',
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',

  conditions: [
    { type: 'price', direction: 'below', value: 0.40 },
    { type: 'volume24h', direction: 'above', value: 100000 },
    { type: 'spread', direction: 'below', value: 0.02 },
  ],

  // 所有条件必须为真
  conditionLogic: 'AND',  // 'AND' | 'OR'

  size: 100,
});

一单取消另一单(OCO)

// OCO:要么止损触发,要么止盈触发,另一个取消
const oco = await triggers.createOCO({
  platform: 'binance',
  symbol: 'BTCUSDT',

  stopLoss: {
    direction: 'below',
    triggerPrice: 93000,
    size: 'all',
  },

  takeProfit: {
    direction: 'above',
    triggerPrice: 105000,
    size: 'all',
  },
});

列出和管理触发器

// 列出所有触发器
const all = await triggers.list();

for (const t of all) {
  console.log(`${t.id}: ${t.platform} ${t.market || t.symbol}`);
  console.log(`  ${t.direction} ${t.triggerPrice}`);
  console.log(`  状态: ${t.status}`);
  console.log(`  创建时间: ${t.createdAt}`);
}

// 仅获取待处理
const pending = await triggers.list({ status: 'pending' });

// 获取历史(已触发)
const history = await triggers.list({ status: 'triggered' });

// 取消触发器
await triggers.cancel(triggerId);

// 取消全部
await triggers.cancelAll();

事件处理器

// 触发器激活
triggers.on('triggered', async (trigger, result) => {
  console.log(`触发器 ${trigger.id} 已激活!`);
  console.log(`订单: ${result.orderId}`);
  console.log(`成交价格: ${result.fillPrice}`);
  console.log(`数量: ${result.filledSize}`);
});

// 触发器失败
triggers.on('failed', (trigger, error) => {
  console.error(`触发器 ${trigger.id} 失败: ${error.message}`);
});

// 价格接近触发器
triggers.on('approaching', (trigger, currentPrice) => {
  console.log(`价格 ${currentPrice} 接近触发器在 ${trigger.triggerPrice}`);
});

支持平台

预测市场

平台 入场触发器 出场触发器 止损止盈
Polymarket
Kalshi
Manifold

期货

平台 入场触发器 原生触发器 止损止盈
Binance
Bybit
MEXC ✓ 原生
Hyperliquid

加密货币现货

平台 入场触发器 出场触发器
Jupiter (Solana)
Raydium
Uniswap (EVM)
1inch (EVM)

触发器类型

类型 描述
entry 触发时开新仓
exit 触发时平仓
stop-loss 止损以限制亏损
take-profit 止盈以锁定收益
trailing-stop 动态止损,跟随价格
oco 一单取消另一单(止损止盈对)

价格来源

平台 价格来源
Polymarket WebSocket中间价
Kalshi REST API最佳买/卖价
Binance WebSocket标记价格
Bybit WebSocket最后价格
Jupiter 链上预言机

示例

预测市场策略

// 逢低买入,逢高卖出
await triggers.create({
  platform: 'polymarket',
  market: 'trump-2028',
  side: 'YES',
  direction: 'below',
  triggerPrice: 0.40,
  size: 200,
});

await triggers.create({
  platform: 'polymarket',
  market: 'trump-2028',
  side: 'YES',
  direction: 'above',
  triggerPrice: 0.55,
  size: 'all',
});

期货突破策略

// 当突破阻力时做多
await triggers.create({
  platform: 'binance',
  symbol: 'BTCUSDT',
  side: 'long',
  direction: 'above',
  triggerPrice: 100000,
  size: 0.5,
  leverage: 10,
  stopLoss: 98000,
  takeProfit: 110000,
});

逢低定投

// 价格下跌时买入更多
const levels = [180, 170, 160, 150];
for (const price of levels) {
  await triggers.create({
    platform: 'jupiter',
    tokenOut: 'SOL',
    tokenIn: 'USDC',
    direction: 'below',
    triggerPrice: price,
    size: 50,  // 每个级别$50
  });
}

最佳实践

  1. 使用限价单 — 避免触发器上的滑点
  2. 设置过期时间 — 不要永远保留触发器
  3. 监控执行 — 检查成交价格
  4. 使用OCO平仓 — 止损止盈一起设置
  5. 用小额测试 — 验证触发器工作
  6. 考虑费用 — 在触发器价格中包含费用