implement response processing from xe
This commit is contained in:
parent
56c6bd7620
commit
0fdf765fef
1 changed files with 17 additions and 2 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
from money.currency import Currency
|
from money.currency import Currency, CurrencyHelper
|
||||||
from money.money import Money
|
from money.money import Money
|
||||||
from xecd_rates_client import XecdClient
|
from xecd_rates_client import XecdClient
|
||||||
|
|
||||||
|
|
@ -63,4 +64,18 @@ class XERateFetcher(RateFetcher):
|
||||||
# 1 unit of from_curr get us.
|
# 1 unit of from_curr get us.
|
||||||
)
|
)
|
||||||
|
|
||||||
# handle response into proper object
|
from_currency = Currency(response["from"])
|
||||||
|
to_currency = Currency(response["to"][0]["quotecurrency"])
|
||||||
|
rate_date = datetime.datetime.fromisoformat(
|
||||||
|
response["timestamp"].replace(
|
||||||
|
"Z", "+00:00"
|
||||||
|
) # Funny replace is necessary because of API response format
|
||||||
|
).date()
|
||||||
|
rate = f"""{response["to"][0]["mid"]:.{CurrencyHelper.decimal_precision_for_currency(to_currency)}f}"""
|
||||||
|
|
||||||
|
return ExchangeRate(
|
||||||
|
from_currency=from_currency,
|
||||||
|
to_currency=to_currency,
|
||||||
|
rate_date=rate_date,
|
||||||
|
rate=rate,
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue