When trying to execute an order during high market volatility, I am getting a response of “Margin is insufficient”. During normal market conditions, this doesn’t seem to happen.
An example scenario I am running into.
Where a max position is 5,000USDT at 100USDT x 50 leverage. An order executed for 99USDT x 50 is failing with the error indicated, even when the wallet has 120USDT.
Code Below:
var reqSymbolPrice = client.FuturesUsdt.Market.GetPrice(_appSettings.BinanceSymbol).Data; decimal symbolPrice = reqSymbolPrice.Price; int symbolQuantity = _calculateQuantity(symbolPrice); _loggerService.LogMessage("Attempting order...", eLogType.Confirm); var reqPlaceOrder = client.FuturesUsdt.Order.PlaceOrder( symbol: _appSettings.BinanceSymbol, side: OrderSide.Buy, type: OrderType.Market, quantity: symbolQuantity );
private int _calculateQuantity(decimal symbolPrice) { return (int)(_appSettings.BinanceAmountSpend / symbolPrice) * _appSettings.BinanceLeverageMultiplier; }
Where BinanceLeverageMultiplier = leverage (x50 in our example) and BinanceAmountSpend = amount of money to buy with (99USDT in our example)
The app will retry, and it seems it can take upwards of 20 retries for the order to go through. The same issue occurs when trying a trade at 1200USDTx20 leverage (where the max is a 25,000USDT position, or 1250USDTx20) where the wallet has 1300USDT.
In this situation, an isolated margin is being used.
Any thoughts on how to mitigate this?