Skip to content

Commit 06d853f

Browse files
committed
Restore original symbols for reversed pairs
1 parent eb5d8b6 commit 06d853f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

main.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ def opportunity_symbol(opportunity):
2121
def get_order_side(opportunity: detector.ShortTicker):
2222
return 'buy' if opportunity.reversed else 'sell'
2323

24-
def get_symbol(opportunity: detector.ShortTicker):
25-
if opportunity.reversed:
26-
return str(symbols.Symbol(f"{opportunity.symbol.quote}/{opportunity.symbol.base}"))
27-
return str(opportunity.symbol)
28-
2924
# Display arbitrage detection result
3025
print("-------------------------------------------")
3126
print(f"New {round(best_profit, 4)}% {exchange_name} opportunity:")
3227
for i in range(3):
33-
print(f"{i+1}. {get_order_side(best_opportunities[i])} {get_symbol(best_opportunities[i])}")
28+
print(f"{i+1}. {get_order_side(best_opportunities[i])} {str(best_opportunities[i].symbol)}")
3429
print("-------------------------------------------")
3530

3631
if benchmark:

triangular_arbitrage/detector.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=W0702, C0325
22

33
import ccxt.async_support as ccxt
4-
from typing import List
4+
from typing import List, Tuple
55
from tqdm.auto import tqdm
66
from itertools import combinations
77
from dataclasses import dataclass
@@ -37,7 +37,7 @@ def get_last_prices(exchange_time, tickers):
3737
if tickers[key]['close'] is not None and not is_delisted_symbols(exchange_time, tickers[key])
3838
]
3939

40-
def get_best_opportunity(tickers: List[ShortTicker]) -> List[ShortTicker]:
40+
def get_best_opportunity(tickers: List[ShortTicker]) -> Tuple[List[ShortTicker], float]:
4141
# pylint: disable=W1114
4242
ticker_dict = {str(ticker.symbol): ticker for ticker in tickers if ticker.symbol is not None}
4343

@@ -85,6 +85,12 @@ def get_opportunity_symbol(a, b):
8585
best_profit = profit
8686
best_triplet = [a_to_b, b_to_c, c_to_a]
8787

88+
# restore original symbols for reversed pairs
89+
best_triplet = [
90+
ShortTicker(symbols.Symbol(f"{triplet.symbol.quote}/{triplet.symbol.base}"), triplet.last_price, reversed=True)
91+
if triplet.reversed else triplet
92+
for triplet in best_triplet]
93+
8894
return best_triplet, best_profit
8995

9096
async def get_exchange_data(exchange_name):

0 commit comments

Comments
 (0)