07.4.3.18.1 — Runtime Event Skeleton Architecture
This commit is contained in:
9
app/src/runtime_events/__init__.py
Normal file
9
app/src/runtime_events/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# app/src/runtime_events/__init__.py
|
||||
|
||||
from src.runtime_events.event_types import RuntimeEventType
|
||||
from src.runtime_events.models import RuntimeEvent
|
||||
|
||||
__all__ = [
|
||||
"RuntimeEvent",
|
||||
"RuntimeEventType",
|
||||
]
|
||||
17
app/src/runtime_events/event_types.py
Normal file
17
app/src/runtime_events/event_types.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# app/src/runtime_events/event_types.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class RuntimeEventType(str, Enum):
|
||||
AUTO_SIGNAL_READY = "auto_signal_ready"
|
||||
|
||||
POSITION_OPENED = "position_opened"
|
||||
POSITION_CLOSED = "position_closed"
|
||||
POSITION_FLIPPED = "position_flipped"
|
||||
|
||||
EXECUTION_BLOCKED = "execution_blocked"
|
||||
RISK_ALERT = "risk_alert"
|
||||
SYSTEM_ALERT = "system_alert"
|
||||
20
app/src/runtime_events/models.py
Normal file
20
app/src/runtime_events/models.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# app/src/runtime_events/models.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
from src.runtime_events.event_types import RuntimeEventType
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class RuntimeEvent:
|
||||
event_type: RuntimeEventType
|
||||
source: str
|
||||
title: str
|
||||
payload: dict[str, Any] = field(default_factory=dict)
|
||||
priority: str = "normal"
|
||||
dedupe_key: str | None = None
|
||||
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
||||
19
app/src/runtime_events/publisher.py
Normal file
19
app/src/runtime_events/publisher.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# app/src/runtime_events/publisher.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from src.notifications.service import NotificationService
|
||||
from src.runtime_events.models import RuntimeEvent
|
||||
|
||||
|
||||
class RuntimeEventPublisher:
|
||||
@classmethod
|
||||
def publish(cls, event: RuntimeEvent) -> None:
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
return
|
||||
|
||||
loop.create_task(NotificationService().handle_runtime_event(event))
|
||||
Reference in New Issue
Block a user