1
0

Added raw short name
Some checks failed
Test Python / Test (push) Failing after 27s

This commit is contained in:
Jon Michael Aanes 2024-08-08 18:07:34 +02:00
parent b1505fd54f
commit 4d2c694486
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

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}
)