From f7abca1e1b646d7c14d18589f52bf09eb81d497e Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Wed, 16 Jul 2025 12:21:18 +0300 Subject: [PATCH] [+] implment assets_index --- .../async_api/schema.py | 2 +- .../async_api/websocket_api.py | 20 +++++++++++++++++-- .../test_task_2025_06_30_v1/tickers/logic.py | 18 +++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/schema.py b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/schema.py index 35e90eb..fd0d50b 100644 --- a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/schema.py +++ b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/schema.py @@ -56,7 +56,7 @@ class AssetTickerResponse(pydantic.BaseModel): message: 'AssetHistoryResponse.message_t.point_t' class AssetsResponse(pydantic.BaseModel): - action: Literal['asset_history'] = 'asset_history' + action: Literal['assets'] = 'assets' class message_t(pydantic.BaseModel): class asset_t(pydantic.BaseModel): diff --git a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/websocket_api.py b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/websocket_api.py index a87ad0d..e7c53dd 100644 --- a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/websocket_api.py +++ b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/async_api/websocket_api.py @@ -3,7 +3,7 @@ import datetime from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import async_sessionmaker from . import schema -from ..tickers.logic import tickers_get_by_period +from ..tickers.logic import tickers_get_by_period, markets_all from typing import (Optional, Literal) @@ -81,7 +81,23 @@ class WebsocketAPI: self, client: fastapi.WebSocket, ) -> None: - raise NotImplementedError + markets = await markets_all( + self.session, + ) + + await client.send_text( + schema.AssetsResponse( + message=schema.AssetsResponse.message_t( + assets=[ + schema.AssetsResponse.message_t.asset_t.model_construct( + name=o.name, + id=o.id, + ) + for o in markets + ] + ) + ).json(by_alias=True,), + ) async def on_message( self, diff --git a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/logic.py b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/logic.py index d3d1189..164a4d8 100644 --- a/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/logic.py +++ b/deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers/logic.py @@ -63,3 +63,21 @@ async def tickers_get_by_period( make_transient(o.market) return rows + +async def markets_all( + session: 'async_sessionmaker[AsyncSession]', +) -> list[Market]: + async with session() as active_session: + async with active_session.begin() as transaction: + q = select( + Market + ) + + res = await active_session.execute(q) + + rows = [o[0] for o in res] + + for o in rows: + active_session.expunge(o) + + return rows