Crypto Arbitrage Trading on Binance

Source Node: 912346

Exploring the so-called ‘3-way arbitrage’ trading strategy on Binance crypto currencies. Is this hype or is it profitable?

What a concept! Make 3 trades in rapid succession when you find favorable exchange rates and voila! Profits in seconds and no exposure to volatility.

Let’s break this down using a ridiculously simple bartering scenario. When we exchange one crypto-currency for another we are bartering or exchanging fungible assets.

Let’s image the following scenario:

  • Jane has 10 almonds
  • Will has pineapples and will trade each for 5 almonds
  • Christine has mangoes and will trade evenly for a pineapple
  • Xavier has almonds and will trade 6 for each mango

So in this arbitrage opportunity, Jane trades 10 almonds for 2 pineapples, and these for 2 mangoes which then she trades for 12 almonds.

She has profited 2 almonds through these trades because of anomalies in the exchanges.

Above is the same type of 3-way arbitrage with crypto currencies.

What at first appears to be simple often is often not.

A few important things to note here in the real-world of crypto markets:

  • price discrepancies between markets are anomalies, they have to be sniffed out deliberately
  • once an arbitrage opportunity is found it must be executed very quickly or you’ll be left with an incomplete execution (1 or 2 trades rather than 3)
  • the trades must be done as a Limit-Order at the specific price identified in the arbitrage exploration (we’ll try this out in a bit)
  • transaction fees will quickly erode the profitability of these trades (we’ll examine this directly in our code)

There’s another key thing to understand about arbitrage trades but we’ll get into that once we’ve covered more details…

Our first step is to identify arbitrage opportunities in real-time. Time is of the essence here, once we’ve identified an exchange discrepancy between markets it must be executed quickly. How quickly? We’ll get to that later…

Our arbitrage data gathering notebook is here:

t/y https://gist.github.com/Valian for starter code

Let’s look at this more closely…

The transaction FEE here is very important. The Binance VIP 0 spot-trade transaction fee is 0.075%, hence the 0.00075 FEE setting. Each trade carries this fee. VIP 1 spot-trades are 0.0675%

Look closely at the trading fees screen in Binance. There are separate fees for “Makers” and “Takers”, the latter are non-market trades (eg. Limit-Orders) and our arbitrage orders must by Limit-Orders otherwise we will lose out on market volatility.

Our margins here are going to be very thin.

For ITERATIONS we will let it run for awhile, whatever you like here. It can take hundreds of iterations to find an arbitrage opportunity so let it breathe.

The PRIMARY coin handles are not comprehensive but sufficient for now.

In our main() section we’ll iterate and write results to a .csv file.

We define our starting_coin as ‘USDT’, this means we start and end with a stable coin not exposed to volatility. You can change this to BTC if you prefer.

You will need to create a config.py file with your Binance API info with the following contents:

API_KEY = 'yourbinanceapikey'
API_SECRET = 'yourbinancesecretkey'

Here is the Jupyter Notebook with some output…

2021-06-08 17:00:29.599878 USDT->BTC->AR->USDT 0.441% profit
BTC / USDT: 0.00002973
AR / BTC : 1937.23363038
USDT / AR : 17.20000000

________
2021-06-08 17:01:43.204487 USDT->SUSD->BTC->USDT 0.0077% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33504.13000000

________
2021-06-08 17:01:44.334160 USDT->SUSD->BTC->USDT 0.0458% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33500.00000000

________
2021-06-08 17:01:44.966052 USDT->SUSD->BTC->USDT 0.0144% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33509.70000000

________
2021-06-08 17:01:46.036212 USDT->BTC->BADGER->USDT 0.1719% profit
BTC / USDT: 0.00002984
BADGER / BTC : 2573.34019557
USDT / BADGER: 12.87500000

2021-06-08 17:01:46.036612 USDT->SUSD->BTC->USDT 0.0242% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33500.49000000

2021-06-08 17:01:46.707569 USDT->SUSD->BTC->USDT 0.0329% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33500.50000000

________
2021-06-08 17:01:47.427442 USDT->SUSD->BTC->USDT 0.0025% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33502.60000000

________
2021-06-08 17:01:48.161421 USDT->SUSD->BTC->USDT 0.0282% profit
SUSD / USDT: 0.99950025
BTC / SUSD: 0.00002970
USDT / BTC : 33502.62000000

These first 6 ticks (separated by ___ ) are quite interesting, let’s look closely:

2021-06-08 17:00:29.599878 USDT->BTC->AR->USDT 0.441%

The triangle identified here is USDT trade for BTC trade for AR (Arweave) trade for USDT, generating a 0.441%, so 100 USDT would have profited 44 cents in this arbitrage, itself taking perhaps no more than 2 secs. But the time involved is part of the challenge here, were these limit trades available for that long or not? This is the key question.

The data above proves a clue, because the next line did not show the same arbitrage available in 17:00:30 therefore it was gone. Had we initiated a trade for BTC it might have executed but then a trade for AR may not have. We cannot be sure with only this information.

It is possible that one second later the USDT / BTC exchange was no longer available at the limit price: BTC / USDT: 0.00002973 but now that we have the BTC perhaps the remaining 2 trades are still possible. We simply cannot know this when we initiate the arbitrage exchange.

AR / BTC : 1937.23363038 ?
USDT / AR : 17.20000000 ?

Each Binance REST API call takes no less than 200ms, depending on where we are located (where your code is running). Binance servers are located in Japan. A limit order (a ‘Taker’) is not instantaneous, it may take another 500ms+ to return so our total time for 3 limit orders could realistically extend out to ~2secs. Of course there could be some inability to execute a limit order as specified in that instant so there are numerous ways an arbitrage execution may fail to complete.

There are numerous ways an arbitrage execution may fail to complete within the window the arbitrage opportunity exists.

But look at the next arbitrage opportunity:

2021-06-08 17:01:43.204487 USDT->SUSD->BTC->USDT 0.0077%

It remains open for several seconds, enough time to execute all 3 trades, however the profit varies between 0.0077% and 0.0282%. If we used 100 USDT this would result in a profit of less than 1 cent after commissions.

Source: https://medium.com/@gk_/crypto-arbitrage-trading-on-binance-12dcb4d17b30?source=rss——-8—————–cryptocurrency

Time Stamp:

More from Medium