Introduce AssetPair
This commit is contained in:
parent
aad7c9939e
commit
e5c9edce5e
|
@ -124,7 +124,8 @@ class Asset:
|
||||||
if isinstance(self, Commodity):
|
if isinstance(self, Commodity):
|
||||||
return f'commodity:{self.alpha_vantage_id}'
|
return f'commodity:{self.alpha_vantage_id}'
|
||||||
|
|
||||||
raise NotImplementedError('Unsupported asset type: ' + str(self))
|
msg = f'Unsupported asset type: {repr(self)}'
|
||||||
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_string_id(asset_id: str) -> 'Asset':
|
def from_string_id(asset_id: str) -> 'Asset':
|
||||||
|
@ -481,12 +482,15 @@ class AssetAmount:
|
||||||
return self.amount < other.amount
|
return self.amount < other.amount
|
||||||
|
|
||||||
|
|
||||||
|
AssetPair = tuple[Asset, Asset]
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, eq=True)
|
@dataclasses.dataclass(frozen=True, eq=True)
|
||||||
class ExchangeRateSample(Asset):
|
class ExchangeRateSample:
|
||||||
"""Single exchange rate sample with a timestamp and various stats."""
|
"""Single exchange rate sample with a timestamp and various stats."""
|
||||||
|
|
||||||
timestamp: datetime.date | datetime.datetime
|
timestamp: datetime.date | datetime.datetime
|
||||||
base_asset: Asset
|
asset_pair: AssetPair
|
||||||
_average: Decimal | None = None
|
_average: Decimal | None = None
|
||||||
last: Decimal | None = None
|
last: Decimal | None = None
|
||||||
open: Decimal | None = None
|
open: Decimal | None = None
|
||||||
|
@ -509,6 +513,7 @@ class ExchangeRateSample(Asset):
|
||||||
one = Decimal('1')
|
one = Decimal('1')
|
||||||
return dataclasses.replace(
|
return dataclasses.replace(
|
||||||
self,
|
self,
|
||||||
|
asset_pair=(self.asset_pair[1], self.asset_pair[0]),
|
||||||
_average=one / self._average if self._average else None,
|
_average=one / self._average if self._average else None,
|
||||||
last=one / self.last if self.last else None,
|
last=one / self.last if self.last else None,
|
||||||
open=one / self.open if self.open else None,
|
open=one / self.open if self.open else None,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user