Automated Triangular Arbitrage of Cryptos in 4 steps (2024)

Build your own arbitrage trading algorithm in Python

Arbitrage takes advantage of the difference in the asset prices in the market. Arbitrage has been traditionally done in the forex market for many years but given the volatility in the crypto market, it can applied to the crypto market as well. Opportunities for arbitrage can exist within the same exchange or across exchanges.

Triangular arbitrage is a technique that tries to exploit the price discrepancy across three different assets at the same time.
For example, we can exchange BTC for USDT, BTC for ETH and ETH back to USDT. If the net worth in doing these three trades simultaneously is profitable then the 3 trades are executed simultaneously.

Automated Triangular Arbitrage of Cryptos in 4 steps (1)

In this article we will be looking into the arbitrage opportunities within the same exchange, in particular we will be deep diving into triangular arbitrage approaches. The focus is to develop and implement a trading algorithm that can identify a profit and trigger the required trade orders for it.

Arbitrage is considered as a lower risk trading method as compared to the traditional trading where the timing of the buy/sell is crucial. Also in arbitrage, the profit/loss is known immediately as all the required trades are executed simultaneously.

There are different approaches of buying/selling the 3 assets to achieve triangular arbitrage. In this article we shall be considering two approaches.

Approach 1: BUY — BUY — SELL

Automated Triangular Arbitrage of Cryptos in 4 steps (2)

In the above example, we start with USDT as the initial investment. After performing the 3 trades, we are again left with USDT at the end. Here are the trades that will be performed:

  1. Buy Bitcoin (BTC) with Tether (USDT)
  2. Buy Ethereum (ETH) with Bitcoin (BTC)
  3. Sell Ethereum (ETH) for Tether (USDT)

At the end of the third trade, we can compare the final USDT with the initial investment that we started with in step 1. If this leads to a substantial profit then the 3 trades can be initiated simultaneously.

Approach 2: BUY — SELL — SELL

Automated Triangular Arbitrage of Cryptos in 4 steps (3)

Similar to the first approach, the same assets are used to check for arbitrage opportunities in a different flow. In the above example the following 3 trades are evaluated:

  1. Buy Ethereum (ETH) with Tether (USDT)
  2. Sell Ethereum (ETH) for Bitcoin (BTC)
  3. Sell Bitcoin (BTC) for Tether (USDT)

Here is an overview of the different steps to implement a triangular arbitrage trading algorithm. We shall be looking into each of these steps in detail in the next sections.

Step 1: Get all the valid crypto combinations
Step 2: Perform triangular arbitrage
Step 3: Place the trade orders
Step 4: Bundle it together

Before moving ahead with these steps we need to initialise the exchange to do the arbitrage. Select the exchange where you have a trading account and the one that supports api based trading. In this example I have used the WazirX exchange as I have a trading account in this exchange.

import ccxt
from config import myconfig
exchange = ccxt.wazirx({
“apiKey”: myconfig.API_KEY,
“secret”: myconfig.API_SECRET
})

The package ccxt supports various exchanges and in case you have an account in any of the other exchanges then you can get the same code working by just changing the exchange’s name in the above snippet. Refer to this page to get the list of exchanges supported by ccxt.

We need a base currency with the initial investment in our trading account to get started. Here we consider USDT as the base currency. Note that even fiat currencies like INR or USD can be considered as the base currency.

There are hundreds of cryptos supported by the exchange and hence we can derive different combinations to perform the triangular arbitrage. We can either hard-code to a limited set of combinations or allow the code to consider all the possible combinations available in the exchange. The below code snippet implements the second approach of identifying all the possible arbitrage combinations.

There are 543 crypto assets supported by this exchange at the time of writing this article.

Next extract all the possible combinations to apply the BUY-BUY-SELL and the BUY-SELL-SELL approaches of triangular arbitrage.

There are 63 different arbitrage combinations that the code was able to identify.

Automated Triangular Arbitrage of Cryptos in 4 steps (5)

Eg: If a BUY-BUY-SELL algorithm has to be applied on the first entry, then:

  1. Buy BTC (intermediate) for USDT (base)
  2. Buy XRP (ticker) for BTC (intermediate)
  3. Sell XRP (ticker) for USDT (base)

If this circular trade can lead to a profit, then we are good to execute the 3 trades simultaneously.

Pull the prices of the three assets from the exchange and identify the final price after performing the three buy/sell conversions.

Similarly the BUY-SELL-SELL approach also needs to be implemented. Only a snippet of the code is provided here to avoid code congestion. Please refer to the git repository linked in the end of the article to get the complete executable code.

Calculate the profit/loss in performing this triangular arbitrage by considering the exchange’s brokerage for each transaction and the minimum profit expected from the trade.

Here is the code to execute the three trades on the exchange. If market price trade is not supported by the exchange, then a limit price trade needs to be executed. Limit price orders can sometimes cause the trading order to be stuck if the price has fluctuated before the execution of the order.

Wrap the above steps to a single package and run it for all the possible combinations.

For each combination perform the below 3 steps
(Example: Buy — BTC/USDT, sell — ETH/BTC, sell — ETH/USDT)

  1. Identify the final sell price after performing the 3 trades
  2. Calculate the profit/loss in making these transactions
  3. Place the 3 trade orders if the transactions lead to the desired profit

Here is a sample result on running this code for one iteration.

An initial investment of 100$ was considered. With 63 combinations and 2 approaches, a total of 126 arbitrage combinations were checked and 26 of them showed a profit as below.

Automated Triangular Arbitrage of Cryptos in 4 steps (6)

Note that the above table is from the logs and not from actual trades that were executed. Though this table shows a rosy figure, it may not always be a smooth ride in reality.

  1. Since all the three orders need to be executed simultaneously to realise the profit, there are chances that some orders don’t get executed on time due to network delays or issue with the exchange. In such a scenario you could be stuck with the cryptos and a manual intervention might be required.
  2. The crypto price considered here is the live ticker price. The prices can fluctuate before the orders are executed. Better approach would be to take the entries from the order book and choose the ticker price based on the volume.
  3. Three ticker prices are required simultaneously from the exchange to perform the triangular arbitrage. Some exchanges set a rate limit which does not allow repeated api calls. In such a case the api might throw a RateLimitExceeded (HTTP 429 Too Many Requests) exception. This can be handled by using a 1-second sleep timer between the api calls. But if the price changes within these couple of seconds then the orders may not execute.
  4. Some exchanges don’t allow to place orders at market price (like in my example). Limit price is required. In such cases, again there are chances that the orders don’t get executed due to the price fluctuation.

Refer to this git repo to access the complete code: TriangularArbitrageCryptos

Based on the exchange and the api support that it provides, the trading algorithms can be tuned further. Try playing around with the code by changing the base currency, using market price trades or checking on other arbitrage approaches.

Again, the disclaimer, this article is only for educational purposes and for you to understand the different types of trading options available. Remember that you are competing with several other trading bots out there. In case you want to experiment with real trades then first ensure that you have built a robust trading algorithm before venturing into it to avoid losses.

Additionally, if you are interested in wrapping this code within a trading bot application, use this article as a reference: Building a basic Crypto Trading Bot in Python

Thanks for reading till the end :-). Happy experimenting!!

IF “PYTHON+TRADING” FASCINATES YOU THEN CHECK THESE OUT…

  • Beginner’s Guide to Technical Analysis in Python for Algorithmic Trading
  • Building a Basic Crypto Trading Bot in Python
  • Automated Triangular Arbitrage of Cryptos in 4 steps [you are here]
  • Identifying Trading Patterns — Behavioural Analysis of Traders
  • Fundamental Analysis of Stocks using Python
Automated Triangular Arbitrage of Cryptos in 4 steps (2024)

FAQs

How to do triangular arbitrage in crypto? ›

Triangular arbitrage takes advantage of price discrepancies between three different assets – usually cryptocurrencies – in the market. The concept is simple: A trader exchanges one crypto asset for a second, the second for a third, and the third for the first.

What is the triangular arbitrage trick? ›

Triangular Arbitrage is a trading strategy that seeks to exploit pricing inefficiencies between three different currencies when their exchange rates do not match up exactly. This could be across different exchanges, or within the same platform.

Is triangular arbitrage possible in crypto? ›

While such egregious examples of pricing inefficiencies are less prominent these days as crypto exchanges and arbitrage bots jump at the opportunity to close up the gap, crypto triangular arbitrage opportunities certainly still exist.

What is automated crypto arbitrage? ›

Crypto arbitrage bots are automated trading programs that use algorithms to analyze price differences across multiple exchanges and execute trades on behalf of the trader. These bots can quickly identify price discrepancies and execute trades in a matter of seconds, much faster than any human trader could.

Can you make a living off crypto arbitrage? ›

There is always some profit to be made from arbitrage if you are a day trader in the crypto market. To profit from arbitrage, you must be persistent and quick to take advantage of profitable opportunities. They buy cryptocurrency from one exchange and sell it on another.

How do I get started in crypto arbitrage? ›

Justin Robins
  1. Crypto Arbitrage – A Beginner's Guide. ...
  2. Crypto Investing Step 1: Create an Account With an Exchange. ...
  3. Crypto Investing Step 2: Fund Your New Exchange Account. ...
  4. Crypto Investing Step 3: Purchase USD, USDT or BNB. ...
  5. Crypto Investing Step 4: Transfer Tokens from Exchanges and Wallets.
Mar 28, 2022

What currencies are best for triangular arbitrage? ›

Triangular arbitrage can be applied to the three currencies – the US dollar, the euro, and the pound. To execute the triangular arbitrage opportunity, Sam should perform the following transactions: Sell dollars for euros: $1,000,000 x 0.8678 = €867,800.

What is the best way to arbitrage bet? ›

The most common arbitrage bet is made by taking positions in the market across a bookmaker and a betting exchange - backing at the bookmaker and then laying the same outcome on the betting exchange.

Is triangular arbitrage illegal? ›

Yes, triangular arbitrage is a legal method of making profits and gains through transacting two currencies between different markets. However, the large sums of money transacted by investors and traders should not be sourced illegally as black money.

Which crypto arbitrage is best? ›

List of the BEST Crypto Arbitrage Bot:
  • 1) Pionex – Best for Crypto Trading arbitrage platform for Beginners and Advanced Users.
  • 2) Cryptohopper – Best for Copy arbitrage trading and Fixed Fee Option.
  • 3) Bitsgap – Best for arbitrage trading across various crypto exchanges.
  • 4) Coinrule – Best for Advanced Trading Indicators.
May 22, 2023

What are the best coins for arbitrage? ›

Which coins can be used for arbitrage trading? Any coin can be used for arbitrage trading, such as Bitcoin, Ethereum, Litecoin, Ripple (XRP), USDT, and USDC. A coin with high volatility and unique opportunities would be a better choice majority of the time.

Does Coinbase allow arbitrage? ›

Yes, ARBITRAGE can be custodied on Coinbase Wallet.

Can you make money from automated crypto trading? ›

Answer: Trading bots are profitable for as long as you can configure them properly. The best crypto trading bots will obviously make a profit and it is essential to set to test them or have some sort of guarantee first before buying.

How much can I make from crypto arbitrage? ›

With crypto arbitrage trading, you can make up to $100 in profit every day. I know you are eager to learn how to start up your own profitable crypto arbitrage business, but we will get into that in a bit. Next, let us look at the things you need to have a successful business.

Can you become a multi millionaire from crypto? ›

Many people have become crypto millionaires because they've, well, bought low and sold high. But there are also various kinds of crypto millionaires, the crypto entrepreneurs who have the necessary business acumen to create world-changing solutions.

Is crypto arbitrage legal in the US? ›

Bitcoin arbitrage is legal, as is arbitrage in most other financial assets. Arbitrage plays an important role in creating efficient markets and setting clear prices for market participants. Arbitrage plays an important role in creating efficient markets and setting clear prices for market participants.

Can you lose money in arbitrage? ›

In some situations, it is even possible for the investor to have a loss at the con- vergence date of the arbitrage. In this situation, the investor ends up worse off than if he had invested only in the riskless asset.

What is an example of crypto arbitrage? ›

Through a single exchange like Kraken, you can participate in triangular arbitrage trading, which involves spotting the price differences between three cryptocurrencies on the exchange. For example, you can purchase XLM with BTC, sell XLM to ETH, and convert ETH back to BTC.

How to build a crypto arbitrage bot? ›

In this microblog, we will discuss the steps to building a profitable crypto arbitrage trading bot.
  1. Step 1: Choose a Cryptocurrency Exchange. ...
  2. Step 2: Partner with a Development Company. ...
  3. Step 3: Define Your Trading Strategy. ...
  4. Step 4: Develop and Test Your Bot. ...
  5. Step 5: Monitor Your Bot. ...
  6. Step 6: Refine and Optimize Your Bot.
Mar 20, 2023

How do you make money with crypto arbitrage? ›

Some cryptocurrency exchanges allow users to lend and borrow cryptocurrencies. As a result, arbitrage trading presents opportunities for cryptocurrency traders to profit. All you need to do is visit an exchange that lends money to another exchange with a higher rate after borrowing it from users at a lower rate.

How profitable is triangular arbitrage? ›

Profitable triangular arbitrage is very rarely possible because when such opportunities arise, traders execute trades that take advantage of the imperfections and prices adjust up or down until the opportunity disappears.

Is triangular arbitrage risky? ›

Triangular arbitrage is a form of low-risk profit-making by currency traders that takes advantage of exchange rate discrepancies through algorithmic trades. To ensure profits, such trades should be performed quickly and should be large in size.

What is the most predictable currency pairs? ›

One of the most predictable forex pairs is the EUR/USD. This currency pair represents the euro and the US dollar, two of the world's most widely traded currencies. The EUR/USD is also the most actively traded currency pair in the world, accounting for over 20% of all forex trades.

What is the simplest form of arbitrage? ›

Simple arbitrage involves simultaneously buying and selling one asset on two different exchanges. Unlike retail arbitrage, traders may assume very little risk because the transactions are executed at the same time.

How risky is arbitrage? ›

Criticism of Risk Arbitrage

If the deal does not happen for whatever reason, the usual result would be a drop—potentially sharp—in the stock price of the target and a rise in the stock price of the would-be acquirer. An investor who is long the target's shares and short the acquirer's shares will suffer losses.

How do you find arbitrage opportunities in Crypto? ›

To find the right arbitrage opportunity, you need to analyze crypto prices on different exchanges. You can use crypto arbitrage software and tools to help you monitor prices on various exchanges. The software can help you identify price differences, which you can use to make a profit.

Can arbitrage make me rich? ›

Arbitrage is the practice of taking advantage of a price difference between two or more assets or markets, and profiting until the price difference disappears. Recognizing arbitrage opportunities is one of the easiest ways to make money.

Do people make money from arbitrage? ›

In the course of making a profit, arbitrage traders enhance the efficiency of the financial markets. As they buy and sell, the price differences between identical or similar assets narrow. The lower-priced assets are bid up, while the higher-priced assets are sold off.

How much do arbitrage bots cost? ›

Featured Crypto Arbitrage Bots: An Overview
BotDescriptionPrice
TralityBest for Building BotsFree Forever Plan, then plans start at €9.99/month
BitsgapBest for Exchange Compatibility7-day free trial, then plans start at $24/month
3CommasBest for Advanced UsersFree Forever Plan; then plans start at $14.50/month
4 more rows
Nov 25, 2022

Is crypto arbitrage bot profitable? ›

Can you make money with crypto arbitrage? Crypto arbitrage can be profitable, but given that the price difference in exchanges is usually tiny, this trading strategy is most profitable when you have a large sum of money to invest, and also have access to arbitrage bots.

Which type of arbitrage is very rare? ›

This means the potential for pure arbitrage has become a rare occurrence.

Where to invest in arbitrage? ›

Best-Performing Arbitrage Funds in India
Fund NameAssets under management (AuM)1-year Returns
Kotak Equity Arbitrage Fund19,522.216.12%
Tata Arbitrage Fund5,187.306.03%
Edelweiss Arbitrage Fund4,316.856.06%
SBI Arbitrage Opportunities Fund7,587.096.06%
8 more rows
May 5, 2023

Are arbitrage bots legal? ›

Arbitrage trading is not only legal in the United States, but is encouraged, as it contributes to market efficiency. Furthermore, arbitrageurs also serve a useful purpose by acting as intermediaries, providing liquidity in different markets.

What is an example of arbitrage? ›

Arbitrage Examples

Assume that a stock XYZ is listed in both markets A and B. The price of XYZ in market A is $17, but in market B, the price is 16.69 Sterling Pounds ($20). Therefore, Peterson, the arbitrageur, buys 100 XYZ stocks in market A. He spent $1700 and then sold the stocks in market B for $2000.

Can you make money by buying and selling on Coinbase? ›

But you can earn rewards simply by buying and holding dollar-pegged stablecoins like Dai and USD Coin (USDC). As of June 2021, you can earn 2.00% APY rewards by simply holding Dai in your Coinbase account. You can also earn 0.15% APY for holding USD Coin — and can earn even more via USDC Lending (see tip No. 4).

What is the most profitable crypto trading strategy? ›

Arbitrage is one of the most popular strategies on the market. It involves buying a coin on one platform and selling it on another using the difference in price between the two platforms. Like scalping, arbitrage tends to generate small profits. Thus, the larger your order size, the more profit you can make.

Can you make a living off trading bots? ›

If the bot doesn't lose any trades in this kind of trading month, the trader could potentially earn 20% each month for an all-in strategy. This means that an account with $10,000 will earn up to $2,000. A trading bot can theoretically make a trader a billionaire.

Can you make a living from a trading bot? ›

The amount of money you can earn from using trading bots varies greatly. It largely depends on how much knowledge and experience. Another key factor is how much time you have. Yes, bots do save you time, but you still need to carry out research on trends and keep up with crypto news and things like that.

How much do arbitrage traders make? ›

Arbitrage Trader Salary
Annual SalaryMonthly Pay
Top Earners$182,500$15,208
75th Percentile$110,000$9,166
Average$94,266$7,855
25th Percentile$47,000$3,916

Why is arbitrage illegal? ›

Arbitrage is not illegal by itself, but it does have risks associated with it. These include allocating capital poorly. You could enter into contracts incorrectly. This could result in the buying or selling of an asset at an unfavorable price.

Can you make a living buying and selling crypto? ›

You can buy crypto and hold it until its value rises, then sell for a profit — and even engage in day trading if your goal is quick income. But be wary: cryptocurrency and day trading are both high risk, so never invest more than you can afford to lose.

Which exchange is best for triangular arbitrage? ›

Best Exchanges For Crypto Arbitrage – Arbitrage Between Crypto Exchanges
  • KuCoin.
  • FTX.
  • Phemex.
  • Gate.io.
  • ByBit.
Oct 12, 2022

Top Articles
Buy Axie Infinity with Credit or Debit Card • Nexo
Fleet-wide Vehicle Tracker Installation Time - Crystal Ball
Dainty Rascal Io
Great Clips Mount Airy Nc
Chicago Neighborhoods: Lincoln Square & Ravenswood - Chicago Moms
Kokichi's Day At The Zoo
Amtrust Bank Cd Rates
30 Insanely Useful Websites You Probably Don't Know About
25X11X10 Atv Tires Tractor Supply
Insidious 5 Showtimes Near Cinemark Tinseltown 290 And Xd
Shorthand: The Write Way to Speed Up Communication
EY – все про компанію - Happy Monday
Sprague Brook Park Camping Reservations
Pike County Buy Sale And Trade
Big Y Digital Coupon App
Whitley County Ky Mugshots Busted
Grasons Estate Sales Tucson
Enterprise Car Sales Jacksonville Used Cars
Overton Funeral Home Waterloo Iowa
How to Create Your Very Own Crossword Puzzle
Inter-Tech IM-2 Expander/SAMA IM01 Pro
*Price Lowered! This weekend ONLY* 2006 VTX1300R, windshield & hard bags, low mi - motorcycles/scooters - by owner -...
Finalize Teams Yahoo Fantasy Football
What Channel Is Court Tv On Verizon Fios
O'Reilly Auto Parts - Mathis, TX - Nextdoor
Sullivan County Image Mate
Babbychula
Exl8000 Generator Battery
LCS Saturday: Both Phillies and Astros one game from World Series
F45 Training O'fallon Il Photos
When Does Subway Open And Close
Weathervane Broken Monorail
Pixel Combat Unblocked
Sams Gas Price Sanford Fl
Obituaries, 2001 | El Paso County, TXGenWeb
Salemhex ticket show3
Robert A McDougal: XPP Tutorial
Dtlr On 87Th Cottage Grove
Current Time In Maryland
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Www Craigslist Com Shreveport Louisiana
Metra Union Pacific West Schedule
A Man Called Otto Showtimes Near Amc Muncie 12
Finland’s Satanic Warmaster’s Werwolf Discusses His Projects
What Is A K 56 Pink Pill?
30 Years Of Adonis Eng Sub
56X40X25Cm
Ucla Basketball Bruinzone
Breaking down the Stafford trade
Sam's Club Gas Price Sioux City
Take Me To The Closest Ups
Mit diesen geheimen Codes verständigen sich Crew-Mitglieder
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6227

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.