From 06d853f2027f699122d3b67b0974f127b473e5ae Mon Sep 17 00:00:00 2001 From: Herklos Date: Thu, 19 Oct 2023 01:03:18 +0200 Subject: [PATCH] Restore original symbols for reversed pairs --- main.py | 7 +------ triangular_arbitrage/detector.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 39feb70..41bb0c8 100644 --- a/main.py +++ b/main.py @@ -21,16 +21,11 @@ def opportunity_symbol(opportunity): def get_order_side(opportunity: detector.ShortTicker): return 'buy' if opportunity.reversed else 'sell' - def get_symbol(opportunity: detector.ShortTicker): - if opportunity.reversed: - return str(symbols.Symbol(f"{opportunity.symbol.quote}/{opportunity.symbol.base}")) - return str(opportunity.symbol) - # Display arbitrage detection result print("-------------------------------------------") print(f"New {round(best_profit, 4)}% {exchange_name} opportunity:") for i in range(3): - print(f"{i+1}. {get_order_side(best_opportunities[i])} {get_symbol(best_opportunities[i])}") + print(f"{i+1}. {get_order_side(best_opportunities[i])} {str(best_opportunities[i].symbol)}") print("-------------------------------------------") if benchmark: diff --git a/triangular_arbitrage/detector.py b/triangular_arbitrage/detector.py index 476f2f6..8aad0af 100644 --- a/triangular_arbitrage/detector.py +++ b/triangular_arbitrage/detector.py @@ -1,7 +1,7 @@ # pylint: disable=W0702, C0325 import ccxt.async_support as ccxt -from typing import List +from typing import List, Tuple from tqdm.auto import tqdm from itertools import combinations from dataclasses import dataclass @@ -37,7 +37,7 @@ def get_last_prices(exchange_time, tickers): if tickers[key]['close'] is not None and not is_delisted_symbols(exchange_time, tickers[key]) ] -def get_best_opportunity(tickers: List[ShortTicker]) -> List[ShortTicker]: +def get_best_opportunity(tickers: List[ShortTicker]) -> Tuple[List[ShortTicker], float]: # pylint: disable=W1114 ticker_dict = {str(ticker.symbol): ticker for ticker in tickers if ticker.symbol is not None} @@ -85,6 +85,12 @@ def get_opportunity_symbol(a, b): best_profit = profit best_triplet = [a_to_b, b_to_c, c_to_a] + # restore original symbols for reversed pairs + best_triplet = [ + ShortTicker(symbols.Symbol(f"{triplet.symbol.quote}/{triplet.symbol.base}"), triplet.last_price, reversed=True) + if triplet.reversed else triplet + for triplet in best_triplet] + return best_triplet, best_profit async def get_exchange_data(exchange_name):