DocsType Reference

Order & Position Types

OrderMeta

Metadata attached to orders for tracking and analysis. All fields are optional.

interface OrderMeta { signal?: string; // Signal name shown in results (e.g., 'buy', 'sell') reason?: string; // Human-readable reason type?: 'full_entry' | 'full_exit' | 'partial_entry' | 'partial_exit'; [key: string]: unknown; // Custom fields }
ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'ema_crossover', type: 'full_entry', confidence: 0.85, // custom field });

Position

Returned by ctx.position(symbol). Reflects the current state of your position.

interface Position { qty: number; // Quantity held (positive = long, negative = short, 0 = flat) avgPrice: number; // Average entry price unrealizedPnL: number; // Unrealized profit/loss at current bar realizedPnL: number; // Realized profit/loss from closed trades }

Common Patterns

const pos = ctx.position('ASSET'); // Check if flat if (pos.qty === 0) { /* no position */ } // Check if long if (pos.qty > 0) { /* holding long */ } // Check if short if (pos.qty < 0) { /* holding short */ } // Check profit if (pos.unrealizedPnL > 0) { /* in profit */ }

OrderAPI

The full order interface available via ctx.order:

interface OrderAPI { market(symbol: string, qty: number, meta?: OrderMeta): void; close(symbol: string, meta?: OrderMeta): void; reduce(symbol: string, pct: number, meta?: OrderMeta): void; limit(symbol: string, qty: number, price: number, meta?: OrderMeta): void; stop(symbol: string, qty: number, stopPrice: number, meta?: OrderMeta): void; }
MethodDescription
market()Immediate fill at next bar's open
close()Close entire position
reduce()Reduce position by a percentage (0–1)
limit()Fill when price reaches the limit
stop()Fill when price reaches the stop

See the Strategy API for detailed usage of each method.

orderpositionOrderMetaPositionqtyavgPricesignalmarketclosereduce