don't trigger events and state callbacks in strategy evaluation
This commit is contained in:
parent
95b1921f37
commit
a0c1a58d39
@ -138,13 +138,24 @@ class SymbolStatus:
|
|||||||
|
|
||||||
# Applies strategy and adds position to list
|
# Applies strategy and adds position to list
|
||||||
async def add_position(self, position: Position):
|
async def add_position(self, position: Position):
|
||||||
|
events = []
|
||||||
|
|
||||||
# if a strategy is defined then the strategy takes care of creating a PW for us
|
# if a strategy is defined then the strategy takes care of creating a PW for us
|
||||||
if not self.strategy:
|
if not self.strategy:
|
||||||
pw = PositionWrapper(position)
|
pw = PositionWrapper(position)
|
||||||
else:
|
else:
|
||||||
pw = await self.__apply_strategy_to_position__(position)
|
pw, events = await self.__apply_strategy_to_position__(position)
|
||||||
self.positions = __add_to_dict_list__(self.positions, self.current_tick, pw)
|
self.positions = __add_to_dict_list__(self.positions, self.current_tick, pw)
|
||||||
|
|
||||||
|
# triggering state callbacks
|
||||||
|
await self.__trigger_position_state_callbacks__(pw)
|
||||||
|
|
||||||
|
# triggering events callbacks
|
||||||
|
for e in events:
|
||||||
|
if not isinstance(e, Event):
|
||||||
|
raise ValueError
|
||||||
|
await self.add_event(e)
|
||||||
|
|
||||||
def all_prices(self) -> List[float]:
|
def all_prices(self) -> List[float]:
|
||||||
return list(map(lambda x: self.prices[x], range(1, self.current_tick + 1)))
|
return list(map(lambda x: self.prices[x], range(1, self.current_tick + 1)))
|
||||||
|
|
||||||
@ -173,10 +184,7 @@ class SymbolStatus:
|
|||||||
def set_tick_price(self, tick, price):
|
def set_tick_price(self, tick, price):
|
||||||
self.prices[tick] = price
|
self.prices[tick] = price
|
||||||
|
|
||||||
async def __apply_strategy_to_position__(self, position: Position):
|
async def __apply_strategy_to_position__(self, position: Position) -> Tuple[PositionWrapper, List[Event]]:
|
||||||
if not self.strategy:
|
|
||||||
return
|
|
||||||
|
|
||||||
pw, events = self.strategy.position_on_new_tick(position, self)
|
pw, events = self.strategy.position_on_new_tick(position, self)
|
||||||
|
|
||||||
if not isinstance(pw, PositionWrapper):
|
if not isinstance(pw, PositionWrapper):
|
||||||
@ -185,16 +193,7 @@ class SymbolStatus:
|
|||||||
if not isinstance(events, list):
|
if not isinstance(events, list):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
# triggering state callbacks
|
return pw, events
|
||||||
await self.__trigger_position_state_callbacks__(pw)
|
|
||||||
|
|
||||||
# triggering events callbacks
|
|
||||||
for e in events:
|
|
||||||
if not isinstance(e, Event):
|
|
||||||
raise ValueError
|
|
||||||
await self.add_event(e)
|
|
||||||
|
|
||||||
return pw
|
|
||||||
|
|
||||||
async def __trigger_position_state_callbacks__(self, pw: PositionWrapper):
|
async def __trigger_position_state_callbacks__(self, pw: PositionWrapper):
|
||||||
await self.eh.call_position_state(self, pw)
|
await self.eh.call_position_state(self, pw)
|
||||||
|
Loading…
Reference in New Issue
Block a user