Crypto arbitrage calculator in Python (Koinex)

Anupam vashist
Karma and Eggs
Published in
5 min readMay 17, 2018

--

First things first, let’s go over the concept of arbitrage. In a nutshell, arbitrage is a strategy to take advantage of differences in prices across markets to make profit.

We will use INR-EUR pair for our example. Suppose my friend is coming from somewhere in Europe and he informs me about the latest iPhone for 600 EUR. Converting this price into INR with a conversion rate of ~80 INR/EUR, the iPhone costs him INR 48,000.

Let’s assume this phone isn’t launched in India yet and the expected price is ~INR 60,000. I wish to be one of the first in India to have this latest phone, maybe i like to flaunt flashy stuff. Let’s also assume that he spent INR 7000 for his service of bringing phone to India. That costs him INR 55000 for the phone.

Now Let’s assume he wants to make some money out of this deal, given that the expected price is INR 60K, he has an option to sell it to me anywhere between 55K and 60K INR and even above it, i’ll readily take it since i’m eager to have it at the earliest.

The arbitrage opportunity here was INR 12,000 and plus at first, but post travelling expenses, it comes out to be INR 5000 and plus.

Similar thing happens in cryptocurrency trading.

Due to difference in demand and supply of coins in different countries and exchanges, there opens an arbitrage window sometimes and those who are aware of this window can take out huge profits out of thin air.

But there is a problem! dealing with arbitrage across international currencies is frowned upon by the governments. True. Instead here, we will talk about another type of advantage we can take out of this awareness.

Fluctuating demands and supplies

Taking Indian exchanges for example, the cost of a coin in INR is usually higher than in USD. the range varies from 2% to even 20% in many cases, usually lying ~5–10% range. Historically speaking, there have been scenarios where the news of government ban on crypto in india created havoc and people started selling like a King turning into a saint. The above range slumped down to as low as -25%.

Was it a good arbitrage opportunity? Yes!

Also, It was a good buying point since we know that international markets were steady and soon the arbitrages will catch up to a usual 5–10% range.

In essence, the knowledge of arbitrage is a good data point to consider while investing in a crypto coin. Looking at the time series graphs and red/green markers alone are inefficient to come to any conclusions.

In the following part, i’ll share a program which focuses on a leading Indian exchange -Koinex, and check arbitrage opportunities compared to International market from cryptocompare. If you are a frequent cryto trader or even wanting to start trading, this program and another tool from a previous article will help you stay out of trouble.

Here we go!

Step 1: Install python3, open IDLE(or any editor) and Import necessary libraries

Step 2: Fetch Prices from Koinex ticker API and parse it through JSON to have it in python dictionary format- easier to deal with.

Output should look like below

Step 3: Convert data from this dictionary into an array with INR Prices converted into a currency we are comparing to (Here We’ll check INR-EURO pair which costs ~80.45 INR/EURO)

Let’s see how this looks like:

Step 4: Now we need prices of these coins in Euro market. We can fetch this from cryptocompare API (see documentation in the link) into a python List. We have used 0.0000000001 as dummy value for coins which aren’t available on cryptocompare, we can easily point these out.

Step 5: Now all we need is to calculate arbitrage comparing Koinex prices to Cryptocompare. Code snippet below will do this.

Et Voila! here is the Output dataframe:

Inferences:

The Output dataframe is showing arbitrage opportunities across 23 coins.

A quick look at percentage arbitrages tells us that all 23 coins are in greater demand in Koinex than average EUR market.

Historically speaking, most of the coins here are in the average inflation range with an exception of OMG, ONT and specially, ZCO. If i were to invest, i’d stay away from these 3 coins to play safe.

I’d probably experiment with the likes of BAT, IOST or TRX but before checking the possibility of pump and dump using the program here.

Also, i’d want to keep running the program and record data on various instances to keep track on the average arbitrage % across time. This keeps up the knowledge of “Historically speaking”

I hope this helps. Please do subscribe for more eggs!

Disclaimer: this is an educational piece to help readers better understand the various arbitrage opportunities available in the cryptocurrency market. This is not investment advice or a suggestion to do it — anything you do is at your own risk! Crypto arbitrage can be a very high-risk activity.

--

--