Pridani stahovani kurzu a jednotneho API
- GET /{source_id} pro cnb, kb, csob, moneta, jt, mbank, ppf, trinity, fio, creditas
- jednotny tvar odpovedi s bezhotovostnimi kurzy za 1 jednotku meny
- parametr ?base pro ceny v jine mene nez CZK
- pole buy_sell_origin a middle_origin rikaji, co je stazene a co dopocitane
- pravidelne stahovani na pozadi, ukladani do JSON, priznak stale
- testy a dokumentace ve slozce documentation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""MONETA Money Bank: the JSON endpoint used by the bank's own rate list page."""
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from app.models import ParsedRates
|
||||
from app.sources.base import PRAGUE_ZONE, make_rate
|
||||
|
||||
# Prices are already per 1 unit even when multiplyFactor says 100, for example JPY is
|
||||
# 0.13245, so dividing by the factor would make the rate a hundred times too small.
|
||||
PRICE_AMOUNT = 1
|
||||
MILLISECONDS_PER_SECOND = 1000
|
||||
|
||||
|
||||
def parse(document: str) -> ParsedRates:
|
||||
items = json.loads(document)["responseObject"]["exchangeRates"]
|
||||
if not items:
|
||||
raise ValueError("Moneta rate list is empty")
|
||||
|
||||
# A discontinued currency stays in the list with its last date, for example BGN.
|
||||
latest = max(item["effectiveDate"] for item in items)
|
||||
rates = [
|
||||
# rateAccounting is an accounting rate, not a middle of these prices, so it is not used.
|
||||
make_rate(
|
||||
currency=item["symbol"],
|
||||
amount=PRICE_AMOUNT,
|
||||
buy=item["rateCashlessBuy"],
|
||||
sell=item["rateCashlessSell"],
|
||||
)
|
||||
for item in items
|
||||
if item["effectiveDate"] == latest and item["rateCashlessBuy"] and item["rateCashlessSell"]
|
||||
]
|
||||
|
||||
valid_from = datetime.fromtimestamp(latest / MILLISECONDS_PER_SECOND, PRAGUE_ZONE)
|
||||
return ParsedRates(valid_date=valid_from.date(), rates=rates)
|
||||
Reference in New Issue
Block a user