Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Botcamp/ Triple SMA | Concept AI Strategy Builder #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hummingbot/client/command/silly_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
TYPE_CHECKING,
)
from hummingbot.core.utils.async_utils import safe_ensure_future
from scripts.ai_helper_concept import AiHelperConcept

if TYPE_CHECKING:
from hummingbot.client.hummingbot_application import HummingbotApplication
Expand Down Expand Up @@ -36,6 +37,9 @@ def be_silly(self, # type: HummingbotApplication
elif command == "dennis":
safe_ensure_future(self.silly_dennis())
return True
elif command == "ai":
safe_ensure_future(self.proxyAiCommand(raw_command))
return True
else:
return False

Expand Down Expand Up @@ -213,3 +217,13 @@ def display_alert(self, custom_alert = None):
except Exception:
pass
return f"{alert}" + ("\n" * 18)

async def proxyAiCommand(self, # type: HummingbotApplication
raw_command: str):
self.app.log("")
self.app.log("thinking...")
self.app.log("")
self.app.log( "HUMMING AI: " + await AiHelperConcept.command_proxy(raw_command) )
self.app.log("")


28 changes: 24 additions & 4 deletions hummingbot/strategy/directional_strategy_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DirectionalStrategyBase(ScriptStrategyBase):
time_limit_order_type: OrderType = OrderType.MARKET
trailing_stop_activation_delta = 0.003
trailing_stop_trailing_delta = 0.001
cooldown_after_execution = 30

# Create the candles that we want to use and the thresholds for the indicators
candles: List[CandlesBase]
Expand All @@ -89,6 +90,15 @@ def is_perpetual(self):
"""
return "perpetual" in self.exchange

@property
def max_active_executors_condition(self):
return len(self.get_active_executors()) < self.max_executors

@property
def time_between_signals_condition(self):
seconds_since_last_signal = self.current_timestamp - self.get_timestamp_of_last_executor()
return seconds_since_last_signal > self.cooldown_after_execution

def get_csv_path(self) -> str:
today = datetime.datetime.today()
csv_path = data_path() + f"/{self.directional_strategy_name}_position_executors_{self.exchange}_{self.trading_pair}_{today.day:02d}-{today.month:02d}-{today.year}.csv"
Expand Down Expand Up @@ -119,22 +129,32 @@ def on_stop(self):
for candle in self.candles:
candle.stop()

def get_active_executors(self):
def get_active_executors(self) -> List[PositionExecutor]:
return [signal_executor for signal_executor in self.active_executors
if not signal_executor.is_closed]

def get_closed_executors(self) -> List[PositionExecutor]:
return [signal_executor for signal_executor in self.active_executors
if signal_executor.is_closed]

def get_timestamp_of_last_executor(self):
if len(self.stored_executors) > 0:
return self.stored_executors[-1].close_timestamp
else:
return 0

def on_tick(self):
self.clean_and_store_executors()
if self.is_perpetual:
self.check_and_set_leverage()
if len(self.get_active_executors()) < self.max_executors and self.all_candles_ready:
if self.max_active_executors_condition and self.all_candles_ready and self.time_between_signals_condition:
position_config = self.get_position_config()
if position_config:
signal_executor = PositionExecutor(
strategy=self,
position_config=position_config,
)
self.active_executors.append(signal_executor)
self.clean_and_store_executors()

def get_position_config(self):
signal = self.get_signal()
Expand Down Expand Up @@ -287,4 +307,4 @@ def close_open_positions(self):
position_action=PositionAction.CLOSE)

def market_data_extra_info(self):
return ["\n"]
return ["\n"]
Loading