Stage 05.2 - interactive draft builder
This commit is contained in:
@@ -114,6 +114,53 @@ class ExchangeService:
|
||||
|
||||
return self._get_real_price(validation.normalized_symbol)
|
||||
|
||||
def get_market_snapshot(self, symbol: str | None = None) -> dict[str, object]:
|
||||
symbol_to_use = symbol or self.settings.default_symbol
|
||||
|
||||
if not self.settings.exchange_enabled:
|
||||
ticker = mock_ticker_price(symbol_to_use)
|
||||
return {
|
||||
"symbol": ticker.symbol,
|
||||
"last_price": ticker.price,
|
||||
"bid_price": ticker.price,
|
||||
"ask_price": ticker.price,
|
||||
"updated_at": ticker.updated_at,
|
||||
}
|
||||
|
||||
validation = self.validate_symbol(symbol_to_use)
|
||||
if not validation.is_valid:
|
||||
raise ExchangeError(validation.message)
|
||||
|
||||
client = ExchangeRestClient()
|
||||
payload = client.get_json(
|
||||
"/api/v2/ticker/24hr",
|
||||
params={"symbol": validation.normalized_symbol},
|
||||
)
|
||||
|
||||
last_raw = payload.get("lastPrice")
|
||||
if last_raw is None:
|
||||
raise ExchangeError("Field 'lastPrice' is missing in ticker response.")
|
||||
|
||||
bid_raw = payload.get("bidPrice") or last_raw
|
||||
ask_raw = payload.get("askPrice") or last_raw
|
||||
|
||||
close_time = payload.get("closeTime") or payload.get("eventTime") or ""
|
||||
|
||||
if close_time:
|
||||
dt_utc = datetime.fromtimestamp(int(close_time) / 1000, tz=ZoneInfo("UTC"))
|
||||
dt_local = dt_utc.astimezone(ZoneInfo(self.settings.tz))
|
||||
updated_at = dt_local.strftime("%d.%m.%Y %H:%M:%S")
|
||||
else:
|
||||
updated_at = "n/a"
|
||||
|
||||
return {
|
||||
"symbol": validation.normalized_symbol,
|
||||
"last_price": float(last_raw),
|
||||
"bid_price": float(bid_raw),
|
||||
"ask_price": float(ask_raw),
|
||||
"updated_at": updated_at,
|
||||
}
|
||||
|
||||
def get_balance_summary(self) -> list[BalanceSummary]:
|
||||
if not self.settings.exchange_enabled:
|
||||
return mock_balance_summary()
|
||||
|
||||
Reference in New Issue
Block a user