1
0

Compare commits

..

4 Commits

Author SHA1 Message Date
d635b6c4b9 🤖 Bumped version to 0.1.34
Some checks failed
Package Python / Package (push) Successful in 24s
Test Python / Test (push) Failing after 23s
This commit was automatically generated by a script: https://gitfub.space/Jmaa/python-omni
2024-08-25 19:16:23 +02:00
999a3b597c 🤖 Repository layout updated to latest version
This commit was automatically generated by a script: https://gitfub.space/Jmaa/python-omni
2024-08-25 19:16:12 +02:00
e5c9edce5e
Introduce AssetPair 2024-08-25 19:14:46 +02:00
aad7c9939e
Ruff 2024-08-09 16:56:28 +02:00
5 changed files with 23 additions and 7 deletions

View File

@ -3,6 +3,7 @@ on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"]
jobs:
Package:

View File

@ -1,5 +1,8 @@
name: Test Python
on: [push]
on:
push:
paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"]
jobs:
Test:

View File

@ -16,11 +16,11 @@ Defined hierarchy:
- `Commodity`
"""
import abc
import dataclasses
import datetime
import re
from decimal import Decimal
import abc
import enforce_typing
@ -124,7 +124,8 @@ class Asset:
if isinstance(self, Commodity):
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
def from_string_id(asset_id: str) -> 'Asset':
@ -176,6 +177,7 @@ class FiatCurrency(Currency):
def raw_short_name(self) -> str:
return self.iso_code
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
class CryptoCurrency(Currency):
@ -192,6 +194,7 @@ class CryptoCurrency(Currency):
def raw_short_name(self) -> str:
return self.ccxt_symbol
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
class Stock(Asset):
@ -225,6 +228,7 @@ class Index(Asset):
def raw_short_name(self) -> str:
return self.ticker
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
class Commodity(Asset):
@ -478,12 +482,15 @@ class AssetAmount:
return self.amount < other.amount
AssetPair = tuple[Asset, Asset]
@dataclasses.dataclass(frozen=True, eq=True)
class ExchangeRateSample(Asset):
class ExchangeRateSample:
"""Single exchange rate sample with a timestamp and various stats."""
timestamp: datetime.date | datetime.datetime
base_asset: Asset
asset_pair: AssetPair
_average: Decimal | None = None
last: Decimal | None = None
open: Decimal | None = None
@ -506,6 +513,7 @@ class ExchangeRateSample(Asset):
one = Decimal('1')
return dataclasses.replace(
self,
asset_pair=(self.asset_pair[1], self.asset_pair[0]),
_average=one / self._average if self._average else None,
last=one / self.last if self.last else None,
open=one / self.open if self.open else None,

View File

@ -1 +1 @@
__version__ = '0.1.33'
__version__ = '0.1.34'

View File

@ -2,11 +2,15 @@ import pytest
import fin_defs
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
def test_to_from_string_id(asset: fin_defs.Asset):
assert fin_defs.Asset.from_string_id(asset.to_string_id()) == asset
import fin_defs
@pytest.mark.parametrize('asset', fin_defs.WELL_KNOWN_SYMBOLS.values())
def test_to_from_polygon_id(asset: fin_defs.Asset):
assert fin_defs.Asset.from_polygon_id(asset.to_polygon_id()) == asset