Compare commits
No commits in common. "3a96b50b68e4365f42933cef857c0e80f1f59cca" and "d635b6c4b985a292e58c84f63515d2fbcee130fd" have entirely different histories.
3a96b50b68
...
d635b6c4b9
|
@ -258,7 +258,6 @@ Commodity.COFFEE = Commodity('COFFEE')
|
|||
DKK = FiatCurrency('DKK')
|
||||
USD = FiatCurrency('USD')
|
||||
EUR = FiatCurrency('EUR')
|
||||
GBP = FiatCurrency('GBP')
|
||||
BTC = CryptoCurrency('BTC', coingecko_id='bitcoin')
|
||||
MPC = CryptoCurrency('MPC', coingecko_id='partisia-blockchain')
|
||||
SPX = Index('SPX')
|
||||
|
@ -317,13 +316,6 @@ WELL_KNOWN_SYMBOLS = (
|
|||
| {'SPX500': SPX, 'SP500': SPX, 'Nasdaq 100': NDX}
|
||||
)
|
||||
|
||||
ASSET_PREFIX: dict[Asset, str] = {
|
||||
USD: '$',
|
||||
EUR: '€',
|
||||
GBP: '£',
|
||||
BTC: '₿',
|
||||
}
|
||||
|
||||
NYSE = StockExchange(
|
||||
name='New York Stock Exchange',
|
||||
mic='XNYS',
|
||||
|
@ -438,14 +430,8 @@ class AssetAmount:
|
|||
amount: Decimal
|
||||
|
||||
def __str__(self):
|
||||
return self.human_readable_str()
|
||||
|
||||
def human_readable_str(self):
|
||||
specificity = '2' if self.amount >= 0.10 else '3'
|
||||
prefix = ASSET_PREFIX.get(self.asset, '')
|
||||
return ('{}{:.' + specificity + 'f} {}').format(
|
||||
prefix, self.amount, self.asset.raw_short_name()
|
||||
)
|
||||
return ('{:.' + specificity + 'f} {}').format(self.amount, self.asset)
|
||||
|
||||
def __mul__(self, other: Decimal):
|
||||
if not isinstance(other, Decimal):
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = '0.1.35'
|
||||
__version__ = '0.1.34'
|
||||
|
|
|
@ -7,7 +7,6 @@ lint.ignore = [
|
|||
'Q003', 'D205', # Format conflict
|
||||
|
||||
'TCH', # Microoptimization at the cost of readability
|
||||
'TID252', # I like relative imports
|
||||
|
||||
'D407', 'D413', # Weird documentation stuff
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
from decimal import Decimal
|
||||
|
||||
import fin_defs
|
||||
|
||||
|
||||
def test_str():
|
||||
amount = fin_defs.AssetAmount(fin_defs.USD, Decimal(10))
|
||||
assert str(amount) == '$10.00 USD'
|
|
@ -2,18 +2,15 @@ import pytest
|
|||
|
||||
import fin_defs
|
||||
|
||||
VALID_TICKERS = ['TEST123', '123', 'TEST.EUR']
|
||||
BAD_TICKERS = ['TEST:EUR', 'EUR:TEST']
|
||||
BAD_TICKERS = ['TEST123', '123', 'TEST.EUR', 'TEST:EUR', 'EUR:TEST']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ticker', VALID_TICKERS)
|
||||
def test_valid_tickers(ticker: str):
|
||||
fin_defs.Stock(ticker,exchange=fin_defs.EXCHANGES_BY_IDS['NYSE'])
|
||||
|
||||
@pytest.mark.parametrize('ticker', BAD_TICKERS)
|
||||
def test_bad_tickers(ticker: str):
|
||||
with pytest.raises(ValueError):
|
||||
fin_defs.Stock(ticker,exchange=fin_defs.EXCHANGES_BY_IDS['NYSE'])
|
||||
def test_bad_tickers(ticker):
|
||||
try:
|
||||
fin_defs.Stock(ticker)
|
||||
except Exception as e:
|
||||
assert e
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ticker', BAD_TICKERS)
|
||||
|
@ -23,4 +20,4 @@ def test_crypto_tickers(ticker):
|
|||
|
||||
def test_str():
|
||||
NVO = fin_defs.Stock('NVO', fin_defs.EXCHANGES_BY_IDS['NYSE'])
|
||||
assert str(NVO) == 'stock:NVO.XNYS'
|
||||
assert str(NVO) == 'NVO.XNYS'
|
||||
|
|
|
@ -8,6 +8,9 @@ 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user