# source: https://raw.githubusercontent.com/engmoeidh/crypto-dual-bot/a617ec3e4d835f6805b7d6777e1b84191489438c/swing_bot/strategy_swing.py
from freqtrade.strategy.interface import IStrategy
from common.features import build_feature_dict
from common.position_manager import PositionManager

class Github_engmoeidh_crypto_dual_bot__strategy_swing__20250613_164033(IStrategy):
    timeframe = "1h"
    minimal_roi = {"0": 0.02}
    stoploss = -0.02
    edge_manager = PositionManager({
        "edge_gap": 0.05,
        "decay": 0.02,
        "max_per_coin": 5,
        "kelly_size": 3,
        "prom_port": 8001
    })

    def populate_indicators(self, dataframe, metadata):
        return dataframe  # freqtrade needs this

    def populate_entry_trend(self, dataframe, metadata):
        # placeholder: random long if imbalance >0
        if dataframe.empty: return dataframe
        latest_depth = self.dp.current_depth(metadata["pair"])
        feats = build_feature_dict("BTC", latest_depth)
        if feats["qi"] > 0:
            cond = dataframe.index == dataframe.index[-1]
            dataframe.loc[cond, "enter_long"] = 1
        return dataframe

    def populate_exit_trend(self, dataframe, metadata):
        return dataframe  # exits managed by DPM
