Skip to content

Commit

Permalink
Restore original symbols for reversed pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 19, 2023
1 parent eb5d8b6 commit 06d853f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 1 addition & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions triangular_arbitrage/detector.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 06d853f

Please sign in to comment.