Understanding Order Management Logic in Our Trading System
📌 Understanding Order Management Logic in Our Trading System
Your trading system handles orders in multiple stages to ensure smooth execution, modification, and exit.
Here’s a detailed breakdown of how the Order Management System works.
🔹 1️⃣ Order Flow Stages
Every order follows this 5-step lifecycle:
1️⃣ Order Placement (Execute)
2️⃣ Order Processing (Queues & Validation)
3️⃣ Order Modification (Price/Quantity Adjustments)
4️⃣ Order Execution (Entry Confirmed, Stoploss & Target Set)
5️⃣ Order Exit (Profit, Stoploss, or Manual Exit)
🔹 2️⃣ How Orders Are Managed
Each order is tracked in a queue until it is executed, modified, canceled, or exited.
🛒 Order Placement (EXECUTE)
- When a trade is placed, the system validates: ✅ Valid instrument (e.g.,
NIFTY50
,BANKNIFTY
)
✅ Valid order type (Market
,Limit
,Above/Below
)
✅ Sufficient margin availability - If all conditions pass, it moves to Order Processing.
🔄 Order Processing (QUEUES & VALIDATION)
Once an order is placed, it moves into one of three waiting queues:
1️⃣ Above/Below Waiting Queue
- Used when a Buy/Sell is triggered at a specific price.
- Example: “BUY NIFTY at 19750 when price falls below 19800.”
- The system continuously monitors live price until the trigger condition is met.
2️⃣ Open Waiting Queue
- Holds market orders that haven’t been confirmed yet.
- Once confirmation is received, the trade moves to active positions.
3️⃣ Stoploss & Target Waiting Queue
- Manages exit conditions once a trade is executed.
- Example: “Exit when price hits Stoploss at 19750 or Target at 19900.”
- If Stoploss or Target is reached, the order exits automatically.
✏️ Order Modification (MODIFY)
- Traders can modify an order before execution.
- Allowed changes:
✅ Change Price (e.g., Modify NIFTY Buy from 19750 → 19740)
✅ Change Quantity (e.g., Increase from 1 lot → 2 lots)
✅ Change Stoploss/Target
⚠️ Modification is only allowed if the order is still in the queue.
- If the order is already executed, modification is not possible.
✅ Order Execution (ENTRY CONFIRMED)
Once the order gets filled, it becomes an active position.
- Stoploss & Target are automatically set.
- If Trailing Stoploss is enabled, it adjusts dynamically.
Example of how Trailing SL works:
Price | Stoploss Moves To |
---|---|
19800 | 19750 |
19810 | 19760 |
19820 | 19770 |
🚪 Order Exit (TRADE CLOSED)
An order can exit in three ways:
1️⃣ Stoploss Hit
- If price moves against the trade, Stoploss is triggered.
- Example: Buy at 19800, SL at 19750 → Exits at 19750.
2️⃣ Target Hit
- If price moves in favor, Target is triggered.
- Example: Buy at 19800, Target at 19900 → Exits at 19900.
3️⃣ Manual Exit
- The user manually exits the position before SL/TGT is hit.
- Example: If NIFTY is moving slowly, the trader exits manually at 19850.
Once exited, the position resets, and the trader can place a new order.
🎯 Summary of Order Management Logic
Step | Action | Description |
---|---|---|
1️⃣ Order Placement | EXECUTE |
Validate instrument, order type, and margin |
2️⃣ Order Processing | Queues | Above/Below, Open, Stoploss/Target queues |
3️⃣ Order Modification | MODIFY |
Update price, quantity, SL/TGT (only if pending) |
4️⃣ Order Execution | Active Position | Order gets filled, SL & TGT set |
5️⃣ Order Exit | EXIT |
SL/TGT hit or manual exit |