TimeInForce defines the maximum duration a limit order is allowed to remain open before it is automatically canceled.
This ensures that orders donโt linger in the market indefinitely, preventing stale trades and unintended fills during fast-moving market conditions.
๐น How It Works
- TimeInForce is measured in seconds.
- Once a limit order is placed, the bot monitors the elapsed time:
If elapsed time โฅ TimeInForce โ Order is canceled automatically
- This prevents old or unexecuted orders from being filled at unfavorable prices.
๐น Example
TimeInForce: 60
- Limit order will remain open for 60 seconds.
- If the order is not filled within this window, it is automatically canceled.
- This is especially useful in volatile markets, where prices can move rapidly.
Example Scenario
- Market is moving fast, signal triggers a limit buy at $100
- TimeInForce = 30 seconds
- Price moves to $101 after 20 seconds โ order partially fills or remains unfilled
- After 30 seconds โ order is canceled automatically
- Prevents unexpected fills at a later time when price may no longer align with your strategy
๐น Why Itโs Important
Prevents Stale Orders
- Old orders can execute at the wrong price if the market has moved significantly.
Reduces Risk in Fast Markets
- Limit orders with long lifetimes may accidentally trigger during spikes or dips.
Maintains Strategy Accuracy
- Ensures trades are executed only when market conditions match the signal.
๐น Recommended Values
| Trading Style | TimeInForce (seconds) |
|---|---|
| Scalping / HFT | 10โ30 |
| Intraday / Day Trading | 30โ120 |
| Swing / Longer-Term | 120+ |
- Shorter TimeInForce โ reduces risk, more cancellations
- Longer TimeInForce โ higher chance of fill, but may result in stale entries
๐น Practical Tip
Combine TimeInForce with AskPriceBufferPer for optimal results:
- Small buffer improves fill probability
- Limited TimeInForce prevents executing orders at outdated prices
โ Key Takeaway
TimeInForce ensures limit orders remain relevant and aligned with market conditions.
- Controls the maximum lifespan of a limit order
- Prevents stale or unintended fills
- Critical for fast-moving or volatile markets
- Adjust based on trading style: shorter for scalp/HFT, longer for calm or swing trades