Drakkar-Software / Triangular-Arbitrage

Crypto triangular arbitrage by OctoBot
https://www.octobot.cloud/tools/triangular-arbitrage?utm_source=github&utm_medium=dk&utm_campaign=free_tools&utm_content=repo_link
GNU Affero General Public License v3.0
58 stars 15 forks source link

Higher order cycles #16

Closed ruidazeng closed 3 weeks ago

ruidazeng commented 1 month ago

@Herklos Would you cycle_detector be of any interest in terms of arbitrage opportunity detection? For the test case, total profit from the best triangular arbitrage opportunity is approximately 452.63% (SELL ETH to BTC at 0.30, SELL BTC to USDC at 35,000, BUY ETH from USDC at approximately 0.000526 (reversed from USDC to ETH) vs 477.5% binance opportunity below:

-------------------------------------------
1. BUY USDT to ETH at 0.00050
2. SELL ETH to BTC at 0.30000
3. SELL BTC to USDC at 35000.00000
4. SELL USDC to USDT at 1.10000
-------------------------------------------

In my opinion (I might be wrong about this), if less available currency exchange quotes exist, then the triangular arbitrage opportunity pales in comparison of higher-order cycle arbitrage opportunity. This might be true for some certain crypto currency that are not available on central exchanges and are only traded by AMMs (automated market makers); as an anecdote, my advisor once received compensation for his crypto contributions in the form of a very very niche currency that required a long path to convert back to cash.

Herklos commented 1 month ago

I think this is an interesting idea! Currently, this repo focuses only on triangular arbitrage, but adding the ability to detect more than three cycles could be a great feature. I haven't looked into four-cycle opportunities yet, but your examples show that they could definitely exist. Thanks for sharing your thoughts!

ruidazeng commented 1 month ago

@Herklos

Some other thoughts:

The set of all cycle is for a specific set is significantly larger than the set of all triangular cycles for exchanges if there is an exchange ticker available between every currency to each other; moreover, in that scenario, most longer cycle can be composed entirely from the smaller 3-cycles (triangular cycles), hence higher order cycle detections are not necessary.

However, for smaller DEX that concerns with super niche currencies, where links do not necessarily exist between every currencies (like the example below, very simplified of course and completely made up), then the triangular will completely miss the arbitrage opportunity (in example: Solana > Ethereum > Algorand > Uniswap > Solana), even when if it's extremely profitable:

dex

Either way, the algorithm is the same - Johnson's Algorithm (1975) for finding the shortest paths between all pairs of vertices in an edge-weighted directed graph.