26 lines
729 B
Python
26 lines
729 B
Python
import xmltodict
|
|
from cachetools import TTLCache
|
|
|
|
from session import session, MOEX_BASE_URL
|
|
|
|
__cache: TTLCache = TTLCache(maxsize=10000, ttl=60 * 60)
|
|
|
|
|
|
def bond_sequrities(bond_ticker: str, board: str) -> dict:
|
|
url: str = f"{MOEX_BASE_URL}/engines/stock/markets/BONDS/boards/{board}/securities.xml?securities={bond_ticker}&iss.meta=off&iss.only=securities"
|
|
|
|
if url in __cache:
|
|
return __cache[url]
|
|
|
|
res = session.get(url)
|
|
|
|
if res.status_code != 200:
|
|
return {"error": True, "status_code": res.status_code}
|
|
|
|
data = xmltodict.parse(res.text)["document"]["data"]["rows"]["row"]
|
|
data["@PREVPRICE_PERCENT"] = data.pop("@PREVPRICE")
|
|
__cache[url] = data
|
|
|
|
return data
|
|
|