Skip to content

Commit

Permalink
Merge pull request #24 from hummingbot/feat/clean_up_repo
Browse files Browse the repository at this point in the history
Feat/clean up repo
  • Loading branch information
nikspz authored Jul 18, 2024
2 parents 51b3ea3 + a719ae1 commit 5dd8d41
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 272 deletions.
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: detect-private-key

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.10.0
hooks:
- id: eslint
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]

- repo: https://github.com/CoinAlpha/git-hooks
rev: 78f0683233a09c68a072fd52740d32c0376d4f0f
hooks:
- id: detect-wallet-private-key
types: [file]
exclude: .json

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
files: "\\.(py)$"
args: [--settings-path=pyproject.toml]

- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ['flake8']
args: [--max-line-length=130]
17 changes: 3 additions & 14 deletions bots/controllers/directional_trading/bollinger_v1.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
from typing import List

import pandas_ta as ta # noqa: F401
from pydantic import Field, validator

from hummingbot.client.config.config_data_types import ClientFieldData
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import (
DirectionalTradingControllerBase,
DirectionalTradingControllerConfigBase,
)
from pydantic import Field, validator


class BollingerV1ControllerConfig(DirectionalTradingControllerConfigBase):
controller_name = "bollinger_v1"
candles_config: List[CandlesConfig] = []
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: ", )
)
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: ", )
)
candles_connector: str = Field(default=None)
candles_trading_pair: str = Field(default=None)
interval: str = Field(
default="3m",
client_data=ClientFieldData(
Expand Down
34 changes: 14 additions & 20 deletions bots/controllers/directional_trading/dman_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from typing import List, Optional, Tuple

import pandas_ta as ta # noqa: F401
from pydantic import 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
Expand All @@ -14,23 +12,14 @@
)
from hummingbot.strategy_v2.executors.dca_executor.data_types import DCAExecutorConfig, DCAMode
from hummingbot.strategy_v2.executors.position_executor.data_types import TrailingStop
from pydantic import Field, validator


class DManV3ControllerConfig(DirectionalTradingControllerConfigBase):
controller_name: str = "dman_v3"
candles_config: List[CandlesConfig] = []
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: ",)
)
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: ",)
)
candles_connector: str = Field(default=None)
candles_trading_pair: str = Field(default=None)
interval: str = Field(
default="30m",
client_data=ClientFieldData(
Expand Down Expand Up @@ -61,9 +50,10 @@ class DManV3ControllerConfig(DirectionalTradingControllerConfigBase):
dca_spreads: List[Decimal] = Field(
default="0.001,0.018,0.15,0.25",
client_data=ClientFieldData(
prompt=lambda mi: "Enter the spreads for each DCA level (comma-separated) if dynamic_spread=True this value "
"will multiply the Bollinger Bands width, e.g. if the Bollinger Bands width is 0.1 (10%)"
"and the spread is 0.2, the distance of the order to the current price will be 0.02 (2%) ",
prompt=lambda
mi: "Enter the spreads for each DCA level (comma-separated) if dynamic_spread=True this value "
"will multiply the Bollinger Bands width, e.g. if the Bollinger Bands width is 0.1 (10%)"
"and the spread is 0.2, the distance of the order to the current price will be 0.02 (2%) ",
prompt_on_new=True))
dca_amounts_pct: List[Decimal] = Field(
default=None,
Expand Down Expand Up @@ -119,7 +109,9 @@ def validate_amounts(cls, v, values):
return [Decimal('1.0') / len(spreads) for _ in spreads]
return v

def get_spreads_and_amounts_in_quote(self, trade_type: TradeType, total_amount_quote: Decimal) -> Tuple[List[Decimal], List[Decimal]]:
def get_spreads_and_amounts_in_quote(self,
trade_type: TradeType,
total_amount_quote: Decimal) -> Tuple[List[Decimal], List[Decimal]]:
amounts_pct = self.dca_amounts_pct
if amounts_pct is None:
# Equally distribute if amounts_pct is not set
Expand Down Expand Up @@ -151,6 +143,7 @@ class DManV3Controller(DirectionalTradingControllerBase):
Mean reversion strategy with Grid execution making use of Bollinger Bands indicator to make spreads dynamic
and shift the mid-price.
"""

def __init__(self, config: DManV3ControllerConfig, *args, **kwargs):
self.config = config
self.max_records = config.bb_length
Expand Down Expand Up @@ -201,8 +194,9 @@ def get_executor_config(self, trade_type: TradeType, price: Decimal, amount: Dec
prices = [price * (1 + spread * spread_multiplier) for spread in spread]
if self.config.dynamic_target:
stop_loss = self.config.stop_loss * spread_multiplier
trailing_stop = TrailingStop(activation_price=self.config.trailing_stop.activation_price * spread_multiplier,
trailing_delta=self.config.trailing_stop.trailing_delta * spread_multiplier)
trailing_stop = TrailingStop(
activation_price=self.config.trailing_stop.activation_price * spread_multiplier,
trailing_delta=self.config.trailing_stop.trailing_delta * spread_multiplier)
else:
stop_loss = self.config.stop_loss
trailing_stop = self.config.trailing_stop
Expand Down
17 changes: 3 additions & 14 deletions bots/controllers/directional_trading/macd_bb_v1.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
from typing import List

import pandas_ta as ta # noqa: F401
from pydantic import Field, validator

from hummingbot.client.config.config_data_types import ClientFieldData
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import (
DirectionalTradingControllerBase,
DirectionalTradingControllerConfigBase,
)
from pydantic import Field, validator


class MACDBBV1ControllerConfig(DirectionalTradingControllerConfigBase):
controller_name = "macd_bb_v1"
candles_config: List[CandlesConfig] = []
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: ", )
)
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: ", )
)
candles_connector: str = Field(default=None)
candles_trading_pair: str = Field(default=None)
interval: str = Field(
default="3m",
client_data=ClientFieldData(
Expand Down
28 changes: 17 additions & 11 deletions bots/controllers/directional_trading/supertrend_v1.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from typing import List, Optional

import pandas_ta as ta # noqa: F401
from pydantic import Field, validator

from hummingbot.client.config.config_data_types import ClientFieldData
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import (
DirectionalTradingControllerBase,
DirectionalTradingControllerConfigBase,
)
from pydantic import Field, validator


class SuperTrendConfig(DirectionalTradingControllerConfigBase):
controller_name: str = "supertrend_v1"
candles_config: List[CandlesConfig] = []
candles_connector: Optional[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: ", ))
candles_trading_pair: Optional[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: ", ))
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))
length: int = Field(default=20, client_data=ClientFieldData(prompt=lambda mi: "Enter the supertrend length: ", prompt_on_new=True))
multiplier: float = Field(default=4.0, client_data=ClientFieldData(prompt=lambda mi: "Enter the supertrend multiplier: ", prompt_on_new=True))
percentage_threshold: float = Field(default=0.01, client_data=ClientFieldData(prompt=lambda mi: "Enter the percentage threshold: ", prompt_on_new=True))
candles_connector: Optional[str] = Field(default=None)
candles_trading_pair: Optional[str] = Field(default=None)
interval: str = Field(default="3m")
length: int = Field(default=20, client_data=ClientFieldData(prompt=lambda mi: "Enter the supertrend length: ",
prompt_on_new=True))
multiplier: float = Field(default=4.0,
client_data=ClientFieldData(prompt=lambda mi: "Enter the supertrend multiplier: ",
prompt_on_new=True))
percentage_threshold: float = Field(default=0.01, client_data=ClientFieldData(
prompt=lambda mi: "Enter the percentage threshold: ", prompt_on_new=True))

@validator("candles_connector", pre=True, always=True)
def set_candles_connector(cls, v, values):
Expand Down Expand Up @@ -54,11 +57,14 @@ async def update_processed_data(self):
max_records=self.max_records)
# Add indicators
df.ta.supertrend(length=self.config.length, multiplier=self.config.multiplier, append=True)
df["percentage_distance"] = abs(df["close"] - df[f"SUPERT_{self.config.length}_{self.config.multiplier}"]) / df["close"]
df["percentage_distance"] = abs(df["close"] - df[f"SUPERT_{self.config.length}_{self.config.multiplier}"]) / df[
"close"]

# Generate long and short conditions
long_condition = (df[f"SUPERTd_{self.config.length}_{self.config.multiplier}"] == 1) & (df["percentage_distance"] < self.config.percentage_threshold)
short_condition = (df[f"SUPERTd_{self.config.length}_{self.config.multiplier}"] == -1) & (df["percentage_distance"] < self.config.percentage_threshold)
long_condition = (df[f"SUPERTd_{self.config.length}_{self.config.multiplier}"] == 1) & (
df["percentage_distance"] < self.config.percentage_threshold)
short_condition = (df[f"SUPERTd_{self.config.length}_{self.config.multiplier}"] == -1) & (
df["percentage_distance"] < self.config.percentage_threshold)

# Choose side
df['signal'] = 0
Expand Down
139 changes: 0 additions & 139 deletions bots/controllers/directional_trading/trend_simple_v1.py

This file was deleted.

Loading

0 comments on commit 5dd8d41

Please sign in to comment.