self.get_last_price¶
- strategies.strategy.Strategy.get_last_price(self, asset, quote=None)¶
Takes an asset and returns the last known price
Makes an active call to the market to retrieve the last price. In backtesting will provide the close of the last complete bar.
- Parameters
asset (Asset object) – Asset object for which the last closed price will be retrieved.
- Returns
Last closed price.
- Return type
Float
Example
>>> # Will return the last price for the asset >>> asset = "SPY" >>> last_price = self.get_last_price(asset) >>> self.log_message(f"Last price for {asset} is {last_price}")
>>> # Will return the last price for a crypto asset >>> base = Asset("BTC") >>> quote = Asset("USDT") >>> last_price = self.get_last_price(base, quote) >>> self.log_message(f"Last price for BTC/USDT is {last_price}")