Trade Code: How to Determine Ethereum Arbitrage Opportunities Using Command Line On Cloud
Originally published on: BTCMANAGER
Read the original article
May 18, 2018
This tutorial is about determining arbitrage opportunity available between Kraken and Bitstamp, as their prices BTCManager are shown on the ethereum price section. That being said, you can do this with any exchanges.
Set Up Digital Ocean Account
Arbitrage (“arb”) occurs when there’s a positive price difference between buying price at exchange A and selling price at exchange B. In this case, there’s a potential profit to be made. However, there are many factors which you should think before doing an arbitrage of which include price difference and transaction fees.
The reason for setting up a cloud infra account for this tutorial is because we’ll be doing a follow-up tutorial on getting push notifications based on arb-opportunities and there we will be monitoring arb opportunities 24/7. Thus having a cloud app will come in handy there since it’s a pain to keep your system running all the time.
We will use the cheapest droplet (a node) which will cost roughly $5 per month. First, you should sign up on Digital Ocean. Once you have signed up, you’ll have to pay a small fee for verification (The author picked PayPal, and the minimum was $5).
(Tip: Post verification, use code: DROPLET10 for additional $10 credit).
Now that payment and DigitalOcean account is setup, we will set up a droplet. Use these settings for setting up a droplet (after you click on Create Droplet).
Size: Memory (1 GB 5$/month),
Datacenter Region: Closest to you.
Leave all other fields default and click on Create. Now, wait for few minutes while it sets up a droplet for you. Once it’s done, it will look like:
Now DigitalOcean will email you your login credentials for entering this machine using SSH.
The author is using a Macbook and SSHing your way to a server is super easy with Macs. The author is not familiar with Windows; however, if you are not able to figure out how to SSH using windows, the author suggests you use a virtual terminal provided on the droplet page itself.
To launch a virtual terminal go to access and click on Launch Console.
Coming back to Macbook, all you have to do is open terminal and type:
ssh [email protected] (replace IP-ADDRESS by IP you would have received an email along with username & password) and then enter a password.
It would then immediately prompt you to enter a password again for resetting) and then enter your new password twice and be done with resetting the password.
If sell_price (bitfinex) – buy_price(kraken) >= 0
if sell_price (kraken) – buy_price(bitfinex) >= 0
To write logic on top of prices, we first need to fetch prices from Bitfinex and Kraken. We will use their API to get prices in real time.
This is the endpoint of Bitfinex for getting price on ETH-USD pair: https://api.bitfinex.com/v1/pubticker/ethusd
Bitfinex Response looks like:
This is the endpoint for Kraken for getting price on ETH-USD pair:
Kraken Response looks like:
Now we have to decode this Kraken response because the keys of this JSON response are meaningless, after some digging – you can find it on Kraken’s website.
Once you have logged in on the machine as root user run this command to install python:
apt install python
When the author was learning to code a few years back, most tutorials would just have the author directly providing final code without much explanation. Very uneducational! That being said, in this tutorial – we’ll be breaking code into multiple snippets for you to understand it carefully.
To add code to the system – use vim editor and save it as
Command : python
Reading parameters we want to read:
Kraken Ask Price = dataK[‘result’][‘XETHZUSD’][‘a’]
Kraken Bid Price = dataK[‘result’][‘XETHZUSD’][‘b’]
Bitfinex Ask Price = dataB[‘ask’]
Bitfinex Bid Price = dataB[‘bid’]
Here’s how the response looks after running the script few times.
Our notifier is ready! Feel free to use it, tweak it, add more logic on top of it!
If you are using the code on any website, please give due credit. Stay tuned for the next tutorial, which will be about enabling push notifications periodically when arbitrage opportunities show up!
If you need any help in this process, comment here and the author will try his best to help you out!