2024-10-27 16:24:12 +00:00
|
|
|
import datetime
|
|
|
|
from decimal import Decimal
|
2024-10-27 16:24:26 +00:00
|
|
|
|
2024-10-27 16:24:12 +00:00
|
|
|
import fin_defs
|
|
|
|
|
2024-10-27 16:26:03 +00:00
|
|
|
NOW = datetime.datetime.now(tz=datetime.UTC)
|
2024-10-27 16:24:12 +00:00
|
|
|
THEN = NOW - datetime.timedelta(days=1)
|
|
|
|
|
2024-10-27 16:24:26 +00:00
|
|
|
SAMPLE_AVERAGE = fin_defs.ExchangeRateSample(
|
2024-10-27 16:26:03 +00:00
|
|
|
NOW,
|
|
|
|
(fin_defs.FiatCurrency.DKK, fin_defs.FiatCurrency.USD),
|
|
|
|
_average=Decimal(1),
|
2024-10-27 16:24:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
SAMPLE_HIGH_LOW = fin_defs.ExchangeRateSample(
|
|
|
|
NOW,
|
|
|
|
(fin_defs.FiatCurrency.DKK, fin_defs.FiatCurrency.USD),
|
|
|
|
high=Decimal(1),
|
|
|
|
low=Decimal('0.5'),
|
|
|
|
)
|
2024-10-27 16:24:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_sample_average():
|
|
|
|
assert SAMPLE_AVERAGE.average == 1
|
|
|
|
assert SAMPLE_HIGH_LOW.average == Decimal('0.75')
|
|
|
|
|
|
|
|
|
|
|
|
def test_invert_sample():
|
|
|
|
inverted = SAMPLE_HIGH_LOW.invert_exchange_rate()
|
2024-10-27 16:24:26 +00:00
|
|
|
assert inverted.asset_pair == (fin_defs.FiatCurrency.USD, fin_defs.FiatCurrency.DKK)
|
2024-10-27 16:24:12 +00:00
|
|
|
assert inverted.high == 2
|
|
|
|
assert inverted.low == 1
|
|
|
|
assert inverted.average == 1.5
|
|
|
|
|
|
|
|
|
|
|
|
def test_replace_timestamp():
|
|
|
|
assert SAMPLE_HIGH_LOW.replace_timestamp(THEN).timestamp == THEN
|