Stage 07.1 - auto trading skeleton UI, state machine and mock controls
This commit is contained in:
52
app/src/trading/auto/service.py
Normal file
52
app/src/trading/auto/service.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# app/src/trading/auto/service.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from src.core.config import load_settings
|
||||
from src.trading.auto.state import AutoTradeState
|
||||
|
||||
|
||||
class AutoTradeService:
|
||||
_state = AutoTradeState()
|
||||
|
||||
def get_state(self) -> AutoTradeState:
|
||||
if not self._state.symbol:
|
||||
self._state.symbol = load_settings().default_symbol
|
||||
|
||||
return self._state
|
||||
|
||||
def start(self) -> tuple[AutoTradeState, str]:
|
||||
state = self.get_state()
|
||||
|
||||
if state.status == "RUNNING":
|
||||
return state, "Автоторговля уже активна."
|
||||
|
||||
if state.status == "OBSERVING":
|
||||
state.status = "RUNNING"
|
||||
return state, "Автоторговля активирована."
|
||||
|
||||
state.status = "RUNNING"
|
||||
return state, "Автоторговля запущена."
|
||||
|
||||
def observe(self) -> tuple[AutoTradeState, str]:
|
||||
state = self.get_state()
|
||||
previous_status = state.status
|
||||
|
||||
if previous_status == "OBSERVING":
|
||||
return state, "Режим наблюдения уже включён."
|
||||
|
||||
state.status = "OBSERVING"
|
||||
|
||||
if previous_status == "OFF":
|
||||
return state, "Включён режим наблюдения."
|
||||
|
||||
return state, "Автоторговля переведена в режим наблюдения."
|
||||
|
||||
def stop(self) -> tuple[AutoTradeState, str]:
|
||||
state = self.get_state()
|
||||
|
||||
if state.status == "OFF":
|
||||
return state, "Автоторговля уже выключена."
|
||||
|
||||
state.status = "OFF"
|
||||
return state, "Автоторговля выключена."
|
||||
14
app/src/trading/auto/state.py
Normal file
14
app/src/trading/auto/state.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# app/src/trading/auto/state.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class AutoTradeState:
|
||||
status: str = "OFF"
|
||||
strategy: str | None = None
|
||||
symbol: str = ""
|
||||
risk_percent: float | None = None
|
||||
pnl_usd: float = 0.0
|
||||
Reference in New Issue
Block a user