From 25ca75704d40ecde216289d9e8c6c7bf173acdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Fri, 8 May 2026 03:26:19 +0900 Subject: [PATCH] Add CoinEx market data client --- app/coinex.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/coinex.py diff --git a/app/coinex.py b/app/coinex.py new file mode 100644 index 0000000..0cb3c2c --- /dev/null +++ b/app/coinex.py @@ -0,0 +1,25 @@ +from typing import Any +import httpx + + +class CoinExClient: + def __init__(self, api_base: str) -> None: + self.api_base = api_base.rstrip('/') + + async def get_kline(self, market: str, period: str = '1min', limit: int = 100) -> dict[str, Any]: + params = { + 'market': market.upper(), + 'period': period, + 'limit': max(1, min(limit, 1000)), + } + async with httpx.AsyncClient(timeout=10.0) as client: + response = await client.get(f'{self.api_base}/spot/kline', params=params) + response.raise_for_status() + return response.json() + + async def get_ticker(self, market: str) -> dict[str, Any]: + params = {'market': market.upper()} + async with httpx.AsyncClient(timeout=10.0) as client: + response = await client.get(f'{self.api_base}/spot/ticker', params=params) + response.raise_for_status() + return response.json()