Compare commits
4 Commits
571ad4e938
...
d635b6c4b9
Author | SHA1 | Date | |
---|---|---|---|
d635b6c4b9 | |||
999a3b597c | |||
e5c9edce5e | |||
aad7c9939e |
|
@ -3,6 +3,7 @@ on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||||
|
paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Package:
|
Package:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
name: Test Python
|
name: Test Python
|
||||||
on: [push]
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Test:
|
Test:
|
||||||
|
|
|
@ -16,11 +16,11 @@ Defined hierarchy:
|
||||||
- `Commodity`
|
- `Commodity`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import abc
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import abc
|
|
||||||
|
|
||||||
import enforce_typing
|
import enforce_typing
|
||||||
|
|
||||||
|
@ -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':
|
||||||
|
@ -176,6 +177,7 @@ class FiatCurrency(Currency):
|
||||||
def raw_short_name(self) -> str:
|
def raw_short_name(self) -> str:
|
||||||
return self.iso_code
|
return self.iso_code
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True, eq=True)
|
@dataclasses.dataclass(frozen=True, eq=True)
|
||||||
class CryptoCurrency(Currency):
|
class CryptoCurrency(Currency):
|
||||||
|
@ -192,6 +194,7 @@ class CryptoCurrency(Currency):
|
||||||
def raw_short_name(self) -> str:
|
def raw_short_name(self) -> str:
|
||||||
return self.ccxt_symbol
|
return self.ccxt_symbol
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True, eq=True)
|
@dataclasses.dataclass(frozen=True, eq=True)
|
||||||
class Stock(Asset):
|
class Stock(Asset):
|
||||||
|
@ -225,6 +228,7 @@ class Index(Asset):
|
||||||
def raw_short_name(self) -> str:
|
def raw_short_name(self) -> str:
|
||||||
return self.ticker
|
return self.ticker
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass(frozen=True, eq=True)
|
@dataclasses.dataclass(frozen=True, eq=True)
|
||||||
class Commodity(Asset):
|
class Commodity(Asset):
|
||||||
|
@ -478,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
|
||||||
|
@ -506,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,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.1.33'
|
__version__ = '0.1.34'
|
||||||
|
|
|
@ -2,11 +2,15 @@ import pytest
|
||||||
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
|
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
|
||||||
def test_to_from_string_id(asset: fin_defs.Asset):
|
def test_to_from_string_id(asset: fin_defs.Asset):
|
||||||
assert fin_defs.Asset.from_string_id(asset.to_string_id()) == asset
|
assert fin_defs.Asset.from_string_id(asset.to_string_id()) == asset
|
||||||
|
|
||||||
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
|
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
|
||||||
def test_to_from_polygon_id(asset: fin_defs.Asset):
|
def test_to_from_polygon_id(asset: fin_defs.Asset):
|
||||||
assert fin_defs.Asset.from_polygon_id(asset.to_polygon_id()) == asset
|
assert fin_defs.Asset.from_polygon_id(asset.to_polygon_id()) == asset
|
||||||
|
|
Loading…
Reference in New Issue
Block a user