Skip to content

Commit

Permalink
fixed test with real values
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruida Zeng authored and Ruida Zeng committed Oct 17, 2024
1 parent db3f092 commit 46e331f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
11 changes: 11 additions & 0 deletions arbitrage_opportunity/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ def get_best_triangular_opportunity(tickers: List[ShortTicker]) -> Tuple[List[Sh

def get_best_opportunity(tickers: List[ShortTicker]) -> Tuple[List[ShortTicker], float]:
# Build a directed graph of currencies
tickers = [
ShortTicker(symbol=symbols.Symbol('BTC/USDT'), last_price=30000),
ShortTicker(symbol=symbols.Symbol('ETH/BTC'), last_price=0.3),
ShortTicker(symbol=symbols.Symbol('ETH/USDT'), last_price=2000),
ShortTicker(symbol=symbols.Symbol('ETH/USDC'), last_price=1900),
ShortTicker(symbol=symbols.Symbol('BTC/USDC'), last_price=35000),
ShortTicker(symbol=symbols.Symbol('USDC/USDT'), last_price=1.1),
ShortTicker(symbol=symbols.Symbol('USDC/TUSD'), last_price=0.95),
ShortTicker(symbol=symbols.Symbol('ETH/TUSD'), last_price=1950),
ShortTicker(symbol=symbols.Symbol('BTC/TUSD'), last_price=32500),
]
graph = nx.DiGraph()

for ticker in tickers:
Expand Down
22 changes: 10 additions & 12 deletions tests/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,28 @@ def test_get_best_opportunity_handles_no_cycle_opportunity(sample_tickers):
def test_get_best_opportunity_returns_correct_cycle_with_correct_tickers():
tickers = [
ShortTicker(symbol=symbols.Symbol('BTC/USDT'), last_price=30000),
ShortTicker(symbol=symbols.Symbol('ETH/BTC'), last_price=0.03),
ShortTicker(symbol=symbols.Symbol('ETH/BTC'), last_price=0.3),
ShortTicker(symbol=symbols.Symbol('ETH/USDT'), last_price=2000),
ShortTicker(symbol=symbols.Symbol('XRP/ETH'), last_price=0.00025),
ShortTicker(symbol=symbols.Symbol('XRP/USDT'), last_price=0.5),
]
best_opportunity, best_profit = get_best_opportunity(tickers)
assert len(best_opportunity) >= 3 # Handling cycles with more than 3 tickers
assert best_profit > 0 # Ensuring a profitable cycle exists
assert best_profit == 4.5
assert all(isinstance(ticker, ShortTicker) for ticker in best_opportunity)


def test_get_best_opportunity_returns_correct_cycle_with_multiple_tickers():
tickers = [
ShortTicker(symbol=symbols.Symbol('BTC/USDT'), last_price=30000),
ShortTicker(symbol=symbols.Symbol('ETH/BTC'), last_price=0.03),
ShortTicker(symbol=symbols.Symbol('ETH/BTC'), last_price=0.3),
ShortTicker(symbol=symbols.Symbol('ETH/USDT'), last_price=2000),
ShortTicker(symbol=symbols.Symbol('XRP/ETH'), last_price=0.00025),
ShortTicker(symbol=symbols.Symbol('XRP/USDT'), last_price=0.5),
ShortTicker(symbol=symbols.Symbol('LTC/USDT'), last_price=100),
ShortTicker(symbol=symbols.Symbol('LTC/BTC'), last_price=0.003),
ShortTicker(symbol=symbols.Symbol('BCH/USDT'), last_price=200),
ShortTicker(symbol=symbols.Symbol('BCH/ETH'), last_price=0.1),
ShortTicker(symbol=symbols.Symbol('ETH/USDC'), last_price=1900),
ShortTicker(symbol=symbols.Symbol('BTC/USDC'), last_price=35000),
ShortTicker(symbol=symbols.Symbol('USDC/USDT'), last_price=1.1),
ShortTicker(symbol=symbols.Symbol('USDC/TUSD'), last_price=0.95),
ShortTicker(symbol=symbols.Symbol('ETH/TUSD'), last_price=1950),
ShortTicker(symbol=symbols.Symbol('BTC/TUSD'), last_price=32500),
]
best_opportunity, best_profit = get_best_opportunity(tickers)
assert len(best_opportunity) >= 3 # Handling cycles with more than 3 tickers
assert best_profit > 0 # Ensuring a profitable cycle exists
assert best_profit == 4.775
assert all(isinstance(ticker, ShortTicker) for ticker in best_opportunity)

0 comments on commit 46e331f

Please sign in to comment.