Inspired by another
blogpost
I decided to experiment with trading arbitrage between different
exchanges.
Not so long ago there was a hardfork in the blockchain-based
cryptocurrency Ethereum. This means that we now have two Ethereums:
Ethereum (ETH) and Ethereum Classic (ETC). The exchanges decided to
also support the original cryptocurrency, i.e., ETC, and so we can now
trade ETH against ETC and the other way around. The initial idea was
that ETHETC is such a new pair, that nobody is doing arbitrage yet.
First steps
There is an API for the Kraken
exchange written in python
2 and an API for Shapeshift
which helped me immensely. Since I like Python and Shapeshift and
already have an account at Kraken this was the way to go.
The idea is to check the price of ETHETC at Kraken, and ETCETH at
Shapeshift and check if it is profitable to buy at one exchange and
sell back at the other exchange. In Pseudocode:
Naturally we can also trade the other way around. For this we need
price_etceth_shapeshift instead of price_ethetc_shapeshift and for
kraken also the other way around. So the final pseudocode is as
follows.
The Kraken API
I wrote a file kraken.py which is a wrapper around the Kraken-API
exposing the relevant functions:
Note how defensively the code is written. Somecould the API connection
just timed out or the JSON object could not be decoded. In this case
we wait a second and then simply try again.
The Shapeshift API
Next I did the same for Shapeshift.
Here the errors from the API were much more varied. I got HTTP Error
503: Service Unavailable, HTTP Error 522: Origin Connection
Time-out, HTTP Error 525: Origin SSL Handshake Error, and also HTTP
Error 520: Origin Error. I did not even know those existed at all.
But on the second or third query they worked.
Wrapping it all together
Now here the pseudocode from above again, but this time in Python 2.
And without the actual trading. We are just logging if arbitrage
opportunities exist.
Not exactly the most beautiful code, but it worked.
The fees for Shapeshift and Kraken are straight from their websites.
Of course I could also have looked them up dynamically and if I would
plan to support more pairs, I would do that, but as a quick experiment
hardcoding sufficed.
The Result
Yes, there were some arbitrage opportunities. Sometimes they lasted
about half a minute which was a real surprise for me. On the other
hand the profit margins were really small. You would get around 0.6%
at most. Everything else I saw was around 0.1%. This was the reason I
did not continue the experiment, since these profit margins are too
small for me. There is also a timing risk involved, since you need to
make the deposit on both exchanges, but the price may have changed in
the meantime. You also need enough money, such that the profit will
not simply vanish as a rounding error. But the more money you use the
higher is your slippage which will also make the strategy
unprofitable.