Last active
January 4, 2025 16:18
-
-
Save Canx/71a554c8b0b8e9885ac27a507c3d5afa to your computer and use it in GitHub Desktop.
idea for improving adjust_trade_position function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def adjust_trade_position( | |
self, | |
trade: Trade, | |
current_time: datetime, | |
current_rate: float, | |
current_profit: float, | |
min_stake: Optional[float], | |
max_stake: float, | |
current_entry_rate: float, | |
current_exit_rate: float, | |
current_entry_profit: float, | |
current_exit_profit: float, | |
**kwargs, | |
): | |
if not self.position_adjustment_enable: | |
return None | |
enter_tag = getattr(trade, "enter_tag", "empty") | |
enter_tags = enter_tag.split() | |
# Map modes to adjustment functions | |
adjustment_map = { | |
"rebuy": self.long_rebuy_adjust_trade_position, | |
"grind": self.long_grind_adjust_trade_position, | |
"short_grind": self.short_grind_adjust_trade_position, | |
} | |
# Determine mode | |
mode = self.get_trade_mode(trade, enter_tags) | |
# Call the appropriate function if mode is found | |
if mode in adjustment_map: | |
return adjustment_map[mode]( | |
trade, | |
enter_tags, | |
current_time, | |
current_rate, | |
current_profit, | |
min_stake, | |
max_stake, | |
current_entry_rate, | |
current_exit_rate, | |
current_entry_profit, | |
current_exit_profit, | |
) | |
return None | |
def get_trade_mode(self, trade: Trade, enter_tags: list) -> str: | |
# Rebuy mode | |
if not trade.is_short and ( | |
all(c in self.long_rebuy_mode_tags for c in enter_tags) | |
or ( | |
any(c in self.long_rebuy_mode_tags for c in enter_tags) | |
and all(c in (self.long_rebuy_mode_tags + self.long_grind_mode_tags) for c in enter_tags) | |
) | |
): | |
return "rebuy" | |
# Grinding (long) | |
if not trade.is_short and any( | |
c in ( | |
self.long_normal_mode_tags | |
+ self.long_pump_mode_tags | |
+ self.long_quick_mode_tags | |
+ self.long_mode_tags | |
+ self.long_rapid_mode_tags | |
+ self.long_grind_mode_tags | |
+ self.long_top_coins_mode_tags | |
) | |
for c in enter_tags | |
): | |
return "grind" | |
# Grinding (short) | |
if trade.is_short and any( | |
c in ( | |
self.short_normal_mode_tags | |
+ self.short_pump_mode_tags | |
+ self.short_quick_mode_tags | |
+ self.short_mode_tags | |
+ self.short_rapid_mode_tags | |
+ self.short_grind_mode_tags | |
) | |
for c in enter_tags | |
): | |
return "short_grind" | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment