binance-triangle-arbitrage: Account has insufficient balance for requested action

Description: This issue stems from the high latency it takes to execute three trades. The app can calculate profits in maybe 20ms, but then it takes almost 1000ms to execute the first trade and more time to execute the next two trades. By the time the first trade completes, too much time has passed and the market has shifted.

You can have market information that is 10ms old, and complete calculations in 20ms, but if it then takes 2500ms to execute the three trades, you are in a pickle 😦

More Technical Description: The bot calculates that with the current depth cache you should convert currency A into X amount of currency B and then X amount of currency B into Y amount of currency C, but by the time the first or second trade completes, that market depth cache information which the initial calculation was based on is stale so you can end up with less B or C than expected.

This error will occur when trying to perform the second or third leg of the triangle arbitrage.

Solutions:

  • Use the TRADING.EXECUTION_STRATEGY of "parallel"
  • Help me figure out a better alternative!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I’m testing it locally, but the next release will likely include these changes!

Looks like Binance has changed their api for market orders since the last time I looked. They now provide two golden parameters called executedQty and cummulativeQuoteQty which will provide us the the exact quantity of both symbols involved in the transaction.

After each leg in linear execution, we can look at the amount of the previous symbol received or spent, recalculate based on current market conditions if necessary, and then convert 100% of that into the next symbol. No need for insufficient balance errors!

It also allows us to convert as much of A as possible into B -> C -> A with minimal dust being generated in intermediate symbols.