I'm trying to open a long position to OPUSDT coin, but I always get the "CannotAffordOrderCost" error.
Numbers are here;
- Mark price of OPUSDT Coin: 1.708$
- Wallet Balance in USDT: 108.96975186$
- Leverage: 10x
- Position size in USDT with leverage: 871.8$
- Position amount in OP: 510.4
So the position I'm trying to open a position with 87$. Why API returning this error? I know I have enough money for this position.
const order: APIResponseWithTime<LinearOrder | null> = await client.placeActiveOrder({
symbol: `${position.symbol}`,
reduce_only: false,
close_on_trigger: false,
order_type: "Market",
qty: positionAmount,
side: "Buy",
time_in_force: "GoodTillCancel",
});
Thanks for the answer @DamiToma
The problem is position amount calculation should be based on available balance, not total wallet balance.