hzjken / crypto-arbitrage-framework

A cryptocurrency arbitrage framework implemented with ccxt and cplex. It can be used to monitor multiple exchanges, find a multi-lateral arbitrage path which maximizes rate of return, calculate the optimal trading amount for each pair in the path given flexible constraints, and execute trades with multi-threading implemenation.
552 stars 172 forks source link

OverflowError: Python int too large to convert to C long #11

Open danigr99727 opened 3 years ago

danigr99727 commented 3 years ago

Hi. Excelent work!

I managed to successfully run this project slightly modifying the original code to work only with binance and bittrex (removed kucoin). The code seems to work well most of the time and has been able to find some arbitrage opportunities.

However, every now and again, the code crashes with the following error:

Traceback (most recent call last):
  File "C:/crypto-arbitrage-framework/crypto/main.py", line 43, in <module>
    amt_optimizer.get_solution()
  File "C:\crypto-arbitrage-framework\crypto\amount_optimizer.py", line 51, in get_solution
    self._update_path_params()
  File "C:\crypto-arbitrage-framework\crypto\amount_optimizer.py", line 60, in _update_path_params
    self.path_order_book()  # requires internet connection
  File "C:\crypto-arbitrage-framework\crypto\amount_optimizer.py", line 336, in path_order_book
    order_book[0][1] = self.big_m  # infinity amount for inter exchange transfer
OverflowError: Python int too large to convert to C long

Any idea what could be causing this?

Thank you!

OS: Win 10 Python: 3.7 x64 ccxt: 1.41.31 cplex: 20.1.0.0 docplex: 2.19.202 numpy: 1.19.5

hzjken commented 3 years ago

I believe this is due to the overflow of big_m value in the setting.

You can change the big_m value to maybe 1e+6 here https://github.com/hzjken/crypto-arbitrage-framework/blob/882049565d92bdab0c79da95ffe353594b6cc89c/crypto/amount_optimizer.py#L44

the bigM is just set as a random big number and used as an approximate infinite upper bound in the linear programming. changing from 1e+10 to 1e+6 should be fine.

Have a try.