[+] improve emcont wrapper
This commit is contained in:
parent
eb32f27bad
commit
acd34f2ca5
54
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers_retrieval/emcont.py
vendored
54
deps/test-task-2025-06-30-v1/python/online/fxreader/pr34/test_task_2025_06_30_v1/tickers_retrieval/emcont.py
vendored
@ -1,14 +1,62 @@
|
||||
import aiohttp
|
||||
import decimal
|
||||
import pydantic
|
||||
import json
|
||||
|
||||
from typing import (Any,)
|
||||
from typing import (Any, Annotated, Optional,)
|
||||
|
||||
class Emcont:
|
||||
class rates_get_t:
|
||||
class data_t(pydantic.BaseModel):
|
||||
class rate_t(pydantic.BaseModel):
|
||||
symbol: Annotated[
|
||||
str,
|
||||
pydantic.Field(
|
||||
alias='Symbol',
|
||||
)
|
||||
]
|
||||
bid: Annotated[
|
||||
decimal.Decimal,
|
||||
pydantic.Field(
|
||||
alias='Bid',
|
||||
)
|
||||
]
|
||||
ask: Annotated[
|
||||
decimal.Decimal,
|
||||
pydantic.Field(
|
||||
alias='Ask',
|
||||
)
|
||||
]
|
||||
product_type: Annotated[
|
||||
str,
|
||||
pydantic.Field(
|
||||
alias='ProductType',
|
||||
)
|
||||
]
|
||||
rates: Annotated[
|
||||
list[rate_t],
|
||||
pydantic.Field(
|
||||
alias='Rates',
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
async def rates_get(
|
||||
cls,
|
||||
only_symbols: Optional[set[str]] = None,
|
||||
) -> Any:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get('https://rates.emcont.com') as response:
|
||||
data = await response.text()
|
||||
return json.loads(data[5:-3])
|
||||
data_json = await response.text()
|
||||
data = cls.rates_get_t.data_t.model_validate_json(
|
||||
data_json[5:-3],
|
||||
)
|
||||
|
||||
if only_symbols:
|
||||
data.rates = [
|
||||
o
|
||||
for o in data.rates
|
||||
if o.symbol in only_symbols
|
||||
]
|
||||
|
||||
return data
|
||||
|
Loading…
Reference in New Issue
Block a user