Order Types

TradeStaq supports advanced order types for precise trade execution. Understanding these order types is essential for building effective trading strategies.

Overview

Order TypeDescriptionBest For
MarketExecute immediately at best priceQuick entries/exits
LimitExecute at specified price or betterPrecise entries
StopTrigger market order at priceStop losses
Stop-LimitTrigger limit order at priceControlled stops
Take ProfitClose position at profit targetProfit taking
Trailing StopDynamic stop that follows priceTrend 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

OptionDescription
GTCGood 'til Cancelled - stays until filled or cancelled
IOCImmediate or Cancel - fill what you can, cancel rest
FOKFill or Kill - complete fill or nothing
GTDGood '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

  1. Price reaches trigger price
  2. Stop order becomes market order
  3. 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

  1. Price reaches trigger price
  2. Limit order placed at limit price
  3. 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:

  1. Stop price starts at entry - trail distance
  2. As price rises, stop follows (maintains trail distance)
  3. If price falls, stop stays in place
  4. When price hits stop, position closes

Example

EventPriceTrailing 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,960TRIGGERED

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

  1. Both orders placed simultaneously
  2. Price hits take profit → TP fills, SL cancels
  3. 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

  1. Pending Entry: Entry order placed
  2. Active: Entry filled, SL/TP orders activated
  3. Closed: Either SL or TP filled
  4. 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.

FlagDescription
reduceOnlyOnly reduce position, won't open new
postOnlyMaker only, rejects if would take
hiddenIceberg/hidden order (where supported)
closeOnTriggerClose 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 TypeBinanceBybitOKXHyperliquid
Market
Limit
Stop
Stop-Limit-
Take Profit
Trailing Stop-
OCO-
Bracket✓*✓*✓*✓*

*Bracket orders implemented via multiple orders with linking


Next Steps