1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
4d2c694486
Added raw short name
Some checks failed
Test Python / Test (push) Failing after 27s
2024-08-08 18:07:34 +02:00
b1505fd54f 🤖 Repository layout updated to latest version
This commit was automatically generated by a script: https://gitfub.space/Jmaa/python-omni
2024-08-08 17:38:09 +02:00
2 changed files with 28 additions and 17 deletions

View File

@ -20,6 +20,7 @@ import dataclasses
import datetime
import re
from decimal import Decimal
import abc
import enforce_typing
@ -105,6 +106,11 @@ class Asset:
return FiatCurrency(polygon_id.removeprefix('C:').removesuffix('USD'))
return Stock.from_polygon_id(polygon_id)
@abc.abstractmethod
def raw_short_name(self) -> str:
"""A short name or ticker that does not nessisarily uniquely identify
the asset, but may be commonly used within the industry."""
def to_string_id(self) -> str:
"""Formats the asset id using the fin_defs asset format."""
if isinstance(self, Stock):
@ -167,6 +173,8 @@ class FiatCurrency(Currency):
msg = f'iso_code was not in correct format: {self.iso_code}'
raise ValueError(msg)
def raw_short_name(self) -> str:
return self.iso_code
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
@ -181,6 +189,9 @@ class CryptoCurrency(Currency):
raise ValueError(msg)
"""
def raw_short_name(self) -> str:
return self.ccxt_symbol
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
class Stock(Asset):
@ -197,6 +208,9 @@ class Stock(Asset):
def from_polygon_id(polygon_id: str, stock_exchange: StockExchange) -> 'Stock':
return Stock(polygon_id, stock_exchange)
def raw_short_name(self) -> str:
return self.ticker
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
@ -208,6 +222,8 @@ class Index(Asset):
msg = f'ticker was not in correct format: {self.ticker}'
raise ValueError(msg)
def raw_short_name(self) -> str:
return self.ticker
@enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True)
@ -219,6 +235,9 @@ class Commodity(Asset):
msg = f'alpha_vantage_id was not in correct format: {self.alpha_vantage_id}'
raise ValueError(msg)
def raw_short_name(self) -> str:
return self.alpha_vantage_id # TODO
Commodity.CRUDE_OIL_WTI = Commodity('WTI')
Commodity.CRUDE_OIL_BRENT = Commodity('BRENT')
@ -289,7 +308,7 @@ WELL_KNOWN_SYMBOLS = (
]
}
| {'XXBT': BTC}
| {str(k): k for k in COMMON_NAMES}
| {k.raw_short_name(): k for k in COMMON_NAMES}
| {'SPX500': SPX, 'SP500': SPX, 'Nasdaq 100': NDX}
)

View File

@ -45,20 +45,12 @@ with open(PACKAGE_NAME + '/_version.py') as f:
version = parse_version_file(f.read())
def parse_requirements(text: str) -> list[str]:
return text.strip().split('\n')
def read_requirements(path: str) -> list[str]:
with open(path) as f:
return parse_requirements(f.read())
REQUIREMENTS_MAIN = """
enforce-typing"""
REQUIREMENTS_TEST = """
pytest"""
REQUIREMENTS_MAIN = [
'enforce-typing',
]
REQUIREMENTS_TEST = [
'pytest',
]
setup(
@ -71,9 +63,9 @@ setup(
author_email='jonjmaa@gmail.com',
url='https://gitfub.space/Jmaa/' + PACKAGE_NAME,
packages=[PACKAGE_NAME],
install_requires=parse_requirements(REQUIREMENTS_MAIN),
install_requires=REQUIREMENTS_MAIN,
extras_require={
'test': parse_requirements(REQUIREMENTS_TEST),
'test': REQUIREMENTS_TEST,
},
python_requires='>=3.9',
)