/
fgtmenow
/
tb
Обзор
Документация
Войти
/
fgtmenow
/
tb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
bot/strategy/Example.py
74 строки
2 KB
Azarev Artem
Add project configuration and initial implementation of trading bot
17 янв 2026, 02:00
17 янв 2026, 02:00
5246123
Код
Авторство
О чём код?
from _common.domain.enums.Action import Action from _common.domain.enums.OrderType import OrderType from _common.domain.enums.Side import Side from _common.domain.model.OrderToPlace import OrderToPlace from _common.domain.util.Logger import print_messaged from _common.domain.util.ProfitCalc import calc_closed_pl from bot.strategy.base.BaseStrategy import BaseStrategy class Example(BaseStrategy): def __init__(self): super().__init__(self.__class__.__name__) self.was_loss: dict[str, bool] = {} self.level = 0.025 def check_entry(self, symbol: str) -> OrderToPlace | None: df_5m = self.model.data_5m[symbol] if self.model.data_length(symbol) < 2: return None if not self.model.check_ready(symbol): return None bar = self.model.get_bar(symbol) trend = df_5m.iloc[-1]['trend'] confirm = df_5m.iloc[-1]['confirm'] swing_point = df_5m.iloc[-1]['swing_point'] # get last HH and LL if trend == 1 and swing_point == 1: hh = df_5m.loc[df_5m.index[df_5m['swing_point'] == 1][-1], 'high'] ll = df_5m.loc[df_5m.index[df_5m['swing_point'] == -1][-1], 'low'] entry_price = ll + (hh - ll) * 32.8 / 100 target_price = ll + (hh - ll) * 132.8 / 100 print_messaged(bar.datetime(), f"hh:{hh} ll={ll}, entry={entry_price} target={target_price}") return OrderToPlace( type=OrderType.LIMIT, symbol=symbol, side=Side.LONG, size=0.001, entry_price=entry_price, leverage=20, strategy=self.name, target_price=None, stop_price=None ) return None def check_bar(self, symbol: str) -> Action: pos = self.store.broker.get_position(symbol) bar = self.model.get_bar(symbol) pl = calc_closed_pl( entry_commission_perc=pos.entry_commission, exit_commission_perc=self.store.broker.market_fee, funding_rate_perc=self.instrumentCache.get_funding_rate(symbol), side=pos.side, position_size=pos.size, entry_price=pos.entry_price, exit_price=bar.close, leverage=pos.leverage ) if pl > 0.18: return Action.CLOSE_POSITION return Action.NOTHING