wardbradt / peregrine

Detects arbitrage opportunities across 131 cryptocurrency exchanges in 50 countries
MIT License
1.18k stars 339 forks source link

ValueError: math domain error #71

Closed reall0c closed 3 years ago

reall0c commented 3 years ago

Hi, when do `from peregrinearb import create_weighted_multi_exchange_digraph, bellman_ford_multi, print_profit_opportunity_for_path_multi

graph = create_weighted_multi_exchange_digraph(['hitbtc','exmo','bitfinex','poloniex','kraken', 'bittrex', 'binance'], log=True) graph, paths = bellman_ford_multi(graph, 'BTC', unique_paths=True) for path in paths: print_profit_opportunity_for_path_multi(graph, path)`

its appear 6 times Task exception was never retrieved future: <Task finished coro=<_add_market_to_multi_digraph() done, defined at /h/z/Documents/Arbitrage program/peregrine/peregrinearb/utils/multi_exchange.py:98> exception=ValueError('math domain error')> Traceback (most recent call last): File "/home/tech/Documents/Arbitrage program/peregrine/peregrinearb/utils/multi_exchange.py", line 135, in _add_market_to_multi_digraph weight=-math.log(fee_scalar*ticker_bid)) ValueError: math domain error and finish with this: Starting with 100 in BTC BTC to MEME at 3990000.000000001 = 399000000.0000001 on bittrex for MEME/BTC MEME to USDT at 195.37864091391904 = 77956077724.65372 on poloniex for MEME/USDT USDT to STX at 127.95389048991358 = 9974783432203.533 on hitbtc for STX/USDT STX to BNB at 0.008031959999999998 = 80117061536.12148 on binance for STX/BNB BNB to COCOS at 100909.09090909087 = 8084539845917709.0 on binance for COCOS/BNB COCOS to BTC at 1.6413570000000026e-08 = 132696160.67875974 on hitbtc for COCOS/BTC Could you tell me why throw error with math domain error ? Thanks

edouardkombo commented 3 years ago

Instead of math.log, use math.log1p. It returns the natural logarithm of 1+x (base e). The result is calculated in a way which is accurate for x near zero.

I created a fork of the project and am updating it.

edouardkombo commented 3 years ago

@Quantk a fix has been added here https://github.com/wardbradt/peregrine/pull/77