Add REST API with dashboard and configurable port (server.host/port, TM_PORT, --port)
This commit is contained in:
@@ -138,11 +138,30 @@ class TrainingConfig:
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ServerConfig:
|
||||
"""HTTP-API/Dashboard (Befehl `trademind serve`)."""
|
||||
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8080
|
||||
public_base_url: str = "" # optional, zB. Reverse-Proxy-URL für den Dashboard-Link
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, Any]) -> "ServerConfig":
|
||||
data = data or {}
|
||||
return cls(
|
||||
host=data.get("host", "0.0.0.0"),
|
||||
port=int(data.get("port", 8080)),
|
||||
public_base_url=data.get("public_base_url", "") or "",
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
trading: TradingConfig
|
||||
strategy: StrategyConfig
|
||||
training: TrainingConfig
|
||||
server: ServerConfig = field(default_factory=ServerConfig)
|
||||
exchanges: Dict[str, ExchangeConfig] = field(default_factory=dict)
|
||||
|
||||
def active_exchange(self) -> Optional[ExchangeConfig]:
|
||||
@@ -162,6 +181,7 @@ def load(path: str) -> Config:
|
||||
trading = TradingConfig.from_dict(raw.get("trading", {}))
|
||||
strategy = StrategyConfig.from_dict(raw.get("strategy", {}))
|
||||
training = TrainingConfig.from_dict(raw.get("training", {}))
|
||||
server = ServerConfig.from_dict(raw.get("server", {}))
|
||||
|
||||
exchanges: Dict[str, ExchangeConfig] = {}
|
||||
for name, data in (raw.get("exchanges") or {}).items():
|
||||
@@ -176,5 +196,6 @@ def load(path: str) -> Config:
|
||||
trading=trading,
|
||||
strategy=strategy,
|
||||
training=training,
|
||||
server=server,
|
||||
exchanges=exchanges,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user