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

Exceptions #5

Closed stdusr closed 4 years ago

stdusr commented 4 years ago

Good day, would you be so kind to provide exact versions of Python and dependant modules which are enough to run the minimal example? Currently, when I try to run the following:

import ccxt
from crypto.path_optimizer import PathOptimizer

path_optimizer = PathOptimizer(exchanges  = {'binance': ccxt.binance()})
path_optimizer.init_currency_info()
path_optimizer.find_arbitrage()

I get the following:

C:\Users\a\Desktop\crypto\crypto\path_optimizer.py:241: FutureWarning: Using a non-tuple sequence for multidi mensional indexing is deprecated; use arr[tuple(seq)] instead of arr[seq]. In the future this will be int erpreted as an array index, arr[np.array(seq)], which will result either in an error or a different result.

self.commission_matrix[np.meshgrid(indexes, indexes, indexing = 'ij', sparse = True)] = self.trading_fee[ex c_name] Traceback (most recent call last): File "C:/Users/a/Desktop/crypto/main.py", line 6, in path_optimizer.find_arbitrage() File "C:\Users\a\Desktop\crypto\crypto\path_optimizer.py", line 103, in find_arbitrage self.update_objectives() File "C:\Users\a\Desktop\crypto\crypto\path_optimizer.py", line 278, in update_objectives self.update_balance() File "C:\Users\a\Desktop\crypto\crypto\path_optimizer.py", line 221, in update_balance for i in list(exc_bal.keys()): AttributeError: 'NoneType' object has no attribute 'keys'

Process finished with exit code 1

OS: Win 10 Python: 3.7.4 x64 ccxt: 1.20.35 cplex: 12.9.0.0 docplex: 2.9.133 numpy: 1.17.4

hzjken commented 4 years ago

Hi @StnadardUsre , thank you for the question. This issue is not because of version, it should be the problem of not specifying your coin balance. The aim of the script is trying to be as practical as possible, so the arbitrage path will need to start from your real coin balance or your simulated coin balance.

To use simulated coin balance, you will need to specify the param simulated_bal in the initiation of pathOptimizer.

Like the following, to simulate your account coin balance. You can specify whatever amount and whatever coin type of your preference. simulated_bal = { 'kucoin': {'BTC': 10, 'ETH': 200, 'NEO': 1000, 'XRP': 30000, 'XLM': 80000}, 'binance': {'BTC': 10, 'ETH': 200, 'NEO': 1000, 'XRP': 30000, 'XLM': 80000}, 'bittrex': {'BTC': 10, 'ETH': 200, 'NEO': 1000, 'XRP': 30000, 'XLM': 80000}, }

Or to use your real coin balance, you will need to add in api key and secret key within the exchanges parameter, so that the script can connect to the account api and fetch your real account balance. If you do this, you don't need to specify simulated_bal parameter.

stdusr commented 4 years ago

Thanks for clarifying things out!