I need to check if the current price is not to far from the level when the signal was generated. There could be big differences especially when trading on a higher time frame(30m, 1h, 1d).
So how I am supposed to retrieve and check the current bid/ask/last price in the strategy?
Currently the last tick price is not available to the strategy.
I made it work for the best bid and ask. It took me time to find out that the strategy has a DataProvider field, but after that was easy.
So I implemented the orderbook() method in /freqtrade/data/dataprovider.py as follows:
def orderbook(self, pair: str, max: int):
"""
return latest orderbook data
"""
return self._exchange.get_order_book(pair, max)
Then in the strategy whenever I need it (in my case in populate_buy_trend()) I do:
ob = self.dp.orderbook(metadata['pair'], 1)
top_bid = ob['bids'][0][0] # best bid
would you make a pull request with this enhancement?
Closing it as the pull request implementing the enhancements was successfully merged.
Most helpful comment
I made it work for the best bid and ask. It took me time to find out that the strategy has a DataProvider field, but after that was easy.
So I implemented the orderbook() method in /freqtrade/data/dataprovider.py as follows:
Then in the strategy whenever I need it (in my case in populate_buy_trend()) I do: