Order update streams provide real-time notifications for all order-related events including submissions, fills, cancellations, and rejections. Use these updates to maintain accurate order state and implement trading algorithms.
Order update streams require authentication and an explicit subscription to the orders channel.
Related Events: When an order fills, you may receive additional account events (position and balance updates) regardless of your subscriptions. This ensures you don’t miss account-wide changes triggered by order execution.
pendingsubmit: Order created but not yet submitted to matching enginewaitingtrigger: Order waiting for trigger condition (stop/take profit orders)submitted: Order submitted to matching engine and waiting for execution
Execution Statuses
partiallyfilled: Order partially executed, remainder still activefilled: Order completely executedpartiallyfilledcancelled: Order partially filled then cancelled
Final Statuses
cancelled: Order cancelled by user or systemrejected: Order rejected (insufficient balance, invalid parameters, etc.)inactive: Order is inactive due to account restrictionspendingcancel: Order cancellation requested but not yet confirmed
fillPx: The price of the most recent fill. Useful for tracking individual fill prices, especially for orders that fill at multiple price levels.filledFees: Total fees accumulated from all fills. Essential for calculating net proceeds and tracking trading costs.avgPx vs fillPx: avgPx shows the volume-weighted average price across all fills, while fillPx shows the price of the latest individual fill.
Order Identification
clientOrderId: Your custom identifier for the order. Useful for matching order updates to your internal order management system.entryPositionId and exitPositionId: Links orders to specific positions. entryPositionId is set when opening a position, exitPositionId when closing.orderType: Shows whether the order was limit, market, stop, etc. Helpful for strategy analysis.
Error Handling
reason: Only present for rejected orders. Provides specific rejection reasons like “insufficient balance”, “invalid price”, etc.side: Explicitly shows buy or sell to avoid ambiguity.orderSize: The original order size, useful for calculating fill percentages and remaining quantities.
Use order updates to trigger next steps in complex trading strategies:
function handleAlgorithmicTrade(orderData) { if (orderData.status === 'filled') { // Order completed, execute next strategy step executeNextStrategyStep(orderData); } else if (orderData.status === 'partiallyfilled') { // Partial fill, may need to adjust remaining order adjustRemainingOrder(orderData); } else if (orderData.status === 'rejected') { // Handle rejection in strategy handleStrategyRejection(orderData); }}
Risk Management
Monitor order fills for risk limit enforcement:
function enforceRiskLimits(orderData) { if (orderData.status === 'filled' || orderData.status === 'partiallyfilled') { const position = calculateNewPosition(orderData); if (exceedsRiskLimits(position)) { console.log('🚨 Risk limit exceeded, reducing position'); placeOffsetOrder(orderData); } }}
Order Management UI
Update trading interface with real-time order status:
function updateOrderUI(orderData) { const row = document.getElementById(`order-${orderData.orderId}`); if (row) { row.querySelector('.status').textContent = orderData.status; row.querySelector('.filled').textContent = orderData.executedQty; row.querySelector('.remaining').textContent = orderData.remainingQty; if (orderData.avgPx) { row.querySelector('.avg-price').textContent = orderData.avgPx; } }}
class RobustOrderManager extends OrderManager { onReconnected() { // Refresh order state after reconnection this.requestOrderSummary(); } async requestOrderSummary() { try { const response = await fetch('/api/orders/active', { headers: { 'Authorization': `Bearer ${this.apiKey}` } }); const orders = await response.json(); // Sync local state with server state this.syncOrderState(orders); } catch (error) { console.error('Failed to sync order state:', error); } }}
Duplicate Updates
Handle potential duplicate order updates:
function handleOrderUpdate(orderData) { const lastUpdate = this.getLastUpdate(orderData.orderId); // Check if this is a duplicate update if (lastUpdate && lastUpdate.timestamp >= orderData.timestamp) { console.log('🔄 Ignoring duplicate order update'); return; } // Process the update this.processOrderUpdate(orderData);}