Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
developers:websocket:orders [2025/03/14 20:15] – created chad | developers:websocket:orders [2025/03/14 22:10] (current) – chad | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Order Routing ==== | + | ===== Order Routing |
- | The WebSocket API provides real-time order routing | + | The WebSocket API provides real-time order routing, allowing clients to submit, revise, and pull orders. |
- | This section covers: | ||
- | * Submitting Orders | ||
- | * Revising Orders | ||
- | * Pulling Orders | ||
- | * Handling Order Updates | ||
- | A **C# helper tool** is available to assist developers in constructing order messages. **[Repository Placeholder - Add Link]** | + | ==== Submitting an Order ==== |
- | === Submitting | + | To submit |
- | To submit | + | < |
+ | You must subscribe to the Account before submitting | ||
+ | </ | ||
Example **OrderSubmit** message: | Example **OrderSubmit** message: | ||
< | < | ||
- | message ClientMessage | + | OrderSubmit |
- | oneof payload | + | UserId = " |
- | | + | |
- | } | + | |
+ | | ||
+ | | ||
+ | BuySell | ||
+ | PriceType = PriceType.Limit, | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ] | ||
} | } | ||
- | message OrderSubmit { | + | </ |
- | string user_id = 1; | + | |
- | string account_id = 2; | + | |
- | string market_id = 3; | + | |
- | repeated Order orders = 4; | + | |
- | | + | < |
- | | + | The **OrderSubmit** |
- | | + | </ |
- | | + | |
- | int32 volume | + | |
- | | + | ==== Revising an Order ==== |
- | } | + | |
+ | To revise an existing order, clients send an **OrderRevise** message. | ||
+ | |||
+ | Example **OrderRevise** message: | ||
+ | |||
+ | < | ||
+ | OrderRevise | ||
+ | UserId | ||
+ | AccountId | ||
+ | MarketId | ||
+ | Revisions | ||
+ | { | ||
+ | | ||
+ | Volume = 10, | ||
+ | | ||
+ | | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | The **OrderSubmit** message allows | + | < |
+ | The **OrderRevise** message allows | ||
+ | </ | ||
- | === Revising an Order === | ||
- | To revise | + | ==== Pulling (Cancelling) |
- | Example **OrderRevise** message: | + | To cancel an order, clients must send an **OrderPull** message with the **order ID**. |
+ | |||
+ | Example **OrderPull** message: | ||
< | < | ||
- | message ClientMessage | + | OrderPull |
- | oneof payload | + | UserId = " |
- | | + | |
- | } | + | |
+ | Pulls = [ | ||
+ | | ||
+ | UniqueId | ||
+ | } | ||
+ | ] | ||
} | } | ||
+ | </ | ||
- | message | + | < |
- | | + | The **OrderPull** |
- | | + | </ |
- | | + | |
- | | + | |
+ | ===== Order Types ===== | ||
+ | |||
+ | The WebSocket API supports a variety of order types to accommodate different trading strategies. Below are the supported order types, along with their corresponding **OrderSubmit** messages. | ||
+ | |||
+ | |||
+ | |||
+ | ==== Market Order ==== | ||
+ | |||
+ | A Market Order executes immediately at the best available price. | ||
+ | |||
+ | Example **Market Order** message: | ||
+ | |||
+ | < | ||
+ | OrderSubmit | ||
+ | UserId | ||
+ | AccountId | ||
+ | MarketId | ||
+ | Orders = [ | ||
+ | { | ||
+ | | ||
+ | | ||
+ | TimeType = TimeType.Normal, | ||
+ | | ||
+ | } | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | Only fields that need to be changed should be included. | ||
- | === Pulling (Cancelling) an Order === | ||
- | To cancel an order, clients must send an **OrderPull** message with the **order ID**. | ||
- | Example **OrderPull** message: | + | ==== Limit Order ==== |
+ | |||
+ | A Limit Order is submitted with a specific limit price. The order will only execute at the specified price or better. | ||
+ | |||
+ | Example **Limit Order** message: | ||
< | < | ||
- | message ClientMessage | + | OrderSubmit |
- | oneof payload | + | UserId = " |
- | | + | |
- | } | + | |
+ | | ||
+ | | ||
+ | BuySell | ||
+ | PriceType = PriceType.Limit, | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ] | ||
} | } | ||
+ | </ | ||
- | message | + | |
- | | + | |
+ | |||
+ | ==== Stop Order ==== | ||
+ | |||
+ | A Stop Market Order becomes a Market Order when the stop price is reached. | ||
+ | |||
+ | Example **Stop Order** | ||
+ | |||
+ | < | ||
+ | OrderSubmit | ||
+ | UserId = " | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | Once an order is successfully canceled, an **OrderUpdate** message will be sent in the **ServerMessage**. | ||
- | === Handling Order Updates === | ||
- | All order state changes, including new orders, fills, revisions, and cancellations, | ||
- | Example **OrderUpdate** message: | + | ==== Stop Limit Order ==== |
+ | |||
+ | A Stop Limit Order becomes a Limit Order when the stop price is reached. | ||
+ | |||
+ | Example **Stop Limit Order** message: | ||
< | < | ||
- | message ServerMessage | + | OrderSubmit |
- | oneof payload | + | UserId = " |
- | | + | |
- | } | + | |
+ | | ||
+ | | ||
+ | BuySell | ||
+ | PriceType = PriceType.StopLimit, | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ] | ||
} | } | ||
+ | </ | ||
- | message | + | |
- | | + | |
- | | + | |
- | | + | ==== Trailing Stop Order ==== |
- | | + | |
+ | A Trailing Stop Order moves the stop price automatically based on price movement. | ||
+ | |||
+ | Example **Trailing Stop Order** | ||
+ | |||
+ | < | ||
+ | OrderSubmit | ||
+ | UserId = " | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | StopPrice | ||
+ | TrailPrice | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Fill or Kill (FOK) Order ==== | ||
+ | |||
+ | A Fill or Kill (FOK) Order must be executed immediately in full or it is canceled. | ||
+ | |||
+ | Example **Fill or Kill (FOK) Order** message: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Immediate or Cancel (IOC) Order ==== | ||
+ | |||
+ | An Immediate or Cancel (IOC) Order executes immediately for the available quantity and cancels the rest. | ||
+ | |||
+ | Example **Immediate or Cancel (IOC) Order** message: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Good Till Canceled (GTC) Order ==== | ||
+ | |||
+ | A Good Till Canceled (GTC) Order remains open until it is filled or explicitly canceled. | ||
+ | |||
+ | Example **Good Till Canceled (GTC) Order** message: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Order Cancels Order (OCO) ==== | ||
+ | |||
+ | An OCO (One Cancels Other) order is a pair of orders submitted together. Both orders are on the same side of the market: one is a Limit Order and the other is a Stop Order. When one fills, the other is automatically canceled. If one order is partially filled, the remaining volume of the other order is adjusted accordingly. | ||
+ | |||
+ | OCO orders must be placed for the **same Market and Account**. | ||
+ | |||
+ | Example OrderSubmit message for an OCO order: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }, | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Both orders are placed at the same time. If the Limit Order is filled, the Stop Order is automatically canceled, and vice versa. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== AutoOCO Order ==== | ||
+ | |||
+ | An AutoOCO Order is a batch of three orders: | ||
+ | | ||
+ | * Two OCO Orders (Take Profit and Stop Loss) that execute based on the trigger order' | ||
+ | |||
+ | If the Trigger Order fills, the OCO Orders are submitted. If the OCO Orders begin filling, any remaining volume in the Trigger Order is canceled. | ||
+ | |||
+ | Example OrderSubmit message for an AutoOCO order: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }, | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }, | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Take Profit and Stop Loss ==== | ||
+ | |||
+ | Take profit and stop loss orders are a type of OCO order. The first order in the batch is the **Trigger Order**. Once it fills, the **Take Profit** and **Stop Loss** orders are submitted. | ||
+ | |||
+ | Example OrderSubmit message for a Take Profit / Stop Loss order: | ||
+ | |||
+ | < | ||
+ | OrderSubmit { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }, | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }, | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | Developers should listen for **OrderUpdate** messages to track order execution status. | + | When the **Trigger Order** executes, the **Take Profit** and **Stop Loss** orders are placed. If the price reaches the take profit level, the stop loss order is canceled, and vice versa. |
- | This structure ensures a **consistent, | ||