diff --git a/strategy.py b/strategy.py index edb61d0..deb7339 100644 --- a/strategy.py +++ b/strategy.py @@ -4,7 +4,7 @@ import sympy.abc from bfxapi import Position from sympy import Point, solve -from bfxbot.models import Strategy, PositionState, SymbolStatus, Event, EventKind, EventMetadata +from bfxbot.models import Strategy, PositionState, SymbolStatus, Event, EventKind, EventMetadata, PositionWrapper from bfxbot.utils import TAKER_FEE, net_pl_percentage @@ -42,12 +42,6 @@ class SquaredTrailingStop: return x - self.y(x) -class TrailingStopMetadata(EventMetadata): - def __init__(self, net_pl_percentage: float, **kwargs): - super(TrailingStopMetadata, self).__init__(**kwargs) - self.net_pl_percentage: float = net_pl_percentage - - class TrailingStopStrategy(Strategy): BREAK_EVEN_PERC = TAKER_FEE MIN_PROFIT_PERC = BREAK_EVEN_PERC + 0.3 @@ -62,7 +56,7 @@ class TrailingStopStrategy(Strategy): pl_perc = net_pl_percentage(position.profit_loss_percentage, TAKER_FEE) prev = ss.previous_pw(position.id) - event_metadata = TrailingStopMetadata(position_id=position.id, net_pl_percentage=pl_perc) + event_metadata = EventMetadata(position_id=position.id) if pl_perc > self.GOOD_PROFIT_PERC: state = PositionState.PROFIT @@ -75,8 +69,11 @@ class TrailingStopStrategy(Strategy): else: state = PositionState.CRITICAL - if not prev or prev.state == state: - return state, events + pw = PositionWrapper(position, state=state, net_profit_loss=position.profit_loss, + net_profit_loss_percentage=pl_perc) + + if not prev or prev.state() == state: + return pw, events if state == PositionState.PROFIT: events.append(Event(EventKind.REACHED_GOOD_PROFIT, ss.current_tick, event_metadata)) @@ -90,4 +87,4 @@ class TrailingStopStrategy(Strategy): events.append(Event(EventKind.REACHED_MAX_LOSS, ss.current_tick, event_metadata)) events.append(Event(EventKind.CLOSE_POSITION, ss.current_tick, event_metadata)) - return state, events + return pw, events