Order Types
TradeStaq supports advanced order types for precise trade execution. Understanding these order types is essential for building effective trading strategies.
Overview
| Order Type | Description | Best For |
|---|---|---|
| Market | Execute immediately at best price | Quick entries/exits |
| Limit | Execute at specified price or better | Precise entries |
| Stop | Trigger market order at price | Stop losses |
| Stop-Limit | Trigger limit order at price | Controlled stops |
| Take Profit | Close position at profit target | Profit taking |
| Trailing Stop | Dynamic stop that follows price | Trend riding |
Market Orders
Execute immediately at the current market price.
// Simple market buy
td.trade.long({ size: 0.1 });
// Market sell
td.trade.short({ size: 0.1 });
// Close position
td.trade.close();
When to Use
- Quick entries during volatile moves
- Emergency exits
- High-liquidity pairs where slippage is minimal
Considerations
- Slippage: May fill at different price than displayed
- Fees: Often higher taker fees
- Guaranteed fill: Will always execute
Limit Orders
Execute at your specified price or better.
// Limit buy at $50,000
td.orders.limit({
side: 'buy',
size: 0.1,
price: 50000,
});
// Limit sell at $52,000
td.orders.limit({
side: 'sell',
size: 0.1,
price: 52000,
});
When to Use
- Specific entry prices
- Support/resistance levels
- When you want maker fees (lower)
Time in Force Options
| Option | Description |
|---|---|
| GTC | Good 'til Cancelled - stays until filled or cancelled |
| IOC | Immediate or Cancel - fill what you can, cancel rest |
| FOK | Fill or Kill - complete fill or nothing |
| GTD | Good 'til Date - expires at specific time |
td.orders.limit({
side: 'buy',
size: 0.1,
price: 50000,
timeInForce: 'GTC',
});
Stop Orders
Trigger a market order when price reaches the stop level.
// Stop loss for long position
td.orders.stop({
side: 'sell',
size: 0.1,
triggerPrice: 49000, // Triggers when price falls to 49000
});
// Stop entry for breakout
td.orders.stop({
side: 'buy',
size: 0.1,
triggerPrice: 51000, // Triggers when price rises to 51000
});
How It Works
- Price reaches trigger price
- Stop order becomes market order
- Executes at best available price
Common Uses
- Stop loss: Limit downside risk
- Breakout entry: Enter on momentum
- Trailing protection: Lock in profits
Stop-Limit Orders
Trigger a limit order when price reaches the stop level.
// Stop-limit sell
td.orders.stopLimit({
side: 'sell',
size: 0.1,
triggerPrice: 49000, // When to activate
limitPrice: 48900, // Minimum price to accept
});
How It Works
- Price reaches trigger price
- Limit order placed at limit price
- Fills only at limit price or better
When to Use
- When you want price protection on stops
- Low liquidity markets
- Large position sizes
Risk
- May not fill: If price gaps through your limit, order won't execute
- Consider using regular stop for critical risk management
Take Profit Orders
Close position when profit target is reached.
// Take profit at $52,000
td.orders.takeProfit({
triggerPrice: 52000,
size: 0.1, // Full position
});
// Partial take profit
td.orders.takeProfit({
triggerPrice: 52000,
size: 0.05, // Half position
});
// Take profit as limit order
td.orders.takeProfit({
triggerPrice: 52000,
limitPrice: 51900, // Minimum acceptable
size: 0.1,
});
Best Practices
- Set take profit before entry
- Consider scaling out at multiple levels
- Use with stop loss for complete risk management
Trailing Stop Orders
A dynamic stop that follows favorable price movement.
// Trailing stop by percentage
td.orders.trailingStop({
side: 'sell',
size: 0.1,
trailPercent: 2, // Trail 2% behind price
});
// Trailing stop by fixed amount
td.orders.trailingStop({
side: 'sell',
size: 0.1,
trailAmount: 500, // Trail $500 behind price
});
// With activation price
td.orders.trailingStop({
side: 'sell',
size: 0.1,
trailPercent: 2,
activationPrice: 52000, // Only activate after reaching $52k
});
How It Works
For a long position:
- Stop price starts at entry - trail distance
- As price rises, stop follows (maintains trail distance)
- If price falls, stop stays in place
- When price hits stop, position closes
Example
| Event | Price | Trailing Stop (2%) |
|---|---|---|
| Entry | $50,000 | $49,000 |
| Price rises | $51,000 | $49,980 |
| Price rises | $52,000 | $50,960 |
| Price falls | $51,500 | $50,960 (unchanged) |
| Price falls | $50,960 | TRIGGERED |
Advanced Order Types
OCO (One-Cancels-Other)
Place stop loss and take profit together. When one fills, the other cancels.
td.orders.oco({
symbol: 'BTC/USDT',
side: 'sell', // To close a long position
size: 0.1,
stopLossPrice: 49000,
takeProfitPrice: 52000,
});
How It Works
- Both orders placed simultaneously
- Price hits take profit → TP fills, SL cancels
- Price hits stop loss → SL fills, TP cancels
Best Practices
- Always use OCO for position exits
- Ensures you don't leave orphan orders
- Reduces margin usage vs separate orders
Bracket Orders
Complete entry + exit package in one command.
td.orders.bracket({
symbol: 'BTC/USDT',
entry: {
type: 'market',
side: 'buy',
size: 0.1,
},
stopLoss: {
type: 'stop',
triggerPrice: 49000,
},
takeProfit: {
type: 'take_profit',
price: 52000,
},
});
// With limit entry
td.orders.bracket({
symbol: 'BTC/USDT',
entry: {
type: 'limit',
side: 'buy',
size: 0.1,
price: 50000,
},
stopLoss: {
type: 'stop',
triggerPrice: 49000,
},
takeProfit: {
type: 'limit',
price: 52000,
},
});
Bracket Lifecycle
- Pending Entry: Entry order placed
- Active: Entry filled, SL/TP orders activated
- Closed: Either SL or TP filled
- Cancelled: Entry cancelled, all orders cancelled
Benefits
- Complete position management
- Automatic risk management
- Clean entry/exit logic
Order Flags
Additional options for fine-tuning order behavior.
| Flag | Description |
|---|---|
reduceOnly | Only reduce position, won't open new |
postOnly | Maker only, rejects if would take |
hidden | Iceberg/hidden order (where supported) |
closeOnTrigger | Close position when triggered |
td.orders.limit({
side: 'sell',
size: 0.1,
price: 52000,
flags: {
reduceOnly: true, // Won't accidentally flip position
postOnly: true, // Maker fees only
},
});
Order Status Lifecycle
Orders progress through these states:
┌─────────────────────────────────────────────────────────────────┐
│ ORDER STATUS LIFECYCLE │
│ │
│ ┌─────────┐ ┌────────┐ ┌──────────────────┐ │
│ │ pending │───▶│ placed │───▶│ partially_filled │ │
│ └─────────┘ └────────┘ └──────────────────┘ │
│ │ │ │
│ │ │ │
│ ▼ ▼ │
│ ┌────────┐ ┌────────┐ │
│ │ filled │ │ filled │ │
│ └────────┘ └────────┘ │
│ │
│ Other Terminal States: │
│ • cancelled - User cancelled │
│ • rejected - Exchange rejected │
│ • expired - Time limit reached │
│ • failed - System error │
└─────────────────────────────────────────────────────────────────┘
Best Practices
1. Always Use Stop Losses
// Entry with immediate SL
if (entryCondition) {
td.trade.long({ size: positionSize });
td.orders.stop({
side: 'sell',
size: positionSize,
triggerPrice: entryPrice * 0.98, // 2% stop
});
}
2. Use Bracket Orders for Complete Protection
// Complete risk-managed entry
td.orders.bracket({
symbol: td.config.symbol,
entry: {
type: 'market',
side: 'buy',
size: td.config.positionSize,
},
stopLoss: {
type: 'stop',
triggerPrice: td.market.price * (1 - td.config.stopLossPercent / 100),
},
takeProfit: {
type: 'take_profit',
price: td.market.price * (1 + td.config.takeProfitPercent / 100),
},
});
3. Consider Slippage
For large positions or illiquid markets:
- Use limit orders where possible
- Add slippage buffer to stops
- Test with paper trading first
4. Monitor Order Status
// Check for filled orders
const openOrders = td.orders.getOpen();
const filledOrders = td.orders.getFilled();
// Cancel stale orders
td.orders.cancelAll();
Exchange Support
Not all order types are supported on every exchange:
| Order Type | Binance | Bybit | OKX | Hyperliquid |
|---|---|---|---|---|
| Market | ✓ | ✓ | ✓ | ✓ |
| Limit | ✓ | ✓ | ✓ | ✓ |
| Stop | ✓ | ✓ | ✓ | ✓ |
| Stop-Limit | ✓ | ✓ | ✓ | - |
| Take Profit | ✓ | ✓ | ✓ | ✓ |
| Trailing Stop | ✓ | ✓ | ✓ | - |
| OCO | ✓ | ✓ | ✓ | - |
| Bracket | ✓* | ✓* | ✓* | ✓* |
*Bracket orders implemented via multiple orders with linking
Next Steps
- Risk Management - Configure loss limits
- Creating Strategies - Build your strategy
- Backtesting - Test your orders