SeekAlgo/Docs/Strategy API
Docs/sdk/Strategy API

Strategy API

Full reference for `strategy.*` helpers used by the public scripting surface.

Strategy API

The current strategy API is id-driven. New public scripts should use object-style entry and exit calls.

Entry

strategy.entry({ id: 'trade_1', type: 'long' });
strategy.entry({ id: 'trade_2', type: 'short', qty: 2 });

Basket Entry

strategy.entry({
  id: 'btc_leg',
  type: 'long',
  symbol: 'BTCUSDT:BINANCE:FUTURE:DEFAULT',
});

strategy.entry({
  id: 'eth_leg',
  type: 'long',
  qty: 3,
  symbol: 'ETHUSDT:BINANCE:FUTURE:DEFAULT',
});

Readable Strategy Defaults

Property Purpose
strategy.default_qty_value Raw default quantity value from script({...})
strategy.default_qty_type Default sizing mode from script({...})
strategy.initial_capital Initial capital from script({...})

Qty Precedence

When qty is omitted, the platform uses orderSize and orderType from the script header. When qty is present, that explicit quantity overrides the header default. strategy.default_qty_value is the raw configured value, so for cur and poe sizing you should still omit qty if you want the settings-driven behavior.

strategy.entry({ id: 'default_trade', type: 'long' });
strategy.entry({ id: 'override_trade', type: 'long', qty: 10 });

const headerTrade = strategy.default_qty_type === 'con'
  ? { id: 'header_trade', type: 'long', qty: strategy.default_qty_value }
  : { id: 'header_trade', type: 'long' };

strategy.entry(headerTrade);

Exit

strategy.exit({ id: 'trade_1' });
strategy.exit({ id: 'btc_leg', symbol: 'BTCUSDT:BINANCE:FUTURE:DEFAULT' });

Position And State Helpers

Method Purpose
strategy.position(id) Signed position size
strategy.positionSize(id) Absolute position size
strategy.entryPrice(id) Entry price for the active position
strategy.isLong(id) Whether the position is long
strategy.isShort(id) Whether the position is short
strategy.isFlat(id) Whether no position is open
strategy.unrealizedPnl(id) Open P&L
strategy.openPositionCount() Count of open positions
strategy.positionIds() All tracked position ids
strategy.param_by_id(id, param) Compatibility helper used across current samples

Position Check Example

if (strategy.param_by_id('trade_1', 'position') === 0) {
  strategy.entry({ id: 'trade_1', type: 'long' });
}

Close Helpers

Method Purpose
strategy.exit({ id }) Exit a specific trade
strategy.close(id) Alias-style close helper
strategy.closeAll() Close all open trades
  • keep one stable id per trade idea
  • check the position before sending a new entry
  • use the same id for entry and exit
  • pass symbol for basket legs
  • use qty only when you want to override the script default
  • keep risk logic simple enough to inspect in the chart