Skip to main content

Position Sizing Parameters

Control how much capital to use for positions and how to manage position sizes.

cost​

  • Type: integer
  • Required: No
  • Description: Not used for sizing your own bots

Details​

Entries of your own bots are sized from the bot's allocated amount, which you set in the app (an auto bot starts with 100 in the quote currency). A multi-symbol bot sizes each entry on one slot of its budget. The cost field of a webhook signal does not change either amount.


tradable_ratio​

  • Type: float
  • Required: No
  • Default: 1.0

Description​

Fraction of the allocation to use for an entry. Use a value between 0 and 1. On multi-symbol bots, values above 1 are clamped to 1. A value of 0 is treated as "not set", which means the full allocation is used.

Examples​

// Use 100% of allocation
{"tradable_ratio": 1.0}

// Use 50% of allocation
{"tradable_ratio": 0.5}

// Values above 1 are outside the supported range and are flagged

With Leverage​

allocation = 1000 USDT
tradable_ratio = 1.0
leverage = 10

position_size = allocation * tradable_ratio * leverage
// = 1000 * 1.0 * 10 = 10,000 USDT position

If the allocation is larger than the account's free balance, the entry uses the free balance and you get a warning.

If your exchange connection has an account leverage configured, OptAlgo multiplies leverage by it and divides tradable_ratio by it. The position size stays the same, and less margin is used. Futures entries need leverage.


close_ratio​

  • Type: float
  • Required: No
  • Default: 1.0
  • Range: 0.0 - 1.0

Description​

Fraction of the trade's original filled size to close. The amount closed is capped at what is still open, so two closes with 0.5 close the whole position. A missing value or 0 means a full close.

Examples​

// Close 50% of the original size
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.5
}

// Close 25% of the original size
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 0.25
}

// Close 100% (same as CLOSE)
{
"position_side": "CLOSE_PARTIAL",
"close_ratio": 1.0
}

Automatic Conversion​

If position_side is CLOSE and close_ratio < 1.0, it's automatically converted to CLOSE_PARTIAL.


Complete Examples​

Full Position Size​

{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY",
"tradable_ratio": 1.0,
"leverage": 10
}
// Bot allocation 1000 USDT -> position 10,000 USDT

Half Position Size​

{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY",
"tradable_ratio": 0.5,
"leverage": 10
}
// Bot allocation 1000 USDT -> position 5,000 USDT

Partial Close​

{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "CLOSE",
"close_ratio": 0.5
}
// Closes 50% of the original position size

Best Practices​

1. One entry per trade​

A bot holds one open trade at a time (per trade_id). A second entry while a trade is open is refused, so you cannot scale in by sending several entries. Size the entry with tradable_ratio instead.

2. Scale out of positions​

// Take profit 1: close half of the original size
{"position_side": "CLOSE", "close_ratio": 0.5}

// Take profit 2: close the rest
{"position_side": "CLOSE"}

See Partial close.