Overview
The Orders API allows you to place trading orders on events. Orders are processed asynchronously through a Redis queue and matched by the trading engine.Initiate Order
Endpoint:
POST /order/initiatePlaces a new trading order on an event. Orders are queued and processed asynchronously.Request Body
All request body parameters are validated using Zod schema defined inpackages/zod/src/index.ts:9-19.
The event ID to place the order on.Example: “3169798”
The expected price per contract in INR. Must be at least 0.1.Validation: Minimum value of 0.1Example:
5.5The quantity of contracts to trade. Must be at least 0.1.Validation: Minimum value of 0.1Example:
100The side of the order.Allowed values:
"buy" or "sell"Example: "buy"The type of order.Allowed values:
"LO"- Limit Order"MO"- Market Order
"LO"The user ID placing the order.Example: “user_12345”
Request Validation
The endpoint uses theinitiateOrderValidator middleware which validates the request body against the following Zod schema:
Response
Always
true for successfully queued ordersHTTP status code:
201Success message: “Order placed successfully”
Example Request
Example Response
201 - Success
422 - Validation Error (Invalid Price)
422 - Validation Error (Invalid Offer Type)
422 - Validation Error (Invalid Order Type)
Order Processing Flow
Order Types
Based on the source code atpackages/types/src/index.ts, here are the order-related type definitions:
Order Status Enum
Order Sides Enum
Order Type
Order Interface (Engine)
Message Types
When orders are placed, they are queued with the following message structure:CREATE_ORDER Message
ORDER_PLACED Response
After successful matching, the engine responds with:Implementation Notes
Source Code Reference:
- Order routes:
apps/server/src/router/orderRouter.ts - Order handlers:
apps/server/src/controllers/order/index.ts:16-38 - Validation middleware:
apps/server/src/middlewares/validators/initiate.validator.ts - Zod schema:
packages/zod/src/index.ts:9-19 - Type definitions:
packages/types/src/index.ts
Asynchronous Processing
Orders are processed asynchronously through a Redis queue. The API endpoint returns immediately after queueing the order. To receive order execution updates, subscribe to WebSocket events (see WebSocket API).Order Queue Structure
Each order in the queue has the following structure (fromapps/server/src/controllers/order/index.ts:22-32):
Limit Orders vs Market Orders
- Limit Order (LO): Order will only execute at the specified price or better
- Market Order (MO): Order will execute at the best available price immediately