Closed gaardiolor closed 2 years ago
Using the exchange in an interactive environment is unfortunately not supported due to limitations in jupyter notebooks (related to how asyncio works in combination with notebooks).
This will implicitly (and unfortunately) also limit which strategies can be used in the notebook environment.
While there's workarounds - i'd not really trust these to "really" work reliably - as they do some shady patching of python internals.
I'm working on a long-term solution to that (not explicitly for this - but it'll solve this implicitly) - but that'll still take a some time to be fully ready.
Using notebooks works fine if you fulfil all the objects needed, including the workaround for asyncio:
...
## somewhere after the main imports but before the main notebook code
import nest_asyncio
nest_asyncio.apply()
...
ft_config['strategy'] = strat_name
ft_config['timeframe'] = timeframe
ft_config['timeframe_detail'] = timeframe_detail ## if required
ft_config['datadir'] = data_location
ft_exchange = ExchangeResolver.load_exchange(ft_config['exchange']['name'], config=ft_config, validate=True)
ft_pairlists = PairListManager(ft_exchange, ft_config)
ft_dataprovider = DataProvider(ft_config, ft_exchange, ft_pairlists)
# Load strategy using values set above
strategy = StrategyResolver.load_strategy(ft_config)
strategy.dp = ft_dataprovider
Taken from my notebook example at https://github.com/froggleston/cryptofrog-strategies/blob/informatives/live_plotting.ipynb which is old, but the main functionality should still be relevant.
Edit: However xmatthias is correct - this isn't a supported environment so YMMV.
Thanks! I'll test this with @froggleston 's tips in Jupyter, and outside Jupyter. I'll update this issue with my findings.
To initialize the exchange, nest_asyncio.apply()
will suffice (i think you've had most of the other code more or less correct).
This is however patching python internals - and is not a supported method to use this.
Without looking at that code, and carefully reviewing what exactly it's patching, it could also cause misalignment with instances where it's used without this patch.
You're obviously free to use this workaround - just be warned that it's untested, and may lead to differences elsewhere.
Yes, it's working now. The missing nest_asyncio.apply()
was the main thing, after which I was able to get it to work. Thanks!
as said above - pay close attention to results - and in case of differences to other modes, assume it could maybe also be caused by this.
Describe your environment
Describe the problem:
I am trying to analyze my strategy, following https://www.freqtrade.io/en/stable/strategy_analysis_example/ . However, I'm getting an error.
Steps to reproduce:
My code:
Candles are printed, so this works.
This gives an error:
I have also tried (found on discord):
This gives another error:
Observed Results:
What happened? See above
What did you expect to happen? No error.
Relevant code exceptions or logs
See above. Any tips.. ? Thanks!