mirror of
https://github.com/d0zingcat/deploy.git
synced 2026-05-30 23:16:50 +00:00
(feat) update controllers
This commit is contained in:
@@ -2,9 +2,8 @@ from decimal import Decimal
|
||||
from typing import List, Optional
|
||||
|
||||
import pandas_ta as ta # noqa: F401
|
||||
from pydantic import Field, validator
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
from hummingbot.client.config.config_data_types import ClientFieldData
|
||||
from hummingbot.core.data_type.common import TradeType
|
||||
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
|
||||
from hummingbot.strategy_v2.controllers.market_making_controller_base import (
|
||||
@@ -25,38 +24,15 @@ class DManMakerV2Config(MarketMakingControllerConfigBase):
|
||||
# DCA configuration
|
||||
dca_spreads: List[Decimal] = Field(
|
||||
default="0.01,0.02,0.04,0.08",
|
||||
client_data=ClientFieldData(
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter a comma-separated list of spreads for each DCA level: "))
|
||||
json_schema_extra={"prompt": "Enter a comma-separated list of spreads for each DCA level: ", "prompt_on_new": True})
|
||||
dca_amounts: List[Decimal] = Field(
|
||||
default="0.1,0.2,0.4,0.8",
|
||||
client_data=ClientFieldData(
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter a comma-separated list of amounts for each DCA level: "))
|
||||
time_limit: int = Field(
|
||||
default=60 * 60 * 24 * 7, gt=0,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the time limit for each DCA level: ",
|
||||
prompt_on_new=False))
|
||||
stop_loss: Decimal = Field(
|
||||
default=Decimal("0.03"), gt=0,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the stop loss (as a decimal, e.g., 0.03 for 3%): ",
|
||||
prompt_on_new=True))
|
||||
top_executor_refresh_time: Optional[float] = Field(
|
||||
default=None,
|
||||
client_data=ClientFieldData(
|
||||
is_updatable=True,
|
||||
prompt_on_new=False))
|
||||
executor_activation_bounds: Optional[List[Decimal]] = Field(
|
||||
default=None,
|
||||
client_data=ClientFieldData(
|
||||
is_updatable=True,
|
||||
prompt=lambda mi: "Enter the activation bounds for the orders "
|
||||
"(e.g., 0.01 activates the next order when the price is closer than 1%): ",
|
||||
prompt_on_new=False))
|
||||
json_schema_extra={"prompt": "Enter a comma-separated list of amounts for each DCA level: ", "prompt_on_new": True})
|
||||
top_executor_refresh_time: Optional[float] = Field(default=None, json_schema_extra={"is_updatable": True})
|
||||
executor_activation_bounds: Optional[List[Decimal]] = Field(default=None, json_schema_extra={"is_updatable": True})
|
||||
|
||||
@validator("executor_activation_bounds", pre=True, always=True)
|
||||
@field_validator("executor_activation_bounds", mode="before")
|
||||
@classmethod
|
||||
def parse_activation_bounds(cls, v):
|
||||
if isinstance(v, list):
|
||||
return [Decimal(val) for val in v]
|
||||
@@ -66,8 +42,9 @@ class DManMakerV2Config(MarketMakingControllerConfigBase):
|
||||
return [Decimal(val) for val in v.split(",")]
|
||||
return v
|
||||
|
||||
@validator('dca_spreads', pre=True, always=True)
|
||||
def parse_spreads(cls, v):
|
||||
@field_validator('dca_spreads', mode="before")
|
||||
@classmethod
|
||||
def parse_dca_spreads(cls, v):
|
||||
if v is None:
|
||||
return []
|
||||
if isinstance(v, str):
|
||||
@@ -76,15 +53,16 @@ class DManMakerV2Config(MarketMakingControllerConfigBase):
|
||||
return [float(x.strip()) for x in v.split(',')]
|
||||
return v
|
||||
|
||||
@validator('dca_amounts', pre=True, always=True)
|
||||
def parse_and_validate_amounts(cls, v, values, field):
|
||||
@field_validator('dca_amounts', mode="before")
|
||||
@classmethod
|
||||
def parse_and_validate_dca_amounts(cls, v, validation_info):
|
||||
if v is None or v == "":
|
||||
return [1 for _ in values[values['dca_spreads']]]
|
||||
return [1 for _ in validation_info.data['dca_spreads']]
|
||||
if isinstance(v, str):
|
||||
return [float(x.strip()) for x in v.split(',')]
|
||||
elif isinstance(v, list) and len(v) != len(values['dca_spreads']):
|
||||
elif isinstance(v, list) and len(v) != len(validation_info.data['dca_spreads']):
|
||||
raise ValueError(
|
||||
f"The number of {field.name} must match the number of {values['dca_spreads']}.")
|
||||
f"The number of dca amounts must match the number of {validation_info.data['dca_spreads']}.")
|
||||
return v
|
||||
|
||||
|
||||
@@ -98,11 +76,11 @@ class DManMakerV2(MarketMakingControllerBase):
|
||||
def first_level_refresh_condition(self, executor):
|
||||
if self.config.top_executor_refresh_time is not None:
|
||||
if self.get_level_from_level_id(executor.custom_info["level_id"]) == 0:
|
||||
return self.market_data_provider.time() - executor.timestamp > self.config.top_executor_refresh_time * 1000
|
||||
return self.market_data_provider.time() - executor.timestamp > self.config.top_executor_refresh_time
|
||||
return False
|
||||
|
||||
def order_level_refresh_condition(self, executor):
|
||||
return self.market_data_provider.time() - executor.timestamp > self.config.executor_refresh_time * 1000
|
||||
return self.market_data_provider.time() - executor.timestamp > self.config.executor_refresh_time
|
||||
|
||||
def executors_to_refresh(self) -> List[ExecutorAction]:
|
||||
executors_to_refresh = self.filter_executors(
|
||||
|
||||
@@ -2,9 +2,9 @@ from decimal import Decimal
|
||||
from typing import List
|
||||
|
||||
import pandas_ta as ta # noqa: F401
|
||||
from pydantic import Field, validator
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic_core.core_schema import ValidationInfo
|
||||
|
||||
from hummingbot.client.config.config_data_types import ClientFieldData
|
||||
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
|
||||
from hummingbot.strategy_v2.controllers.market_making_controller_base import (
|
||||
MarketMakingControllerBase,
|
||||
@@ -14,69 +14,60 @@ from hummingbot.strategy_v2.executors.position_executor.data_types import Positi
|
||||
|
||||
|
||||
class PMMDynamicControllerConfig(MarketMakingControllerConfigBase):
|
||||
controller_name = "pmm_dynamic"
|
||||
controller_name: str = "pmm_dynamic"
|
||||
candles_config: List[CandlesConfig] = []
|
||||
buy_spreads: List[float] = Field(
|
||||
default="1,2,4",
|
||||
client_data=ClientFieldData(
|
||||
is_updatable=True,
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter a comma-separated list of buy spreads (e.g., '0.01, 0.02'):"))
|
||||
json_schema_extra={
|
||||
"prompt": "Enter a comma-separated list of buy spreads measured in units of volatility(e.g., '1, 2'): ",
|
||||
"prompt_on_new": True, "is_updatable": True}
|
||||
)
|
||||
sell_spreads: List[float] = Field(
|
||||
default="1,2,4",
|
||||
client_data=ClientFieldData(
|
||||
is_updatable=True,
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter a comma-separated list of sell spreads (e.g., '0.01, 0.02'):"))
|
||||
json_schema_extra={
|
||||
"prompt": "Enter a comma-separated list of sell spreads measured in units of volatility(e.g., '1, 2'): ",
|
||||
"prompt_on_new": True, "is_updatable": True}
|
||||
)
|
||||
candles_connector: str = Field(
|
||||
default=None,
|
||||
client_data=ClientFieldData(
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter the connector for the candles data, leave empty to use the same exchange as the connector: ", )
|
||||
)
|
||||
json_schema_extra={
|
||||
"prompt": "Enter the connector for the candles data, leave empty to use the same exchange as the connector: ",
|
||||
"prompt_on_new": True})
|
||||
candles_trading_pair: str = Field(
|
||||
default=None,
|
||||
client_data=ClientFieldData(
|
||||
prompt_on_new=True,
|
||||
prompt=lambda mi: "Enter the trading pair for the candles data, leave empty to use the same trading pair as the connector: ", )
|
||||
)
|
||||
json_schema_extra={
|
||||
"prompt": "Enter the trading pair for the candles data, leave empty to use the same trading pair as the connector: ",
|
||||
"prompt_on_new": True})
|
||||
interval: str = Field(
|
||||
default="3m",
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the candle interval (e.g., 1m, 5m, 1h, 1d): ",
|
||||
prompt_on_new=False))
|
||||
|
||||
json_schema_extra={
|
||||
"prompt": "Enter the candle interval (e.g., 1m, 5m, 1h, 1d): ",
|
||||
"prompt_on_new": True})
|
||||
macd_fast: int = Field(
|
||||
default=12,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the MACD fast length: ",
|
||||
prompt_on_new=True))
|
||||
default=21,
|
||||
json_schema_extra={"prompt": "Enter the MACD fast period: ", "prompt_on_new": True})
|
||||
macd_slow: int = Field(
|
||||
default=26,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the MACD slow length: ",
|
||||
prompt_on_new=True))
|
||||
default=42,
|
||||
json_schema_extra={"prompt": "Enter the MACD slow period: ", "prompt_on_new": True})
|
||||
macd_signal: int = Field(
|
||||
default=9,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the MACD signal length: ",
|
||||
prompt_on_new=True))
|
||||
json_schema_extra={"prompt": "Enter the MACD signal period: ", "prompt_on_new": True})
|
||||
natr_length: int = Field(
|
||||
default=14,
|
||||
client_data=ClientFieldData(
|
||||
prompt=lambda mi: "Enter the NATR length: ",
|
||||
prompt_on_new=True))
|
||||
json_schema_extra={"prompt": "Enter the NATR length: ", "prompt_on_new": True})
|
||||
|
||||
@validator("candles_connector", pre=True, always=True)
|
||||
def set_candles_connector(cls, v, values):
|
||||
@field_validator("candles_connector", mode="before")
|
||||
@classmethod
|
||||
def set_candles_connector(cls, v, validation_info: ValidationInfo):
|
||||
if v is None or v == "":
|
||||
return values.get("connector_name")
|
||||
return validation_info.data.get("connector_name")
|
||||
return v
|
||||
|
||||
@validator("candles_trading_pair", pre=True, always=True)
|
||||
def set_candles_trading_pair(cls, v, values):
|
||||
@field_validator("candles_trading_pair", mode="before")
|
||||
@classmethod
|
||||
def set_candles_trading_pair(cls, v, validation_info: ValidationInfo):
|
||||
if v is None or v == "":
|
||||
return values.get("trading_pair")
|
||||
return validation_info.data.get("trading_pair")
|
||||
return v
|
||||
|
||||
|
||||
@@ -87,7 +78,7 @@ class PMMDynamicController(MarketMakingControllerBase):
|
||||
"""
|
||||
def __init__(self, config: PMMDynamicControllerConfig, *args, **kwargs):
|
||||
self.config = config
|
||||
self.max_records = max(config.macd_slow, config.macd_fast, config.macd_signal, config.natr_length) + 200
|
||||
self.max_records = max(config.macd_slow, config.macd_fast, config.macd_signal, config.natr_length) + 100
|
||||
if len(self.config.candles_config) == 0:
|
||||
self.config.candles_config = [CandlesConfig(
|
||||
connector=config.candles_connector,
|
||||
|
||||
@@ -3,7 +3,6 @@ from typing import List
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from hummingbot.client.config.config_data_types import ClientFieldData
|
||||
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
|
||||
from hummingbot.strategy_v2.controllers.market_making_controller_base import (
|
||||
MarketMakingControllerBase,
|
||||
@@ -13,9 +12,9 @@ from hummingbot.strategy_v2.executors.position_executor.data_types import Positi
|
||||
|
||||
|
||||
class PMMSimpleConfig(MarketMakingControllerConfigBase):
|
||||
controller_name = "pmm_simple"
|
||||
controller_name: str = "pmm_simple"
|
||||
# As this controller is a simple version of the PMM, we are not using the candles feed
|
||||
candles_config: List[CandlesConfig] = Field(default=[], client_data=ClientFieldData(prompt_on_new=False))
|
||||
candles_config: List[CandlesConfig] = Field(default=[])
|
||||
|
||||
|
||||
class PMMSimpleController(MarketMakingControllerBase):
|
||||
|
||||
Reference in New Issue
Block a user