Skip to content
Sign In

Learning / Features / Smart OCO

Smart OCO - Position-Aware Order Monitoring

Premium Feature

Advanced OCO monitoring that tracks position state instead of individual order events, enabling sophisticated exit strategies.

Understanding the Difference

Standard OCO

Event-Based

Perfect for:

  • • Simple binary outcomes (TP or SL)

  • • Single TP/SL pairs

  • • Order-event cleanup

  • • Maximum simplicity

Monitors:

Individual order fills/cancels

Trigger:

When a primary tracked order closes or is cancelled → Cancel the remaining group

Smart OCO

Position-Based

Perfect for:

  • • Multi-level exit ladders

  • • Partial take profit strategies

  • • Position flip scenarios

  • • Complex exit management

Monitors:

Position size and side

Trigger:

When position conditions met → Cleanup

Both modes are valid tools - choose based on your strategy complexity. Standard OCO excels at simplicity, Smart OCO enables advanced scenarios.

How Smart OCO Works

Smart OCO runs a background monitor polling your position state with two configurable conditions:

cancelOnZeroDefault: ON

Cleanup on Position Close

When position closes to zero → Automatically cancel remaining orders. Perfect for exit ladders that complete fully.

cancelOnFlipDefault: ON

Cleanup on Position Flip

When position changes side (LONG→SHORT) → Cancel old exit orders. Essential for multi-signal strategies.

Syntax

Basic (default: both conditions enabled)

Smart Syntax
smart-oco sell

Advanced Configuration

Smart Syntax
smart-oco sell cancelOnZero=true cancelOnFlip=false
smart-oco sell cancelOnZero=false cancelOnFlip=true
smart-oco all
smart-oco #exits

Real-World Use Cases

1. Three-Level Exit Ladder

Gradual position exit while maintaining stop loss protection throughout

Smart Syntax
ADAUSDT on Binance_F_Demo
// Entry with protection
market long 100
stoploss off 1.5%

// Three-level exit ladder
// TP1: +3%
takeprofit 30%p off rr2
// TP2: +4.5%
takeprofit 30%p off rr3
// TP3: +6%
takeprofit 40%p off rr4

smart-oco sell
Step 1

If size was unchanged at placement: TP1 fills → Exit 30 → Position = 70 → All orders remain active

Step 2

TP2 fills → Exit 30 → Position = 40 → SL + TP3 remain active

Step 3

TP3 fills → Exit 40 → Position = 0 → Smart OCO cancels SL


2. Multi-Signal Strategy with Flips

Trading system that can reverse positions based on new signals

Smart Syntax
BTCUSDT on My_API_Key
// Initial signal in one-way mode
market long 0.01
stoploss off 1%
takeprofit 50%p rr2
takeprofit 50%p rr3
smart-oco sell

Separate reversal alert, only after checking the position is still long 0.01 BTC in one-way mode. Two alerts are not atomic; inspect fills and old-order cleanup before adding new protections.

Smart Syntax
BTCUSDT on My_API_Key
market short 0.02

Comparison Matrix

FeatureStandard OCOSmart OCO
MonitoringOrder eventsPosition state
TriggerOrder fills/cancelsPosition conditions
Partial ExitsFirst exit cancels allMaintains monitoring
Exit LaddersNot supportedFully supported
Flip DetectionNot applicableAutomatic cleanup
LatencyNative linkage or pollingDepends on polling and exchange responses
ComplexitySimpleAdvanced
Best ForBinary outcomesComplex strategies

Choosing the Right Tool

Choose Standard OCO when:

  • Single TP and single SL
  • Binary outcome (TP or SL)
  • No partial exits planned
  • Maximum simplicity preferred
Smart Syntax
market long 100
stoploss off 1%
takeprofit off 3%
oco sell

Choose Smart OCO when:

  • Multiple TP levels (ladder)
  • Position may flip/reverse
  • Gradual exit strategy
  • Advanced position management
Smart Syntax
market long 100
stoploss off 1%
takeprofit 33%p off rr2
takeprofit 33%p off rr3
takeprofit 34%p off rr4
smart-oco sell

Best Practices

TIP #1

Use Position Percentage (%p) for Exit Ladders

Smart Syntax
// Percentages are calculated when orders are placed
takeprofit 33%p off rr2
takeprofit 33%p off rr3
takeprofit 34%p off rr4

// A fixed quantity is another choice; check units and remaining size
takeprofit 30 off rr2
TIP #2

Test in Demo/Testnet First

Smart Syntax
BTCUSDT on Binance_F_Demo
// Safe: Always test first

// Production: Only after testing
BTCUSDT on Binance_F
TIP #3

Understand the Defaults

When in doubt, use default (both conditions enabled). It provides comprehensive automation for most scenarios.

Performance Characteristics

Cancellation timing: Depends on polling and exchange responses from event to order cancellation

Acceptable For:

  • • Discretionary trading
  • • Swing trading (hours/days)
  • • Day trading (intraday)
  • • Scalping (depends on style)

Not Ideal For:

  • • Sub-second latency requirements
  • • High-frequency trading (HFT)
  • • Market making

Frequently Asked Questions

Q: Is Smart OCO slower than Standard OCO?

A: Standard and Smart OCO use different triggers. Software monitoring depends on polling and exchange responses; native OCO is handled by the exchange. Neither software mode promises an instantaneous cancellation.


Q: Can I use both Standard and Smart OCO simultaneously?

A: Yes, absolutely. They are completely independent. You can have Standard OCO on one symbol and Smart OCO on another.


Q: What happens if the server restarts?

A: Smart OCO groups are persisted in the database. On restart, the monitor automatically reloads all active groups and continues monitoring. The restart leaves a monitoring gap; exchange orders already accepted remain subject to exchange rules.


Q: Does Smart OCO work on all exchanges?

A: Availability depends on the exchange, market, order types and plan. Check Exchange Quirks and the supported choices in API Keys; native position TP/SL may not appear as ordinary open orders.

Production ReadyExchange-specific limitsPremium Feature

Last updated: 2025-11-17