Добавил информацию по курсу рубля
This commit is contained in:
21
moex.py
21
moex.py
@@ -1,18 +1,25 @@
|
||||
import requests
|
||||
import xmltodict
|
||||
from cachetools import TTLCache
|
||||
|
||||
from session import session, MOEX_BASE_URL
|
||||
|
||||
BASE_URL: str = "https://iss.moex.com/iss"
|
||||
|
||||
session = requests.Session()
|
||||
|
||||
__cache: TTLCache = TTLCache(maxsize=10000, ttl=60 * 60)
|
||||
|
||||
|
||||
def bond_sequrities(bond_ticker: str, board: str) -> dict:
|
||||
res = requests.get(f"{BASE_URL}/engines/stock/markets/BONDS/boards/{board}/securities.xml?securities={bond_ticker}&iss.meta=off&iss.only=securities")
|
||||
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}
|
||||
|
||||
return xmltodict.parse(res.text)["document"]["data"]["rows"]["row"]
|
||||
data = xmltodict.parse(res.text)["document"]["data"]["rows"]["row"]
|
||||
data["@PREVPRICE_PERCENT"] = data.pop("@PREVPRICE")
|
||||
__cache[url] = data
|
||||
|
||||
return data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user