hummingbot icon indicating copy to clipboard operation
hummingbot copied to clipboard

Use execution exchange not candles exchange for `get_close_price`

Open fengtality opened this issue 2 years ago • 1 comments

Feature Suggestion

get_close_price in ControllerBase uses the last candle from candles feed to fetch the price: https://github.com/hummingbot/hummingbot/blob/master/hummingbot/smart_components/strategy_frameworks/controller_base.py#L52C9-L52C9

However, since this is used to set spreads in MarketMakingController, I think it should use the get_mid_price function so that it uses the most up to date price data, similar to ScriptStrategyBase.

Also, if the user uses a different exchange for candles than execution, this function doesn't work since it looks for candles at self.config.exchange

Impact

More correct

Additional context

No response

fengtality avatar Nov 17 '23 04:11 fengtality

This issue affects directional strategies as well, since get_close_price is used. The error below occurs when kraken is the execution exchange.

KeyError: 'kraken_ETH-USDT'
2023-11-16 21:15:59,853 - 11534 - hummingbot.smart_components.strategy_frameworks.executor_handler_base - ERROR - 'kraken_ETH-USDT'
Traceback (most recent call last):
  File "/Users/feng/Code/hummingbot/hummingbot/smart_components/strategy_frameworks/executor_handler_base.py", line 108, in control_loop
    await self.control_task()
  File "/Users/feng/Code/hummingbot/hummingbot/smart_components/strategy_frameworks/directional_trading/directional_trading_executor_handler.py", line 43, in control_task
    position_config = self.controller.get_position_config(order_level, signal)
  File "/Users/feng/Code/hummingbot/hummingbot/smart_components/strategy_frameworks/directional_trading/directional_trading_controller_base.py", line 73, in get_position_config
    close_price = self.get_close_price(self.config.exchange, self.config.trading_pair)
  File "/Users/feng/Code/hummingbot/hummingbot/smart_components/strategy_frameworks/controller_base.py", line 58, in get_close_price
    candles = self.get_candles_by_connector_trading_pair(connector, trading_pair)
  File "/Users/feng/Code/hummingbot/hummingbot/smart_components/strategy_frameworks/controller_base.py", line 67, in get_candles_by_connector_trading_pair
    return self.get_candles_dict()[candle_name]
KeyError: 'kraken_ETH-USDT'
2023-11-16 21:15:59,967 - 11534 - hummingbot.client.hummingbot_application - INFO - stop command initiated.

fengtality avatar Nov 17 '23 05:11 fengtality