scrtlabs / catalyst

An Algorithmic Trading Library for Crypto-Assets in Python
http://enigma.co
Apache License 2.0
2.49k stars 725 forks source link

capital_base can't be covered using multiple currencies #362

Open STOpandthink opened 6 years ago

STOpandthink commented 6 years ago

I have a problem where I can't start my trader right now because it crashed after a buy trade. So my portfolio is 50% USD and 50% BTC. I want to start the trader that can trade that entire portfolio, not just the available cash (or available BTC).

STOpandthink commented 6 years ago

It occurs to me that probably this should be covered by algo_namespace. (The algorithm should remember the trade and count the asset towards capital_base.)

It's possible this is already being done. I'm running into a weird issue where I'm trying to run the same code on two different machines. On one everything works okay, but the other gives me this error: catalyst.exchange.exchange_errors.NotEnoughCashError: Total usd amount on bitfinex is lower than the cash reserved for this algo: 0.0 < 800.0. While trades can be made on the exchange accounts outside of the algo, exchange must have enough free usd to cover the algo cash.

I've tried clean-algo with no improvement. Are there files or state being stored locally on a machine aside from this?

STOpandthink commented 6 years ago

Just run into the NotEnoughCashError again. I have 900 USD in my account, my Enigma says I have zero. I tried catalyst clean-algo, but it doesn't help. It happened after I was changing quote_currency, but also when I went from paper trading to real trading. I'm not sure if either is related.

STOpandthink commented 6 years ago

One more piece of info: I just recently sold BTC to convert it to USD. So I'm hoping it's a caching issue and will resolve itself soon. Changing namespace to a new one didn't help, by the way.

STOpandthink commented 6 years ago

Oh wow, I tried running it in paper trading mode and it fails too. I don't even understand how that happens, given that in paper trading mode you're supposed to be able to set any amount AFAIK.

STOpandthink commented 6 years ago

Btw, here's the error stacktrace:

Traceback (most recent call last):
  File "correlation.py", line 570, in <module>
    run()
  File "correlation.py", line 567, in run
    run_algorithm(**algo_params)
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/utils/run_algo.py", line 601, in run_algorithm
    stats_output=stats_output
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/utils/run_algo.py", line 363, in _run
    overwrite_sim_params=False,
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 1050, in run
    data, overwrite_sim_params
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 358, in run
    data, overwrite_sim_params
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/algorithm.py", line 724, in run
    for perf in self.get_generator():
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/gens/tradesimulation.py", line 224, in transform
    for capital_change_packet in every_bar(dt):
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/gens/tradesimulation.py", line 137, in every_bar
    handle_data(algo, current_data, dt_to_use)
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/utils/events.py", line 216, in handle_data
    dt,
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/utils/events.py", line 235, in handle_data
    self.callback(context, data)
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 894, in handle_data
    cleanup=lambda: log.warn('Syncing portfolio again.')
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/redo/__init__.py", line 162, in retry
    return action(*args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 717, in synchronize_portfolio
    cash=required_cash,
  File "/home/ubuntu/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange.py", line 755, in sync_positions
    cash=cash,
catalyst.exchange.exchange_errors.NotEnoughCashError: Total usd amount on bittrex is lower than the cash reserved for this algo: 0.0 < 987.0. While trades can be made on the exchange accounts outside of the algo, exchange must have enough free usd to cover the algo cash.
STOpandthink commented 6 years ago

Ah, this was my mistake. My money was actually in USDT, not USD, so I had to specify usdt as quote_currency.

The only thing that's left is: It would still be nice to initialize portfolio using multiple currencies.