Skip to content

Commit 4723203

Browse files
committed
Allow to configure max_cycle from main
1 parent eb9b15a commit 4723203

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

main.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# start arbitrage detection
1616
print("Scanning...")
17-
exchange_name = "binance" # allow pickable exchange_id from https://github.com/ccxt/ccxt/wiki/manual#exchanges
17+
exchange_name = "binanceus" # allow pickable exchange_id from https://github.com/ccxt/ccxt/wiki/manual#exchanges
1818

1919
best_opportunities, best_profit = asyncio.run(detector.run_detection(exchange_name))
2020

@@ -40,16 +40,19 @@ def get_order_side(opportunity: detector.ShortTicker):
4040
# Format the output as below (real live example):
4141
# -------------------------------------------
4242
# New 2.33873% binanceus opportunity:
43-
# 1. buy DOGE to BTC at 552486.18785
44-
# 2. sell DOGE to USDT at 0.12232
45-
# 3. buy ETH to USDT at 0.00038
46-
# 4. buy ADA to ETH at 7570.02271
47-
# 5. sell ADA to USDC at 0.35000
48-
# 6. buy SOL to USDC at 0.00662
49-
# 7. sell SOL to BTC at 0.00226
43+
# 1. buy DOGE with BTC at 552486.18785
44+
# 2. sell DOGE for USDT at 0.12232
45+
# 3. buy ETH with USDT at 0.00038
46+
# 4. buy ADA with ETH at 7570.02271
47+
# 5. sell ADA for USDC at 0.35000
48+
# 6. buy SOL with USDC at 0.00662
49+
# 7. sell SOL for BTC at 0.00226
5050
# -------------------------------------------
5151
order_side = get_order_side(opportunity)
52-
print(f"{i+1}. {order_side} {base_currency} to {quote_currency} at {opportunity.last_price:.5f}")
52+
print(
53+
f"{i + 1}. {order_side} {base_currency} "
54+
f"{'with' if order_side == 'buy' else 'for'} "
55+
f"{quote_currency} at {opportunity.last_price:.5f}")
5356
print("-------------------------------------------")
5457
else:
5558
print("No opportunity detected")

triangular_arbitrage/detector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def get_best_triangular_opportunity(tickers: List[ShortTicker]) -> Tuple[List[Sh
4949
# Build a directed graph of currencies
5050
return get_best_opportunity(tickers, 3)
5151

52+
5253
def get_best_opportunity(tickers: List[ShortTicker], max_cycle: int = 10) -> Tuple[List[ShortTicker], float]:
5354
# Build a directed graph of currencies
5455
graph = nx.DiGraph()
@@ -92,7 +93,6 @@ def get_best_opportunity(tickers: List[ShortTicker], max_cycle: int = 10) -> Tup
9293
return best_cycle, best_profit
9394

9495

95-
9696
async def get_exchange_data(exchange_name):
9797
exchange_class = getattr(ccxt, exchange_name)
9898
exchange = exchange_class()
@@ -108,7 +108,8 @@ async def get_exchange_last_prices(exchange_name, ignored_symbols, whitelisted_s
108108
return last_prices
109109

110110

111-
async def run_detection(exchange_name, ignored_symbols=None, whitelisted_symbols=None):
111+
async def run_detection(exchange_name, ignored_symbols=None, whitelisted_symbols=None, max_cycle=None):
112112
last_prices = await get_exchange_last_prices(exchange_name, ignored_symbols or [], whitelisted_symbols)
113-
best_opportunity, best_profit = get_best_opportunity(last_prices) # default is best opportunity for all cycles
113+
# default is the best opportunity for all cycles
114+
best_opportunity, best_profit = get_best_opportunity(last_prices, max_cycle=max_cycle)
114115
return best_opportunity, best_profit

0 commit comments

Comments
 (0)