A Python program to see if arbitrage trading is profitable

in #utopian-io8 years ago (edited)

Have you ever wondered if you can earn profit by buying a coin at one exchange and selling it at another. Well, I've made a simple python script to tell you just that. It queries ask and bid rates from 4 different exchanges, which are, Cryptopia, Bittrex, HitBTC and Poloniex, to show you the results. This kind of trading is known as arbitrage trading. You can find my script at https://github.com/HamidMushtaq/steemtools/blob/master/getarbitragerates.py, and it works with both Python 2 and 3.

Here is one sample output of the program. I asked it how much possible profit I can get by trading 10 litecoins. I asked that two times, and both times, it said that it is best to buy from Cryptopia and sell it at Bittrex. Here, of course I am ignoring the transaction fees. Withdrawal fees are not included either, but they can be avoided anyway, by keeping stock of both litecoins and bitcoins on both exhanges.

One interesting result is that of STEEM, which I queried the third time. Apparently, I can get a lot of profit by buying from Poloniex and selling it at HitBTC. However, don't be fooled by this, because if you check, you'll notice that the wallet of STEEM at HitBTC is still under maintenance. So, basically, this type of trade is not even possible.

In my Python program, I have got information from these exchanges, using their REST APIs. The information is then extracted from the resulting output in JSON form. Although, in my code, I have listed the sources from where I got help for these APIs, here I am listing them again.

  1. Cryptopia: https://www.cryptopia.co.nz/Forum/Thread/255
  2. Poloniex: https://poloniex.com/support/api/
  3. Bittrex: https://bittrex.com/home/api
  4. HitBTC: https://api.hitbtc.com/?python#rest-api-reference

I hope that you will find this program useful. If you have any questions relating to the code, I would be happy to answer them.

UPDATE
I have now also added Binance into the list of exchanges. So, now rates from 5 exchanges are shown.

Sort:  

Bittrex, Poloniex are my favorite exchanging sites. so what about HitBTC because i havn't used this site?

HitBTC is not bad too. But after adding Binance into the list of exchanges for this program, I can see that Binance has the lowest rates.

Humm, the only downside to his would be the feeds for moving coins around from one exchange to another and the time it takes, i would rather focus in trading in the same exchange, but nevertheless it is a good tool if you know how to use it, thanks for sharing it.

Basically moving of the coins can be avoided if you keep a stock of BTC and the other coin on both exchanges. But like you said, trading is definitely more profitable if you do it right. One interesting phenomena I have observed is that when the values of other cryptos are goin down, the value of digixdao goes up and vice versa. That is because digixdao is backed by gold. I'll make a post about that soon. But first, I have to observe things more in depth.

I can see a great and depth passion of yours in programming😋

Good and useful effort, nice program, email me if you can expand it to other exchanges and cryptos...
[email protected]
@bitpost

Thanks for sharing. Learned something and i will try it.

this information is very useful for me. in the future i will try.

I will try thank you

You got a 2.12% upvote from @mercurybot courtesy of @hmushtaq!