Skip to main content

Overview

The LFG SDK supports various order types for trading perpetual contracts. This guide covers everything from placing basic market orders to managing complex trading strategies.

Short-Term Orders

Fast orders that expire in blocks (~seconds to minutes)

Long-Term Orders

Traditional limit orders with time-based expiration (hours to days)

Order Types

Short-Term Orders

Short-term orders are ideal for:
  • Market-making strategies
  • High-frequency trading
  • Quick in-and-out trades
  • Time-sensitive opportunities
Characteristics:
  • Expire based on block height
  • Lower gas costs
  • Faster execution
  • Typical lifespan: seconds to minutes

Long-Term Orders

Long-term orders are ideal for:
  • Position building
  • Swing trading
  • Limit orders that can wait
  • Strategy orders
Characteristics:
  • Expire based on timestamp
  • Standard gas costs
  • Can stay on orderbook for days
  • Typical lifespan: hours to 28 days

Placing Short-Term Orders

Basic Short-Term Order

SubaccountInfo
required
The subaccount placing the order
string
required
Market identifier (e.g., "ETH-USD", "BTC-USD")
OrderSide
required
OrderSide.BUY or OrderSide.SELL
number
required
Limit price in quote currency (USD). Set to market price for market orders.
number
required
Order size in base currency (e.g., ETH, BTC)
number
required
Unique identifier for this order (0 to 2^32-1)
number
required
Block height when order expires. Must be greater than current block.
Order_TimeInForce
required
Order time in force policy. Use TIME_IN_FORCE_UNSPECIFIED for most cases.
boolean
required
If true, order can only reduce position size (not increase it)

Sell Order Example

Market Order (Short-Term)

For true market orders, query the current market price and place a short-term order at that price with a short expiration.

Placing Long-Term Orders

Basic Long-Term Order

OrderType
required
OrderType.LIMIT, OrderType.MARKET, OrderType.STOP_LIMIT, or OrderType.STOP_MARKET
OrderTimeInForce
required
  • OrderTimeInForce.GTT - Good-til-time (most common) - OrderTimeInForce.IOC - Immediate or cancel - OrderTimeInForce.FOK - Fill or kill
number
required
Seconds from now until order expires (max 28 days)
OrderExecution
required
OrderExecution.DEFAULT, OrderExecution.POST_ONLY, or OrderExecution.IOC
boolean
required
If true, order will only execute as maker (adds liquidity)
boolean
required
If true, order can only reduce existing position

Post-Only Orders

Post-only orders ensure you’re always a maker:
Post-only orders are rejected if they would immediately match and execute as a taker. This guarantees maker rebates.

Reduce-Only Orders

Reduce-only orders can only close existing positions:
Reduce-only orders will be rejected if you don’t have an open position in that market.

Canceling Orders

Cancel Short-Term Order

Cancel Long-Term Order

To cancel an order, you need the original clientId and order flags. Store these when placing orders.

Querying Orders

Get All Orders for Subaccount

Filter Orders by Market

Filter Orders by Status

Get Order by ID

Advanced Trading Strategies

Grid Trading Bot

Stop-Loss Order

Best Practices

Always use unique client IDs for each order:
Or use a counter with your bot instance:
Short-term orders expire quickly. Always check if enough blocks remain:
Keep track of your orders for cancellation and monitoring:
Network issues can cause order placement to fail:

Next Steps

Manage Balances

Query positions and account balances

Transfers

Deposit and withdraw funds

Market Data

Query orderbooks and market statistics

Order Types Reference

Complete order types documentation