Order ID vs Trade ID: Trading Scenarios
Order ID vs Trade ID: Trading Scenarios
This document explains the difference between order_id and trade_id through various trading scenarios to help developers understand how these identifiers work in the Premia V4 trading system.
Key Concepts
- order_id: Unique identifier for individual limit orders (32-character hex string). Generated when a limit order is posted to the orderbook.
- trade_id: Unique identifier for executed trades (32-character hex string). Generated when a market order is filled against limit orders.
Relationship: Multiple trades can reference the same order_id when a single limit order is filled across multiple market orders (partial fills). Each trade execution generates a unique trade_id.
Trading Scenarios
Scenario 1: Simple Market Order (Fully Filled)
You place: Market BUY order for 10 contracts
Order book has:
- SELL limit order A: 10 contracts @ $100
Results:
- Your trade record:
order_id:abc123(your order)trade_id:abc123(same as your order_id)direction: buytaker_fee: 0.008
- Counterparty record:
order_id:def456(their limit order)trade_id:abc123(your order id)direction: selltaker_fee: 0 (they're maker)
Scenario 2: Market Order with Multiple Fills
You place: Market BUY order for 20 contracts
Order book has:
- SELL limit order A: 10 contracts @ $100
- SELL limit order B: 10 contracts @ $101
Results:
- Your trade record:
order_id:abc123trade_id:abc123size: 20average_price: 100.5taker_fee: 0.016
- Counterparty A record:
order_id:def456trade_id:abc123size: 10price: 100
- Counterparty B record:
order_id:ghi789trade_id:abc123size: 10price: 101
Scenario 3: Limit Order That Crosses (Takes Liquidity)
You place: Limit BUY order for 15 @ $105 (crosses the spread)
Order book has:
- SELL limit order A: 10 @ $100
Results:
- Immediate fill (you as taker):
order_id:abc123trade_id:abc123size: 10taker_fee: 0.008
- Counterparty record:
order_id:def456trade_id:abc123size: 10taker_fee: 0
- Your remaining order: 5 contracts @ $105 posted to order book
Scenario 4: Your Limit Order Gets Filled Later
Continuing from Scenario 3: Your 5 contracts @ $105 are on the book
Someone else places: Market SELL order for 5 contracts
Results:
- Their trade record (new taker):
order_id:xyz999trade_id:xyz999direction: selltaker_fee: 0.004
- Your fill record (now maker):
order_id:abc123(your original order)trade_id:xyz999(their order)direction: buytaker_fee: 0 (you're maker now)maker_fee: -0.002 (rebate)
Scenario 5: Partial Fill of Large Limit Order
Order book has: SELL limit order A: 100 contracts @ $100
Multiple market orders hit it:
Market Buy #1: 30 contracts
- Limit order record:
order_id:aaa111(unchanged)trade_id:buyer1size: 30
Market Buy #2: 50 contracts
- Limit order record:
order_id:aaa111(still same)trade_id:buyer2size: 50
Market Buy #3: 20 contracts
- Limit order record:
order_id:aaa111(still same)trade_id:buyer3size: 20
Scenario 6: Post-Only Order Rejection
You place: Post-only SELL order @ $99
Order book has: BUY order @ $100
Results:
- Order rejected (would cross)
- No trades generated
- No
trade_idcreated
Scenario 7: Fill-or-Kill (FOK) Success
You place: FOK BUY order for 50 contracts
Order book has:
- SELL order A: 30 @ $100
- SELL order B: 20 @ $101
Results:
- All fills share same
trade_id:- Fill A:
trade_id:abc123, size: 30 - Fill B:
trade_id:abc123, size: 20
- Fill A:
- Atomic execution (all or nothing)
Scenario 8: RFQ (Request for Quote)
Special case where limit orders have specific takers:
You request: RFQ for 100 contracts Market maker responds: Limit order with taker = your address
Results:
order_id: RFQ-specific IDtrade_id: Generated when you accept- Only you can fill this order
Key Patterns to Remember
- Taker always: Has
order_id == trade_id - Maker always: Has
order_id != trade_id - One market order: Creates one
trade_idfor all fills - Limit orders: Keep same
order_idacross multiple fills - Fee indicator: Positive
taker_fee= you're taker; Zero/negative = you're maker
Common Use Cases
Tracking Your Orders
- Use
order_idto track the lifecycle of your limit orders - Use
trade_idto track executions of your market orders
Reconciliation
- Match trades by
trade_idto see all fills from a single market order - Match trades by
order_idto see all fills of a single limit order
Fee Calculation
- Taker fees are charged when you place market orders (
order_id == trade_id) - Maker rebates are earned when your limit orders are filled (
order_id != trade_id)
WebSocket Events
When subscribing to trade events via WebSocket, you'll receive:
order_id: The original order that was filledtrade_id: The execution that filled it- Same patterns apply as described in the scenarios above
For more details on WebSocket subscriptions, see the WebSocket API documentation.
Updated 6 days ago
