Arbitrage In Cryptocurrency

in cryptocurrency •  7 years ago 

Author: Jacob Carter, CTO Swapchain

**disclaimer: I assume you have a basic understanding and some experience with cryptocurrency and cryptocurrency exchanges like Poloniex, Kraken, etc.

Introduction:

Right now in the cryptocurrency world the methods to profit are few and far inbetween. At the end of the day you can long a single currency or token. That is to say, you can buy low and sell high. There is some flexibility in there with certain exchanges offering things like Margin Trading, but you're still stuck with the conventional buy low sell high method of profiting.

With the introduction of Swapchain that barrier is smashed with the advent of the Hyperswap. BUT Swapchain hasn't always been around, and before Swapchain I was looking for more clever ways to profit from the volatility of the cryptocurrency markets and exchanges. Eventually Google led me to arbitrage.

What is Arbitrage:

Arbitrage is the simultaneous purchase and sale of an asset to profit from a difference in the price. So what the hell does that mean? Let's look at an example. In this example, I will use large rounded numbers instead of accurate exchange rates. This will make things easier to understand. There are more complicated forms of arbitrage such as "triangular arbitrage" but for our example we'll be discussing plain Jane two way arbitrage.

  • You have a BTC and DASH wallet on Poloniex. You also have a BTC and DASH wallet on Kraken.
  • On Poloniex you see an rder, this order is a "bid" for buy 0.5 DASH at 0.25 BTC
  • On Kraken you see an order, this order is an "ask" to sell 0.5 BTC at 1.25 DASH
  • You see an opportunity for arbitrage here an execute both trades on both exchanges simultaneously

Do you see how you just made money? Lets walk through it.

You start with two wallets on two exchanges. Let's say you have 2 of each coin in each wallet on each exchange:

Poloniex Wallet
Kraken Wallet 2 BTC
2 BTC ($100/each)
2 BTC ($100/each)
2 DASH ($50/each)
2 DASH ($50/each)

You have a total of 4 BTC ($400) and 4 DASH ($200) across all your wallets

Your total cash value is $600

You see two orders, one on each exchange:

Poloniex Order
Kraken Order
Buy 0.5 DASH for 0.25 BTC
Sell 0.5 BTC for 1.25 DASH

You execute both orders simultaneously:

Settle on Poloniex
Settle on Kraken
2 BTC + 0.25 BTC = 2.25 BTC2
2 BTC + 0.5 BTC = 2.5 BTC
2 DASH - 0.5 DASH = 2.5 DASH
2 DASH - 1.25 DASH = .75 DASH

You have a total of 4.75 BTC and 3.25 DASH across all your wallets

Your total cash value is $637.50 ($37.50 more that we started with)

As an individual executing arbitrage you are taking advantage of small differences in currency prices across exchanges to buy and sell at the same time and come out with a profit.

Opportunity Discovery:

Here are the basic logical steps when deciding if you have found an opportunity for arbitrage.

  • Combine order books across exchanges. In order to find opportunities for arbitrage you must be looking at all open orders for all exchanges in one place.
  • Separate asks and bids and then sort low to high. Take all your asks and all your bids and house them in separate data sets. Once you have made this split sort your asks from low to high and sort your bids from high to low. The reason why is explained in step 3.
  • Is there a price difference? In the example above the only reason that we were able to make any money is because the lowest ask on one exchange was less than the highest bid on another. Take your sorted data sets for asks and bids and compare the lowest ask with the high bid.
  • There are two important pieces of information in an order. The price and the volume. For example if an order has a price of $1 and a volume of 10 it would take $10 to execute that entire order. This highlights two limiting factors
    • Based on the money in each wallet on the separate exchanges how much volume can you support for a single trade (things like maximum percentage of wallet willing to be spent on one trade may play a role here)
    • Unless the two orders have the exact same amount of volume, one of them will be less than the other. Because you are looking for equal but opposite trades, you will want to match the volume of one trade with the volume of another.
    • In conclusion: The volume for your arbitrage trade is the smaller of these two numbers: 1) the highest volume your wallet will allow 2) the lowest volume of the two orders.
  • Now that we have our prices and our desired volume we can calculate the trade value for each order with price * volume. Some exchanges will have a minimum trade value allowed. If this is the case you must next ensure that: trade value > minimum trade allowed for both exchanges involved in the arbitrage scenario.
  • Now we can calculate the cost of each trade again with price * volume. Once we have the cost of each trade and have ensured we know our maximum possible volume and ensured we meet minimum trade requirements for both exchanges we can evaluate how the exchange's fees will affect our trade. Let's say the exchange where we are on the bid side has a fee of 0.25% and the exchange where we are on the ask side has a fee of 0.15%.
    • Total Ask Fee = Total Ask Cost * 0.0015
    • Total Bid Fee = Total Bid Cost * 0.0025
  • Okay now finally we can calculate how much money this trade would make us. To do this we simply check:
    • Total Profit = (Total Ask Cost - Total Ask Fee) - (Total Bid Cost - Total Bid Fee)
  • You may often find for small trades that the associated fees wipe out any opportunity for profit.

When Everything Doesn't Go According To Plan:

So as we all know, things in life don't always go according to plan. What then? This is really up to you. The worst and most common mistake to happen when executing an arbitrage trade is to have an order on one exchange go through and the the order on the other to fail. This failure can be because of order types (e.g. fill or kill), code problems, network errors, you were too slow and the order is gone, etc.

So now the question is what do I do? You can try and reverse the trade that did go through and break even, you can reverse the trade that did go through for a small loss, or you can just let it be and keep moving forward. At the end of the day you have to decide what you think will be best for you.

Things to Consider:

  • Rebalancing wallets. Because you are executing (hopefully) many trades over a short period of time, the wallets on our exchange will start to get uneven as you execute a long series of bids or asks filling one wallet while draining the other. It is a good idea, from time to time, to stop and check your wallets, rebalance when necessary so you don't miss out on any good opportunities for lacking funds.
  • Fail safes. Your arbitrage software has a lot of power. It can execute trades with real money on your behalf across many exchanges. What if something goes wrong? What is a bug in your code causes a series of stupid trades that leave you at a loss to occur? What if a market anomaly causes your software to start dumping money into trades that are bad in nature. What if AI causes your machine to become self aware and try to take over the world. We have to be prepared. My favorite method is to use a velocity monitor. The idea here is that you track the rate at which you lose money. Money loss will occur (in the one sided trade for example). By monitoring this loss you can set suicide switches to flip when your loss exceeds a certain rate over a certain period of time. It is a good idea to have something of this sort in place.
  • Be Fast. Arbitrage by nature encourages fair and equal market prices. When traders take advantage of these small gaps in price they close very fast, ensuring all exchanges are offering very very similar rates. What this means is that when a gap is found is must be executed on immediately before it is closed or before another trader takes advantage of it. Things to consider are internet connection, chosen programming languages, CPU core and threading utilization, etc. "If you ain't first, you're last"

Hopefully these explanations, tips, and tricks will help you avoid or overcome some of the pitfalls I encountered when building my arbitrage software. Good luck and happy trading.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

EtherDelta is a Goldmine, insane arbitrage opportunity https://steemit.com/gifto/@fifelue/tips-be-a-millionaire-using-arbitrage

Congratulations @swapchain! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @swapchain! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!