Skip to main content

Closing Positions

Position types for closing existing positions, either fully or partially.

CLOSE​

Close a specific position completely.

Example​

{
"strategy_key": "your_key",
"position_side": "CLOSE",
"trade_id": "abc123"
}

When to Use​

  • Close a specific trade by trade_id
  • Exit position at market price
  • Simple, immediate close

CLOSE_PARTIAL​

Close a portion of an open position based on close_ratio.

Required Parameters​

  • close_ratio: Fraction of the trade's original filled size to close (between 0 and 1). The amount is capped at what is still open.
  • exchange and ticker: the bot's exchange and symbol (on a multi-symbol bot, the coin to close)
  • trade_id: only if you opened the trade with one

Examples​

Close 50% of position:

{
"strategy_key": "your_key",
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.5,
"trade_id": "abc123"
}

Close 25% of position:

{
"strategy_key": "your_key",
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.25,
"trade_id": "abc123"
}

Scaling Out Strategy​

// Take profit 1: Close 33%
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.33,
"trade_id": "BTC_LONG"
}

// Take profit 2: Close another 33% of the original size
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.33,
"trade_id": "BTC_LONG"
}

// Take profit 3: Close remaining
{
"position_side": "CLOSE",
"trade_id": "BTC_LONG"
}

CLOSE_ALL​

Close all open positions for the strategy, regardless of trade_id.

Example​

{
"strategy_key": "your_key",
"position_side": "CLOSE_ALL"
}

When to Use​

  • Emergency close all positions
  • End of trading session
  • Risk management trigger
  • Strategy shutdown

Behavior​

  • Closes every open trade for the strategy
  • Processes all trades in parallel
  • Ignores trade_id if provided
  • Deletes cached leverage settings

Aliases​

These position types are converted to CLOSE:

FLAT​

{"position_side": "FLAT"}
// Converted to: {"position_side": "CLOSE"}

CANCEL​

{"position_side": "CANCEL"}
// Converted to: {"position_side": "CLOSE"}

CLOSE_LONG​

{"position_side": "CLOSE_LONG"}
// Converted to: {"position_side": "CLOSE"}

CLOSE_SHORT​

{"position_side": "CLOSE_SHORT"}
// Converted to: {"position_side": "CLOSE"}

Automatic CLOSE_PARTIAL Conversion​

If you send CLOSE with close_ratio < 1.0, it's automatically converted to CLOSE_PARTIAL:

// This signal:
{
"position_side": "CLOSE",
"close_ratio": 0.5,
"trade_id": "abc123"
}

// Becomes:
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.5,
"trade_id": "abc123"
}

Complete Examples​

Simple Close​

{
"strategy_key": "your_key",
"position_side": "CLOSE",
"trade_id": "BTC_LONG_001"
}

Partial Close with Reason​

{
"strategy_key": "your_key",
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.5,
"trade_id": "BTC_LONG_001",
"reason": "First take profit target reached"
}

Emergency Close All​

{
"strategy_key": "your_key",
"position_side": "CLOSE_ALL",
"reason": "High volatility - closing all positions"
}

Best Practices​

1. Always Use trade_id for Specific Closes​

// ✅ Good
{
"position_side": "CLOSE",
"trade_id": "BTC_001"
}

// ⚠️ Risky (may close wrong trade)
{
"position_side": "CLOSE"
}

2. Scale Out of Winners​

// Take partial profits along the way
{"close_ratio": 0.33} // At TP1
{"close_ratio": 0.5} // At TP2
{"close_ratio": 1.0} // At TP3

3. Use CLOSE_ALL for Emergencies Only​

// Emergency situations
{
"position_side": "CLOSE_ALL",
"reason": "Market crash - emergency close"
}

Next Steps​