Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Sep 19, 2024
1 parent 1a9101a commit 2d8e32e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion copilot/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from core.mixins import EventHandlerMixin
from core.models.risk_type import SessionRiskType, SignalRiskType
from core.models.side import PositionSide, SignalSide
from core.models.signal_risk import SignalRisk
from core.models.entity.signal_risk import SignalRisk
from core.models.strategy_type import StrategyType
from core.queries.copilot import EvaluateSession, EvaluateSignal

Expand Down
2 changes: 1 addition & 1 deletion core/actors/policy/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def should_process(cls, actor, event: NewMarketDataReceived) -> bool:
return (
event.symbol == actor.symbol
and event.timeframe == actor.timeframe
and event.closed
and event.bar.closed
)
9 changes: 3 additions & 6 deletions core/events/ohlcv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass, field

from core.models.entity.ohlcv import OHLCV
from core.models.entity.bar import Bar
from core.models.symbol import Symbol
from core.models.timeframe import Timeframe

Expand All @@ -19,17 +18,15 @@ class MarketEvent(Event):
class NewMarketDataReceived(MarketEvent):
symbol: Symbol
timeframe: Timeframe
ohlcv: OHLCV
closed: bool
bar: Bar

def to_dict(self):
parent_dict = super().to_dict()

current_dict = {
"symbol": str(self.symbol),
"timeframe": str(self.timeframe),
"ohlcv": self.ohlcv.to_dict(),
"closed": self.closed,
"bar": self.bar.to_dict(),
}

return {**parent_dict, **current_dict}
5 changes: 0 additions & 5 deletions core/events/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ class RiskEvent(Event):
@dataclass(frozen=True)
class RiskThresholdBreached(RiskEvent):
pass


@dataclass(frozen=True)
class RiskAdjustRequested(RiskEvent):
adjust_price: float
2 changes: 1 addition & 1 deletion feed/_historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def _handle_market(self, batch: List[Bar]) -> None:
for bar in batch:
await self.tell(
NewMarketDataReceived(
self.symbol, self.timeframe, bar.ohlcv, bar.closed
self.symbol, self.timeframe, bar
)
)
await asyncio.sleep(0.0001)
Expand Down
2 changes: 1 addition & 1 deletion feed/_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ async def _process_bars(self, bars: List[Bar]):

await self.tell(
NewMarketDataReceived(
self.symbol, self.timeframe, bar.ohlcv, bar.closed
self.symbol, self.timeframe, bar
)
)
7 changes: 4 additions & 3 deletions risk/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ async def _process_market(
self, event: NewMarketDataReceived, position: Optional[Position]
):
next_position = position
curr_bar = event.bar.ohlcv

if position and not position.has_risk:
prev_bar = next_position.risk_bar
next_bar = await self.ask(NextBar(self.symbol, self.timeframe, prev_bar))

next_bar = next_bar or event.ohlcv
next_bar = next_bar or curr_bar

attempts = 0
diff = event.ohlcv.timestamp - next_bar.timestamp
diff = curr_bar.timestamp - next_bar.timestamp

while diff < 0 and attempts < MAX_ATTEMPTS:
new_prev_bar = await self.ask(
Expand All @@ -168,7 +169,7 @@ async def _process_market(
attempts += 1

if new_prev_bar:
diff = event.ohlcv.timestamp - new_prev_bar.timestamp
diff = curr_bar.timestamp - new_prev_bar.timestamp
prev_bar = new_prev_bar

bars = [next_bar]
Expand Down
2 changes: 1 addition & 1 deletion strategy/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def pre_receive(self, event: NewMarketDataReceived):

async def on_receive(self, event: NewMarketDataReceived):
signal_event = self.strategy_ref.next(
self.symbol, self.timeframe, self.strategy, event.ohlcv
self.symbol, self.timeframe, self.strategy, event.bar.ohlcv
)

if signal_event:
Expand Down

0 comments on commit 2d8e32e

Please sign in to comment.