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

Error: local variable 'trade_id' referenced before assignment #17

Open hubuser3976 opened 3 years ago

hubuser3976 commented 3 years ago

I get the following runtime error

crypto-arbitrage-framework/crypto/trade_execution.py", line 158, in kucoin_transfer_to to_id = trade_id UnboundLocalError: local variable 'trade_id' referenced before assignment

Anyone able to suggest a fix? The offending loop is:-

@staticmethod def kucoin_transfer_to(to, exchange, amount, code): '''function to transfer amount between main and trading account in kucoin''' accounts = exchange.privateGetAccounts() data = accounts['data'] for i in data: if i['currency'] == code and i['type'] == 'main': main_id = i['id'] elif i['currency'] == code and i['type'] == 'trade': <============(Problem is here, needs an additional elif to check for zero trade balance) trade_id = i['id'] else: pass

    if to == 'main':
        from_id, to_id = trade_id, main_id
    elif to == 'trade': 
        from_id, to_id = main_id, trade_id      <=======(ERROR thrown here)
    else:
        raise ValueError('to should be main or trade')