/** * Trading Response Types * * Response types for trading operations. */ import type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, Order, OrderSide, OrderStatus, OrderType, PositionSide, TimeInForce, TradingMode } from "./orders"; /** * Match result information for order execution. * Contains detailed information about trades, fills, and execution quality. * * @remarks * This structure is returned after an order is processed by the matching engine, * providing details about how the order was executed, including fills, slippage, * and final order status. */ export interface MatchResult { /** Number of trades executed during matching */ trades_count: number; /** Total quantity filled across all trades (in base currency) */ total_filled: string; /** Remaining unfilled quantity after immediate matches (in base currency) */ remaining_quantity: string; /** Average fill price across all trades (null if no fills occurred) */ average_fill_price: string | null; /** Final order status after matching (e.g., FILLED, PARTIALLY_FILLED, etc.) */ status: OrderStatus; /** Actual slippage experienced in basis points (positive = worse price, null if no fills) */ actual_slippage_bps: number | null; /** Maximum slippage allowed when order was submitted in basis points (null if not set) */ max_slippage_bps: number | null; /** Price range across executed trades (null if no fills) */ execution_price_range: { /** Best (most favorable) execution price achieved */ best_price: string; /** Worst (least favorable) execution price achieved */ worst_price: string; } | null; } /** * Response from creating an order. * * @remarks * Contains the order ID, operation status, and optional match result * with details about immediate fills that occurred during order placement. */ export interface CreateOrderResponse { /** Created order identifier (UUID) */ order_id: string; /** Operation status (SUCCESS or FAILED) */ status: "SUCCESS" | "FAILED"; /** Operation message describing the result (e.g., "Order processed with 2 trades") */ message: string; /** Match result information if order was processed by matching engine */ match_result?: MatchResult; } /** * Response from cancelling an order. */ export interface CancelOrderResponse { /** Order identifier */ order_id: string; /** Cancellation status */ status: "SUCCESS" | "FAILED"; /** Optional response message */ message?: string; } /** * Response from replacing an order. */ export interface ReplaceOrderResponse { /** New order identifier (after replacement) */ order_id: string; /** Replace operation status */ status: "SUCCESS" | "FAILED"; /** Operation message */ message: string; /** Fields that were updated */ updated_fields: UpdatedFields; /** Original order identifier that was replaced */ original_order_id?: string; /** Match result information for the new order */ match_result?: MatchResult; } /** * Fields that were updated in the replace operation */ export interface UpdatedFields { /** Updated price (if changed) */ price?: string; /** Updated quantity (if changed) */ quantity?: string; } /** * Query parameters for getting paginated orders */ export interface GetPaginatedOrdersParams { /** Filter by order status */ status?: OrderStatus; /** Filter by trading pair UUID */ trading_pair_id?: string; /** Filter by trading mode */ trading_mode?: TradingMode; /** Filter by margin account UUID */ margin_account_id?: string; /** Page number for pagination (default: 1) */ page?: number; /** Number of orders per page (default: 10, max: 100) */ page_size?: number; } /** * Response from getting paginated orders */ export interface GetPaginatedOrdersResponse { /** Latest orders from Redis cache (real-time, instant updates). * These are the most recently created/updated orders that may not yet be in PostgreSQL. * Only populated on page 1. */ latest_orders?: Order[]; /** Array of historical orders from PostgreSQL (paginated) */ orders: Order[]; /** Total number of orders matching the query */ total: number; /** Current page number */ page: number; /** Number of orders per page */ page_size: number; /** Total number of pages */ total_pages: number; } /** * Response from getting a single order by ID */ export interface GetOrderResponse { /** Order data */ order: Order; /** Request status */ status: "SUCCESS" | "FAILED"; } /** * Error details for a failed batch cancel operation on a single order */ export interface BatchCancelError { /** Error code */ code: string; /** Error message */ message: string; } /** * Result of a batch cancel operation for a single order */ export interface BatchCancelResult { /** Order identifier */ order_id: string; /** Timestamp when the order was canceled (ISO 8601 format) */ cancelled_at?: string; /** Error details if the cancellation failed */ error?: BatchCancelError; } /** * Response from batch cancelling orders */ export interface BatchCancelOrdersResponse { /** Total number of orders requested to cancel */ total_requested: number; /** Total number of orders successfully canceled */ total_cancelled: number; /** Total number of orders that failed to cancel */ total_failed: number; /** Individual results for each order */ results: BatchCancelResult[]; } /** * Error details for a failed batch operation on a single order */ export interface BatchError { /** Error code */ code: string; /** Error message */ message: string; } /** * Result of a batch create operation for a single order */ export interface BatchCreateResult { /** Order identifier (empty string if creation failed before ID assignment) */ order_id: string; /** Match result information if the order was processed */ match_result?: MatchResult; /** Error details if the creation failed */ error?: BatchError; } /** * Response from batch creating orders */ export interface BatchCreateOrdersResponse { /** Total number of orders requested to create */ total_requested: number; /** Total number of orders successfully created */ total_succeeded: number; /** Total number of orders that failed to create */ total_failed: number; /** Individual results for each order */ results: BatchCreateResult[]; } /** * Result of a batch replace operation for a single order */ export interface BatchReplaceResult { /** Original order identifier */ original_order_id: string; /** New order identifier (if successful) */ new_order_id?: string; /** Fields that were updated (if successful) */ updated_fields?: UpdatedFields; /** Match result information if the new order was processed */ match_result?: MatchResult; /** Error details if the replacement failed */ error?: BatchError; } /** * Response from batch replacing orders */ export interface BatchReplaceOrdersResponse { /** Total number of orders requested to replace */ total_requested: number; /** Total number of orders successfully replaced */ total_succeeded: number; /** Total number of orders that failed to replace */ total_failed: number; /** Individual results for each order */ results: BatchReplaceResult[]; } /** * Parameters for a single order in a batch create request */ export interface BatchCreateOrderParams { /** Trading pair UUID */ tradingPairId: string; /** Order type: "LIMIT" or "MARKET" */ orderType: OrderType; /** Order side: "BUY" or "SELL" */ side: OrderSide; /** Order price (required for LIMIT orders) */ price?: string; /** Order quantity */ quantity: string; /** Trading mode (defaults to "SPOT") */ tradingMode?: TradingMode; /** Maximum slippage for market orders as decimal (e.g., 0.01 for 1%) */ slippageTolerance?: number; /** For sub-accounts: use master's balance */ useMasterBalance?: boolean; /** Custom expiration date for GTC orders (ISO 8601 format) */ expirationDate?: string; /** Time in force: "GTC", "IOC", or "FOK" */ timeInForce?: Extract; /** Margin account UUID for margin/perp orders */ marginAccountId?: string; /** Position side for margin/perp orders */ positionSide?: PositionSide; /** Leverage for margin/perp orders */ leverage?: string; /** Whether the order can only reduce existing exposure */ reduceOnly?: boolean; } /** * Parameters for a single order in a batch replace request */ export interface BatchReplaceOrderParams { /** Order ID to replace */ orderId: string; /** New order price (optional) */ price?: string; /** New order quantity (optional) */ quantity?: string; /** For sub-accounts: use master's balance (optional) */ useMasterBalance?: boolean; } /** * Parameters for creating a standalone conditional TP/SL order. */ export interface CreateConditionalOrderParams { tradingPairId: string; marginAccountId: string; conditionType: ConditionalOrderConditionType; triggerPrice: string; triggerSource?: ConditionalOrderTriggerSource; side: OrderSide; positionSide: Exclude; orderType: OrderType; limitPrice?: string; quantity?: string; reduceOnly?: boolean; timeInForce?: Extract; slippageToleranceBps?: number; expiresAt?: string; } export interface CreateConditionalOrderResponse { conditional_order_id: string; status: "SUCCESS" | "FAILED"; message: string; state: ConditionalOrderState; } export interface CancelConditionalOrderResponse { conditional_order_id: string; status: "SUCCESS" | "FAILED"; message: string; } export interface ListConditionalOrdersParams { margin_account_id?: string; trading_pair_id?: string; state?: ConditionalOrderState; page?: number; page_size?: number; } export interface ConditionalOrder { conditional_order_id: string; trading_pair_id: string; margin_account_id: string; position_id?: string; linked_group_id?: string; condition_type: ConditionalOrderConditionType; trigger_source: ConditionalOrderTriggerSource; trigger_price: string; side: OrderSide; position_side: PositionSide; order_type: OrderType; limit_price?: string; quantity?: string; slippage_tolerance_bps?: number; reduce_only: boolean; time_in_force?: TimeInForce; state: ConditionalOrderState; triggered_order_id?: string; triggered_at?: string; cancelled_at?: string; expires_at?: string; failure_reason?: string; created_at: string; updated_at: string; } export interface ListConditionalOrdersResponse { orders: ConditionalOrder[]; total: number; page: number; page_size: number; }