Freqtrade: Retrieve bid/ask/last price in the strategy

Created on 24 May 2019  路  4Comments  路  Source: freqtrade/freqtrade

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?

Enhancement

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:

    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

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aak-dev picture aak-dev  路  4Comments

shusso picture shusso  路  4Comments

Dante2333 picture Dante2333  路  3Comments

psionyx2311 picture psionyx2311  路  3Comments

konstantin-doncov picture konstantin-doncov  路  4Comments