{"id":8507,"date":"2021-03-25T17:00:53","date_gmt":"2021-03-25T17:00:53","guid":{"rendered":"http:\/\/algotrading101.com\/learn\/?p=8507"},"modified":"2021-05-14T13:22:25","modified_gmt":"2021-05-14T13:22:25","slug":"crypto-arbitrage-guide","status":"publish","type":"post","link":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/","title":{"rendered":"Crypto Arbitrage Guide &#8211; What It Is and How to Find It"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_8507\" class=\"pvc_stats total_only  \" data-element-id=\"8507\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>\n<h3 class=\"wp-block-heading\">Table of contents:<\/h3>\n\n\n\n<ol><li><a href=\"#what-is-crypto-arbitrage\">What is crypto arbitrage?<\/a><\/li><li><a href=\"#why-does-crypto-arbitrage-occur\">Why does crypto arbitrage occur?<\/a><\/li><li><a href=\"#what-are-the-pros-and-cons-of-crypto-arbitrage\">What are the Pros and Cons of crypto arbitrage?<\/a><\/li><li><a href=\"#what-types-of-arbitrage-exist\">What types of arbitrage exist?<\/a><ul><li><a href=\"#spatial-arbitrage\">Spatial arbitrage<\/a><\/li><li><a href=\"#spatial-arbitrage-without-transferring\">Spatial arbitrage without transferring<\/a><\/li><li><a href=\"#triangular-arbitrage\">Triangular arbitrage<\/a><\/li><\/ul><\/li><li><a href=\"#how-to-take-advantage-of-arbitrage-algorithmically\">How to take advantage of arbitrage algorithmically?<\/a><\/li><li><a href=\"#how-to-find-a-crypto-arbitrage\">How to find a crypto arbitrage?<\/a><ul><li><a href=\"#method-1\">Method 1<\/a><\/li><li><a href=\"#method-2\">Method 2<\/a><\/li><\/ul><\/li><li><a href=\"#what-are-the-dangers-of-crypto-arbitrage\">What are the dangers of crypto arbitrage?<\/a><\/li><li><a href=\"#full-code\">Full code<\/a><\/li><\/ol>\n\n\n\n<a name=\"what-is-crypto-arbitrage\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is crypto arbitrage?<\/strong><\/h2>\n\n\n\n<p>The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.<\/p>\n\n\n\n<p>To put it simply, if we buy a crypto asset for a lower price on one exchange and sell it for a higher price on another exchange, we have used the crypto arbitrage method.<\/p>\n\n\n\n<p>This article focuses on finding cryptocurrency mispricing across several exchanges in order to do a crypto arbitrage. We\u2019ll cover how to calculate the opportunity for a crypto arbitrage and make a profit off of it.<\/p>\n\n\n\n<a name=\"why-does-crypto-arbitrage-occur\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why does crypto arbitrage occur?<\/strong><\/h2>\n\n\n\n<p>According to most financial textbooks, it is believed that markets are efficient and thus that an arbitrage opportunity simply can\u2019t occur. (Un)Fortunately, the reality is far from theory and traders have found a way to exploit it.<\/p>\n\n\n\n<p>There are many reasons behind the occurrence of a crypto arbitrage and I\u2019ve extracted the most notable ones:<\/p>\n\n\n\n<p><strong>Liquidity variance across several exchanges<\/strong><\/p>\n\n\n\n<p>Most of the exchanges have their own order books that tend to be different with varying liquidity for a particular asset. For those new to trading, an order book is an automated list of current sell and buy positions for a specified asset.<\/p>\n\n\n\n<p>For example, if we are buying Bitcoin, it might be easier to convert it into cash on a particular exchange without causing a loss. This can easily have something to do with the order book of an exchange.<\/p>\n\n\n\n<p>If one exchange has a wide order book and the other a more filled one, it would be wise for us to buy our asset on the latter, as the former would end up in us paying a higher price.<\/p>\n\n\n\n<p>But why does this happen if both order books show the same price for our asset?<\/p>\n\n\n\n<p>Well, one exchange (with the wide order book) can be made up of small orders of BTC at the very top of its book price.<\/p>\n\n\n\n<p>After we buy these orders, we\u2019re automatically moving into the lower levels of the order book to make the rest of our order, and thus paying a higher price.<\/p>\n\n\n\n<p><strong>Different types of exchanges<\/strong><\/p>\n\n\n\n<p>Not all exchanges are the same. Some of them are most suitable for retail investors while others are built with a preference for institutional ones.<\/p>\n\n\n\n<p>If we take a look at the varying behaviors and preferences of these two types of traders, a crypto arbitrage opportunity occurs.<\/p>\n\n\n\n<p>For example, the institutional traders tend to have gaps between their large limit market orders while the retail traders don\u2019t.<\/p>\n\n\n\n<p>This gap allows us to buy a particular asset on the retail trader exchange and then commit to a sell position on the other one. With the power of algorithmic trading, most arbitrages can offer an instantaneous profit.<\/p>\n\n\n\n<p><strong>Withdrawal and deposit times vary across exchanges<\/strong><\/p>\n\n\n\n<p>As exchanges don\u2019t have the same deposit and withdrawal times the opportunities for the crypto arbitrage grow. If we could move our fiat and crypto assets instantaneously, the market differences between several exchanges would flatten out.<\/p>\n\n\n\n<p>This means that the exchanges with a faster transfer time catch up with the market sooner while the other ones slowly crawl up to the updated market sentiment levels.<\/p>\n\n\n\n<p>Moreover, the <strong>cost of transferring our fiat\/crypto<\/strong> holdings also varies and thus creates even more arbitrage opportunities.<\/p>\n\n\n\n<p><strong>The supply and demand vary across countries<\/strong><\/p>\n\n\n\n<p>As countries can have different supply and demand levels, we can exploit the crypto arbitrage opportunities.<\/p>\n\n\n\n<p>If Japan has a lukewarm sentiment for Ethereum while the US is going bullish, we can buy the ETH in Japan and sell it to the US.<\/p>\n\n\n\n<p><strong>Foreign currency rates<\/strong><\/p>\n\n\n\n<p>For example, if we\u2019re trading Lithium, the varying currency exchange rates can create arbitrage opportunities.<\/p>\n\n\n\n<p>Imagine a scenario where the USD gains against the JPY, while the asset price for Lithium remains the same on Japanese and US exchanges.<\/p>\n\n\n\n<p>This creates an arbitrage opportunity where we convert USD to JPY, buy Lithium on a Japanese Exchange and then sell the Lithium on a US exchange.<\/p>\n\n\n\n<p>Some of the other notable reasons are the following:<\/p>\n\n\n\n<ul><li>Tight capital controls outside of the US and EU<\/li><li>Lack of traders (i.e. market makers)<\/li><li>Regulations across exchanges<\/li><li>Spreads<\/li><li>Costs<\/li><\/ul>\n\n\n\n<a name=\"what-are-the-pros-and-cons-of-crypto-arbitrage\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are the Pros and Cons of crypto arbitrage?<\/strong><\/h2>\n\n\n\n<p><strong>The Pros:<\/strong><\/p>\n\n\n\n<ul><li><strong>Low risk<\/strong> \u2013 As we\u2019re buying and selling the asset simultaneously, there is no risk involved as there is in the long-term investments.<\/li><\/ul>\n\n\n\n<ul><li><strong>Flourishes in volatile markets <\/strong>\u2013 Arbitrage trading is a good way to trade the volatile markets without taking too much risk.<\/li><\/ul>\n\n\n\n<ul><li><strong>Not reliant on bull or bear markets<\/strong> \u2013 You can money regardless of market direction. That said, there will be more arbitrage opportunities during massive bull markets. This is because traders are more focused on riding the bull run than arbitraging.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"600\" height=\"553\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/0_VF90R2vPRmnSSdfl_.jpg\" alt=\"\" class=\"wp-image-6627\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/0_VF90R2vPRmnSSdfl_.jpg 600w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/0_VF90R2vPRmnSSdfl_-300x277.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>Source: The Economist<\/figcaption><\/figure>\n\n\n\n<p><strong>The Cons:<\/strong><\/p>\n\n\n\n<ul><li><strong>Transaction fees<\/strong> \u2013 Exchanges mostly make a profit from the transaction fees they impose on traders. While someone as a swing trader doesn\u2019t bat an eye on the transaction fees, it can hurt the arbitrage trader and bring his profit to minimum amounts.<\/li><\/ul>\n\n\n\n<ul><li><strong>Exchanges and cryptocurrencies are unpredictable<\/strong> \u2013 Most of us can remember a moment when a crypto exchange freezes or crasher on us in times of high volume. Not to speak of some transaction times and cost issues. An exchange might shut down and take all your capital with them too.<\/li><\/ul>\n\n\n\n<ul><li><strong>Technology <\/strong>&#8211; If we want to excel at crypto arbitrage, we need to use the latest technology that allows us to make the trades quickly enough in order to make a profit.<\/li><\/ul>\n\n\n\n<ul><li><strong>Minimum mispricing <\/strong>\u2013 Considering the costs, transaction fees and the stability of the market, a crypto mispricing has to be high enough such that you are profitable after costs.<\/li><\/ul>\n\n\n\n<ul><li><strong>Regulations <\/strong>\u2013 Regulations like KYC (Know Your Client) and AML (Anti-Money Laundering), can impact the cross-border arbitrage.<\/li><\/ul>\n\n\n\n<ul><li><strong>Experience<\/strong> &#8211; New traders can jump too quickly on an asset without considering all the ways the arbitrage could go wrong. Thus, having experience in trading and on the fluctuations of the market is key.<\/li><\/ul>\n\n\n\n<a name=\"what-types-of-arbitrage-exist\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What types of arbitrage exist?<\/strong><\/h2>\n\n\n\n<p>There are many ways to commit to a crypto arbitrage and I\u2019ll cover the most used ones.<\/p>\n\n\n\n<a name=\"spatial-arbitrage\">\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Spatial arbitrage<\/strong><\/h3>\n\n\n\n<p>This arbitrage is the most common one. It allows us to buy a crypto asset on one exchange and then transfer it to the other exchange while selling it for a higher price.<\/p>\n\n\n\n<p>Issues like costs, transfer times and spreads, make this type of arbitrage not as valuable. Basically, by the time we transfer a crypto to another exchange, chances are that the price has already changed.<\/p>\n\n\n\n<p>The good side of this arbitrage tactic is that it\u2019s quite easy to do.<\/p>\n\n\n\n<p><strong>2 Methods<\/strong><\/p>\n\n\n\n<ol><li>Long\/short on exchange 1, transfer crypto\/fiat to exchange 2, then short\/long<\/li><li>Long and short on 2 exchanges, then transfer the long to the other exchange, and cover the shorts.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1-1024x576.png\" alt=\"\" class=\"wp-image-6624\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1-1024x576.png 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1-300x169.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1-768x432.png 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1-1536x864.png 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/1.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<a name=\"spatial-arbitrage-without-transferring\">\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Spatial arbitrage without transferring<\/strong><\/h3>\n\n\n\n<p>This method is used in order to eliminate the transfer time and cost. It is also preferred by most crypto day trading arbitrageurs.<\/p>\n\n\n\n<p><strong>Method 1<\/strong><\/p>\n\n\n\n<p>In this case, we long ETH and short ETH on another, we then wait for the price of ETH to converge to the same price. <\/p>\n\n\n\n<p>We then close both trades.<\/p>\n\n\n\n<p>The downside of this method is that convergence of the mispricing needs to happen.<\/p>\n\n\n\n<p><strong>Method 2<\/strong><\/p>\n\n\n\n<p>This tactic involves having a balance on two different exchanges, let\u2019s say <a href=\"https:\/\/algotrading101.com\/learn\/binance-python-api-guide\/\">Binance<\/a> and <a href=\"https:\/\/algotrading101.com\/learn\/bitmex-api-introduction-guide\/\">BitMex<\/a>.<\/p>\n\n\n\n<p>After looking into the spreads of the ETH-USD asset, we decide to buy the asset on Binance and sell it on BitMex. This would be done by moving our USD to Binance and the ETH to BitMex.<\/p>\n\n\n\n<p>Then we would wait for the price to difference to reach X% more on BitMex. When it happens we will commit to a buy ETH order with the USD from Binance, and simultaneously commit to a sell ETH order for USD on BitMex.<\/p>\n\n\n\n<p>Let us now add some numbers to this example so it can be clearer. Let\u2019s say we bought 1 ETH for $6,06 on Binance we would have spent $606.<\/p>\n\n\n\n<p>If we then sold our 1 ETH at the same time on BitMex at a rate of $6,20 we would have sold it for $620.<\/p>\n\n\n\n<p>This means that we simultaneously bought 1 ETH and sold 1 ETH. We didn\u2019t lose or gain one. The profit we made from this is $14, not including the trading fees.<\/p>\n\n\n\n<a name=\"triangular-arbitrage\">\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Triangular arbitrage<\/strong><\/h3>\n\n\n\n<p>This tactic utilizes a single or more exchanges while exploiting the differences between the trading pairs. As many exchanges have a great variety of markets with different currency options, we can utilize many opportunities for a triangular arbitrage.<\/p>\n\n\n\n<p>For example, we can trade BTC for ETH, ETH to LTC and LTC back to BTC. If the differences were substantial, we would have made a profit.<\/p>\n\n\n\n<p>To make this example clearer let us go over the method step by step.<\/p>\n\n\n\n<p>Firstly, we\u2019ll begin at one asset, here being BTC. This asset will be the starting and the finishing point of our arbitrage loop.<\/p>\n\n\n\n<p>Secondly, we will trade this first asset (BTC) for a second one, here being ETH. Make sure that this second asset is connected to the starting and the following one.<\/p>\n\n\n\n<p>Thirdly, we will trade our second asset (ETH) for a third one, here being LTC. Make sure that this third asset is connected to the second and first one.<\/p>\n\n\n\n<p>And at the end, all we need to is to convert this third asset (LTC) back to the starting one (BTC).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2-1024x576.png\" alt=\"\" class=\"wp-image-6625\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2-1024x576.png 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2-300x169.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2-768x432.png 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2-1536x864.png 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Triangular Arbitrage Example<\/figcaption><\/figure>\n\n\n\n<p>As shown in the picture above, we will begin with the value of 1000 BTC. In order to calculate the opportunity and its value, we will simply go around the triangle by calculating the bid and ask prices for each cryptocurrency.<\/p>\n\n\n\n<p>In order to calculate the ratio we are dividing the ETH by LTC. As you can see I\u2019ve set the multiply and divide symbols that you use while going around the triangle.<\/p>\n\n\n\n<p>Let\u2019s calculate it together:<\/p>\n\n\n\n<p>1000 x 0.032 \/ 6.97 x 223.66 = 1026.85 BTC<\/p>\n\n\n\n<p>If we compare our newly computed value with the starting one, we can calculate the size of our opportunity.<\/p>\n\n\n\n<a name=\"how-to-take-advantage-of-arbitrage-algorithmically\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to take advantage of arbitrage algorithmically?<\/strong><\/h2>\n\n\n\n<p>As arbitrage opportunities last for a few seconds up to a few minutes, it is too time-consuming for a trader to calculate all the possibilities. This is where the algorithmic traders jump in with their cool algos that do the job quickly.<\/p>\n\n\n\n<p>Some traders prefer making the final decision when it comes to their arbitrage and thus they make an alert program that scans across multiple exchanges and notifies the trader with arbitrage possibilities.<\/p>\n\n\n\n<p>There are even third-party software that specializes in notifying subscribed traders with arbitrage opportunities. But beware! There are many scams out there when it comes to this software, so I would advise extensive research before picking one.<\/p>\n\n\n\n<p>As this article is focusing more on how to find mispricing I won\u2019t dabble further in how these algorithms are coded. <\/p>\n\n\n\n<p>I\u2019d advise the reader to check out our Binance and BitMex API guides so you get an idea of how to build an arbitrage.<\/p>\n\n\n\n<a name=\"how-to-find-a-crypto-arbitrage\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to find a crypto arbitrage?<\/strong><\/h2>\n\n\n\n<p>When it comes to finding crypto arbitrage opportunities, it can be done by two main methods. Let\u2019s cover both of them step-by-step.<\/p>\n\n\n\n<a name=\"method-1\">\n\n\n\n<h3 class=\"wp-block-heading\">Method 1<\/h3>\n\n\n\n<p>The first method involves using an exchange API from two different exchanges to compare the prices of the asset. This method is accurate but it suffers from not being scalable.<\/p>\n\n\n\n<p>Allow me to show you how to do it. I\u2019ll be using BitMex and Coinbase for this. Have in mind that we\u2019re only going to look for the mispricing, we won\u2019t fire any trades.<\/p>\n\n\n\n<p>If you want to fire a trade, check out our <a href=\"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/\">Coinbase<\/a> and BitMex API guides.<\/p>\n\n\n\n<p>Let us begin by importing the relevant libraries that we need:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import bitmex\nimport requests\nimport json\nimport datetime\nfrom coinbase.wallet.client import Client\nfrom time import sleep<\/code><\/pre><\/div>\n\n\n\n<p>The next step is to validate our API Keys and API Secrets:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>bitmex_api_key = &#39;EeE092m3lwJism5mAFc4plfX&#39; \nbitmex_api_secret = &#39;kgRLOsB7QOfauIyyNj5VOvPQ8ueLCuWWxwXTAI4ABcqqEMqk&#39;\n\ncoinbase_API_key = &#39;cTgYvXpaksr5fFgr&#39;\ncoinbase_API_secret = &#39;Css2cMN9kTjPNh2XvuHLM9HrdVcX3ty5&#39;<\/code><\/pre><\/div>\n\n\n\n<p>Now, let\u2019s set up the clients:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>client = bitmex.bitmex(api_key= bitmex_api_key, api_secret=bitmex_api_secret)\n\nclientb = Client(coinbase_API_key, coinbase_API_secret)<\/code><\/pre><\/div>\n\n\n\n<p>The next step is to create a loop that will check for the percent change between the two cryptocurrencies (BTC) prices. If the percent hits the 1.5% mark, we will want the program to notify us.<\/p>\n\n\n\n<p>Have in mind that for BitMex, we need to process the position endpoint result in order to get what we need. When it comes to Coinbase, we\u2019ll need to convert the obtained JSON string into a float value in order to calculate the percentage.<\/p>\n\n\n\n<p>Depending on your API package and limit you\u2019ll freely tweak the sleep times between API calls.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>while True:\n    positions = client.Position.Position_get(filter=json.dumps({&quot;symbol&quot;: &#39;XBTUSD&#39;})).result()[0][0]\n    bitmex_btc = {}\n    \n    bitmex_btc[&quot;markPrice&quot;] = positions[&quot;markPrice&quot;]\n    print(&#39;BitMex: &#39;,bitmex_btc[&#39;markPrice&#39;])\n    \n    coinbase_btc = clientb.get_spot_price(currency_pair= &#39;BTC-USD&#39;)\n    print(&#39;Coinbase: &#39;,coinbase_btc[&#39;amount&#39;])\n    \n    percent = float(((float(coinbase_btc[&#39;amount&#39;]) - bitmex_btc[&#39;markPrice&#39;]) * 100) \/ bitmex_btc[&#39;markPrice&#39;]) \n    \n    sleep (1)\n    \n    if percent &lt; 1.5:\n        print (&#39;No arbitrage possibility&#39;)\n        continue\n    \n    else:\n        if percent == 1.5:\n            print (&#39;ARBITRAGE TIME&#39;)\n            break\n    sleep(1)<\/code><\/pre><\/div>\n\n\n\n<a name=\"method-2\">\n\n\n\n<h3 class=\"wp-block-heading\">Method 2<\/h3>\n\n\n\n<p>The second method involves using data pulling APIs and websites that can scan across multiple exchanges, i.e. CoinGecko or CoinMarketCap. This method is less accurate than the previous one but is vastly scalable.<\/p>\n\n\n\n<p>For this example, we will use CoinGecko, which is a data provider and a crypto tracking website. If you want to learn more about CoinGecko and check out their API, visit the following link:<\/p>\n\n\n\n<p>Let&#8217;s begin by importing the relevant libraries we need:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import json\nfrom time import sleep\nfrom pycoingecko import CoinGeckoAPI\ncg = CoinGeckoAPI()<\/code><\/pre><\/div>\n\n\n\n<p>Now, we&#8217;ll call the CoinGecko API function that pulls the Bitcoin data for all exchanges it has:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>coin_tickers = cg.get_coin_ticker_by_id(id=&#39;bitcoin&#39;)\ncoin_tickers<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"446\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/3-1024x446.png\" alt=\"\" class=\"wp-image-6650\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/3-1024x446.png 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/3-300x131.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/3-768x335.png 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/3.png 1276w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The next, thing we want to zoom onto is the &#8216;tickers&#8221; part as it holds the last price data value. I will also make a new variable &#8220;btc&#8221; upon which we will make our data pulling and calculations.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>btc = coin_tickers[&#39;tickers&#39;]\nbtc<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1016\" height=\"548\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/4.png\" alt=\"\" class=\"wp-image-6651\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/4.png 1016w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/4-300x162.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/4-768x414.png 768w\" sizes=\"(max-width: 1016px) 100vw, 1016px\" \/><\/figure>\n\n\n\n<p>The next thing is to create a list for all the processed last price values. As I want to see currencies that deviate 1.5% from the specified currency, we&#8217;ll make an average starting price to compare the rest to.<\/p>\n\n\n\n<p>Notice how the last part of the if statement weeds out the outliers. Without it, one BTC instance was priced at more than $500k. This is good to keep in mind and implement as data can have bugs or mistakes in it. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>all_prices = []\nfor i in btc:\n    if i[&#39;target&#39;] == &#39;USDT&#39; or i[&#39;target&#39;] == &#39;USD&#39; and i[&#39;last&#39;]&lt;500000:\n        all_prices.append(i[&#39;last&#39;])\n        \nstarting_price = sum(all_prices)\/len(all_prices)\nprocessed = []<\/code><\/pre><\/div>\n\n\n\n<p>The next thing is to create a loop that will pull the data, calculate the percentage, and append it to the processed list. After that, we want the program to show us only the values that match our criteria.<\/p>\n\n\n\n<p>If the data doesn&#8217;t match our criteria we&#8217;ll run the loop after a specified time frame.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>while True:\n    for exchange in btc:\n        if exchange[&#39;target&#39;] == &#39;USDT&#39; or exchange[&#39;target&#39;] == &#39;USD&#39; and exchange[&#39;last&#39;] &lt; 500000:\n            percent = float(((starting_price - exchange[&#39;last&#39;]) * 100) \/ exchange[&#39;last&#39;])\n            if percent &gt;= 1.5 and exchange[&#39;last&#39;] &gt;= 100:\n                processed.append(str(exchange[&#39;market&#39;][&#39;name&#39;]) +&#39;:&#39;+ str(exchange[&#39;last&#39;]))\n        if len(processed) == 0:\n            sleep(30)\n            continue\n        else:\n            break\n    \nprocessed<\/code><\/pre><\/div>\n\n\n\n<a name=\"what-are-the-dangers-of-crypto-arbitrage\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are the dangers of crypto arbitrage?<\/strong><\/h2>\n\n\n\n<p>Crypto arbitrage methods carry some danger with them and I\u2019ll share the most notable ones with you:<\/p>\n\n\n\n<p><strong>High fees<\/strong><\/p>\n\n\n\n<p>Many traders are aware of the withdrawal fees that exchanges charge but some exchanges even charge deposit fees. And these fees can easily pile up and be get up to $20 per exchange.<\/p>\n\n\n\n<p><strong>Time<\/strong><\/p>\n\n\n\n<p>Most crypto arbitrage opportunities aren\u2019t long-lived because the markets fluctuate and adjust. If the market changes while you\u2019re in the process of a crypto arbitrage, most often, you\u2019re in for a loss.<\/p>\n\n\n\n<p><strong>Volume<\/strong><\/p>\n\n\n\n<p>If you\u2019re not careful enough, you might end up trying to sell delisted coins with no volume. This will get you stuck and you\u2019re going to lose most of you starting money.<\/p>\n\n\n\n<p>Moreover, a coin may have volume but the volume can be the one that you don\u2019t prefer for your buying and selling prices. Also, take in mind the exchange depth as they might be hyped up.<\/p>\n\n\n\n<p><strong>Transaction issues<\/strong> <\/p>\n\n\n\n<p>Exchanges can get bugged and that\u2019s where the fun on exchange overload, withdrawal issues, crashing, wallet issues and etc. come into play. This can ruin your arbitrage process which depends on speed and efficiency.<\/p>\n\n\n\n<a name=\"full-code\">\n\n\n\n<h2 class=\"wp-block-heading\">Full code<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/IgorWounds\/Crypto-Aribtrage-Mispricing-Algotrading101\">GitHub Link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_8507\" class=\"pvc_stats total_only  \" data-element-id=\"8507\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Table of contents: What is crypto arbitrage? Why does crypto arbitrage occur? What are the Pros and Cons of crypto arbitrage? What types of arbitrage exist? Spatial arbitrage Spatial arbitrage without transferring Triangular arbitrage How to take advantage of arbitrage algorithmically? How to find a crypto arbitrage? Method 1 Method 2 What are the dangers [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":6625,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"no","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Crypto Arbitrage Guide - What It Is and How to Find It - AlgoTrading101 Blog<\/title>\n<meta name=\"description\" content=\"The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Crypto Arbitrage Guide - What It Is and How to Find It - AlgoTrading101 Blog\" \/>\n<meta property=\"og:description\" content=\"The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-25T17:00:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-14T13:22:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Igor Radovanovic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Igor Radovanovic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Crypto Arbitrage Guide - What It Is and How to Find It - AlgoTrading101 Blog","description":"The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/","og_locale":"en_US","og_type":"article","og_title":"Crypto Arbitrage Guide - What It Is and How to Find It - AlgoTrading101 Blog","og_description":"The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.","og_url":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/","og_site_name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","article_published_time":"2021-03-25T17:00:53+00:00","article_modified_time":"2021-05-14T13:22:25+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/12\/2.png","type":"image\/png"}],"author":"Igor Radovanovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Igor Radovanovic","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/#article","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/"},"author":{"name":"Igor Radovanovic","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae"},"headline":"Crypto Arbitrage Guide &#8211; What It Is and How to Find It","datePublished":"2021-03-25T17:00:53+00:00","dateModified":"2021-05-14T13:22:25+00:00","mainEntityOfPage":{"@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/"},"wordCount":2627,"publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"articleSection":["Trading"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/","url":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/","name":"Crypto Arbitrage Guide - What It Is and How to Find It - AlgoTrading101 Blog","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/#website"},"datePublished":"2021-03-25T17:00:53+00:00","dateModified":"2021-05-14T13:22:25+00:00","description":"The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.","breadcrumb":{"@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/algotrading101.com\/learn\/crypto-arbitrage-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/algotrading101.com\/learn\/"},{"@type":"ListItem","position":2,"name":"Crypto Arbitrage Guide &#8211; What It Is and How to Find It"}]},{"@type":"WebSite","@id":"https:\/\/algotrading101.com\/learn\/#website","url":"https:\/\/algotrading101.com\/learn\/","name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","description":"Authentic Stories about Algorithmic trading, coding and life.","publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/algotrading101.com\/learn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/algotrading101.com\/learn\/#organization","name":"AlgoTrading101","url":"https:\/\/algotrading101.com\/learn\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/","url":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","contentUrl":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","width":1200,"height":627,"caption":"AlgoTrading101"},"image":{"@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae","name":"Igor Radovanovic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","caption":"Igor Radovanovic"},"sameAs":["https:\/\/igorradovanovic.com","https:\/\/www.linkedin.com\/in\/igor-radovanovic-profile"],"url":"https:\/\/algotrading101.com\/learn\/author\/igor\/"}]}},"modified_by":"Lucas Liew","_links":{"self":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/8507"}],"collection":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/comments?post=8507"}],"version-history":[{"count":12,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/8507\/revisions"}],"predecessor-version":[{"id":9355,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/8507\/revisions\/9355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media\/6625"}],"wp:attachment":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media?parent=8507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/categories?post=8507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/tags?post=8507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}