triggers

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Triggers - Complete API Reference

触发器 - 完整API参考

Set up conditional orders that automatically execute trades when price conditions are met. Works across prediction markets, futures, and crypto spot.

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

Chat Commands

聊天命令

Create Trigger Orders

创建触发订单

/trigger buy poly "Trump 2028" YES below 0.40 size 100
/trigger buy poly "Fed rate" NO above 0.60 size 50
/trigger sell poly "Trump 2028" YES above 0.55 size all
/trigger buy poly "Trump 2028" YES below 0.40 size 100
/trigger buy poly "Fed rate" NO above 0.60 size 50
/trigger sell poly "Trump 2028" YES above 0.55 size all

Futures Triggers

期货触发器

/trigger long binance BTCUSDT below 95000 size 0.1 leverage 10x
/trigger short binance ETHUSDT above 4000 size 1 leverage 20x
/trigger close binance BTCUSDT above 105000
/trigger long binance BTCUSDT below 95000 size 0.1 leverage 10x
/trigger short binance ETHUSDT above 4000 size 1 leverage 20x
/trigger close binance BTCUSDT above 105000

Crypto Spot Triggers

加密货币现货触发器

/trigger buy sol SOL below 180 size 100usdc
/trigger sell eth ETH above 4000 size 0.5
/trigger swap arb USDC to ARB below 1.50 size 500
/trigger buy sol SOL below 180 size 100usdc
/trigger sell eth ETH above 4000 size 0.5
/trigger swap arb USDC to ARB below 1.50 size 500

Manage Triggers

管理触发器

/triggers                        List all active triggers
/triggers pending                Show pending only
/triggers history                Triggered order history
/trigger cancel <id>             Cancel trigger
/trigger cancel all              Cancel all triggers
/triggers                        列出所有活跃触发器
/triggers pending                仅显示待处理触发器
/triggers history                已触发订单历史
/trigger cancel <id>             取消指定触发器
/trigger cancel all              取消所有触发器

Stop-Loss & Take-Profit

止损与止盈

/sl poly "Trump" at 0.35         Stop-loss on position
/tp poly "Trump" at 0.65         Take-profit on position
/trailing-stop poly "Trump" 10%  Trailing stop (% from high)

/sl poly "Trump" at 0.35         对持仓设置止损
/tp poly "Trump" at 0.65         对持仓设置止盈
/trailing-stop poly "Trump" 10%  追踪止损(从高点回落百分比)

TypeScript API Reference

TypeScript API参考

Create Trigger Service

创建触发器服务

typescript
import { createTriggerService } from 'clodds/triggers';

const triggers = createTriggerService({
  // Price monitoring
  checkIntervalMs: 5000,  // Check every 5 seconds

  // Execution
  maxSlippagePercent: 2,
  retryAttempts: 3,

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

// Start monitoring
await triggers.start();
typescript
import { createTriggerService } from 'clodds/triggers';

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

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

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

// 启动监控
await triggers.start();

Create Prediction Market Trigger

创建预测市场触发器

typescript
// Buy YES when price drops below threshold
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,    // Optional: max price for limit
});

console.log(`Trigger ID: ${trigger.id}`);
console.log(`Status: ${trigger.status}`);  // 'pending'

// Sell when price rises above threshold
await triggers.create({
  type: 'exit',
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  direction: 'above',
  triggerPrice: 0.55,
  size: 'all',  // Sell entire position
});
typescript
// 当价格低于阈值时买入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',  // 卖出全部持仓
});

Create Futures Trigger

创建期货触发器

typescript
// Long entry when BTC drops below support
await triggers.create({
  type: 'entry',
  platform: 'binance',
  symbol: 'BTCUSDT',
  side: 'long',
  direction: 'below',
  triggerPrice: 95000,
  size: 0.1,
  leverage: 10,

  // Auto-set SL/TP on fill
  stopLoss: 93000,
  takeProfit: 105000,
});

// Short entry when ETH breaks above resistance
await triggers.create({
  type: 'entry',
  platform: 'bybit',
  symbol: 'ETHUSDT',
  side: 'short',
  direction: 'above',
  triggerPrice: 4000,
  size: 1,
  leverage: 20,
});

// Close position when price target hit
await triggers.create({
  type: 'exit',
  platform: 'binance',
  symbol: 'BTCUSDT',
  direction: 'above',
  triggerPrice: 105000,
  size: 'all',
});
typescript
// 当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',
});

Create Crypto Spot Trigger

创建加密货币现货触发器

typescript
// Buy SOL when price drops
await triggers.create({
  type: 'entry',
  platform: 'jupiter',  // Solana DEX
  tokenIn: 'USDC',
  tokenOut: 'SOL',
  direction: 'below',
  triggerPrice: 180,
  size: 100,  // 100 USDC
  slippagePercent: 1,
});

// Sell ETH when price rises
await triggers.create({
  type: 'exit',
  platform: 'uniswap',  // EVM DEX
  chain: 'ethereum',
  tokenIn: 'ETH',
  tokenOut: 'USDC',
  direction: 'above',
  triggerPrice: 4000,
  size: 0.5,
});
typescript
// 当价格下跌时买入SOL
await triggers.create({
  type: 'entry',
  platform: 'jupiter',  // Solana去中心化交易所
  tokenIn: 'USDC',
  tokenOut: 'SOL',
  direction: 'below',
  triggerPrice: 180,
  size: 100,  // 100 USDC
  slippagePercent: 1,
});

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

Stop-Loss & Take-Profit

止损与止盈设置

typescript
// Set stop-loss on existing position
await triggers.setStopLoss({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  triggerPrice: 0.35,
  size: 'all',
});

// Set take-profit
await triggers.setTakeProfit({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  triggerPrice: 0.65,
  size: 'all',
});

// Trailing stop (follows price up, triggers on pullback)
await triggers.setTrailingStop({
  platform: 'polymarket',
  market: 'will-trump-win-2028',
  side: 'YES',
  trailPercent: 10,  // Trigger if drops 10% from high
  size: 'all',
});
typescript
// 对现有持仓设置止损
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',
});

Multi-Condition Triggers

多条件触发器

typescript
// Trigger only when multiple conditions met
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 },
  ],

  // All conditions must be true
  conditionLogic: 'AND',  // 'AND' | 'OR'

  size: 100,
});
typescript
// 仅当多个条件满足时触发
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,
});

One-Cancels-Other (OCO)

二选一取消(OCO)

typescript
// OCO: Either SL or TP triggers, other cancels
const oco = await triggers.createOCO({
  platform: 'binance',
  symbol: 'BTCUSDT',

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

  takeProfit: {
    direction: 'above',
    triggerPrice: 105000,
    size: 'all',
  },
});
typescript
// OCO:触发止损或止盈其中一个时,另一个自动取消
const oco = await triggers.createOCO({
  platform: 'binance',
  symbol: 'BTCUSDT',

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

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

List & Manage Triggers

列出与管理触发器

typescript
// List all triggers
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(`  Status: ${t.status}`);
  console.log(`  Created: ${t.createdAt}`);
}

// Get pending only
const pending = await triggers.list({ status: 'pending' });

// Get history (triggered)
const history = await triggers.list({ status: 'triggered' });

// Cancel trigger
await triggers.cancel(triggerId);

// Cancel all
await triggers.cancelAll();
typescript
// 列出所有触发器
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();

Event Handlers

事件处理器

typescript
// Trigger activated
triggers.on('triggered', async (trigger, result) => {
  console.log(`Trigger ${trigger.id} activated!`);
  console.log(`Order: ${result.orderId}`);
  console.log(`Fill price: ${result.fillPrice}`);
  console.log(`Size: ${result.filledSize}`);
});

// Trigger failed
triggers.on('failed', (trigger, error) => {
  console.error(`Trigger ${trigger.id} failed: ${error.message}`);
});

// Price approaching trigger
triggers.on('approaching', (trigger, currentPrice) => {
  console.log(`Price ${currentPrice} approaching trigger at ${trigger.triggerPrice}`);
});

typescript
// 触发器被激活
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}`);
});

Supported Platforms

支持的平台

Prediction Markets

预测市场

PlatformEntry TriggersExit TriggersSL/TP
Polymarket
Kalshi
Manifold
平台开仓触发器平仓触发器止损/止盈
Polymarket
Kalshi
Manifold

Futures

期货

PlatformEntry TriggersNative TriggersSL/TP
Binance
Bybit
MEXC✓ Native
Hyperliquid
平台开仓触发器原生触发器止损/止盈
Binance
Bybit
MEXC✓ 原生
Hyperliquid

Crypto Spot

加密货币现货

PlatformEntry TriggersExit Triggers
Jupiter (Solana)
Raydium
Uniswap (EVM)
1inch (EVM)

平台开仓触发器平仓触发器
Jupiter (Solana)
Raydium
Uniswap (EVM)
1inch (EVM)

Trigger Types

触发器类型

TypeDescription
entryOpen new position when triggered
exitClose position when triggered
stop-lossExit to limit losses
take-profitExit to lock in gains
trailing-stopDynamic stop that follows price
ocoOne-cancels-other (SL + TP pair)

类型描述
entry触发时开立新持仓
exit触发时平仓
stop-loss平仓以限制损失
take-profit平仓以锁定收益
trailing-stop随价格动态调整的止损
oco二选一取消(止损+止盈组合)

Price Sources

价格来源

PlatformPrice Source
PolymarketWebSocket mid price
KalshiREST API best bid/ask
BinanceWebSocket mark price
BybitWebSocket last price
JupiterOn-chain oracle

平台价格来源
PolymarketWebSocket中间价
KalshiREST API最优买卖价
BinanceWebSocket标记价格
BybitWebSocket最新成交价
Jupiter链上预言机

Examples

示例

Prediction Market Strategy

预测市场策略

typescript
// Buy the dip, sell the rip
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',
});
typescript
// 逢低买入,逢高卖出
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',
});

Futures Breakout Strategy

期货突破策略

typescript
// Enter long on breakout above resistance
await triggers.create({
  platform: 'binance',
  symbol: 'BTCUSDT',
  side: 'long',
  direction: 'above',
  triggerPrice: 100000,
  size: 0.5,
  leverage: 10,
  stopLoss: 98000,
  takeProfit: 110000,
});
typescript
// 突破阻力位时开多单
await triggers.create({
  platform: 'binance',
  symbol: 'BTCUSDT',
  side: 'long',
  direction: 'above',
  triggerPrice: 100000,
  size: 0.5,
  leverage: 10,
  stopLoss: 98000,
  takeProfit: 110000,
});

DCA on Dips

逢低分批买入(DCA)

typescript
// Buy more as price drops
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 at each level
  });
}

typescript
// 价格下跌时分批买入
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美元
  });
}

Best Practices

最佳实践

  1. Use limit orders — Avoid slippage on triggers
  2. Set expiration — Don't leave triggers forever
  3. Monitor execution — Check fill prices
  4. Use OCO for exits — SL + TP together
  5. Test with small size — Verify triggers work
  6. Account for fees — Include in trigger price
  1. 使用限价订单 — 避免触发时的滑点
  2. 设置有效期 — 不要永久保留触发器
  3. 监控执行情况 — 检查成交价格
  4. 使用OCO进行平仓 — 同时设置止损和止盈
  5. 小金额测试 — 验证触发器功能正常
  6. 考虑手续费 — 将其纳入触发价格计算