Trade Code: How to Determine Ethereum Arbitrage Opportunities Using Command Line On Cloud

Blockchain Altcoins Ethereum
Trade Code: How to Determine Ethereum Arbitrage Opportunities Using Command Line On Cloud

This tutorial is about determining arbitrage opportunity available between Kraken and Bitstamp, as their prices on 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 a crypto 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).

Distributions: Ubuntu,
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:

Droplet Digital Ocean

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.

Online 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.

Pseudo Code

If sell_price (bitfinex) – buy_price(kraken) >= 0

Tell Arb

if sell_price (kraken) – buy_price(bitfinex) >= 0

Tell Arb

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:

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.

Kraken Decoding

Python Time

Once you have logged in on the machine as root user run this command to install python:

apt install python

Coding Time

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 <anyname>.py file, for example, the author has saved it as ‘’.

Intermediate Code - Trade Code

Raw Code


Command : python <name>.py

Reading API Data

Determining Arbitrage:

Reading parameters we want to read:

Kraken Ask Price = dataK[‘result’][‘XETHZUSD’][‘a’][0]

Kraken Bid  Price = dataK[‘result’][‘XETHZUSD’][‘b’][0]

Bitfinex Ask Price = dataB[‘ask’]

Bitfinex Bid Price = dataB[‘bid’]

Here’s how the response looks after running the script few times.

Final Response

Final code:

Final Code - Trade Code

Raw Code


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!

Priyeshu Garg

Priyeshu is a software engineer who is passionate about machine learning and blockchain technology. He holds an engineering degree in Computer Science Engineering and is a passionate economist. He built his first digital marketing startup when he was a teenager, and worked with multiple Fortune 500 companies along with smaller firms. When he is not solving the transportation problems at his company, he can be found writing about the blockchain or hacking at a Hackathon.

Follow him on Twitter at :

Follow Us on Google News