cx_spend.py 785 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. import sys
  3. import typing
  4. import cache
  5. def main() -> None:
  6. cx = sys.argv[1]
  7. for spent_30d, ticker in sorted(items(cx), reverse=True):
  8. print(f'{ticker:4} {spent_30d:11,.0f}')
  9. def items(cx: str) -> typing.Iterator[tuple[float, str]]:
  10. raw_prices: list[RawPrice] = cache.get('https://refined-prun.github.io/refined-prices/all.json')
  11. for price in raw_prices:
  12. if price['ExchangeCode'] != cx:
  13. continue
  14. if (vwap_30d := price['VWAP30D']) is None or (traded_30d := price['Traded30D']) is None:
  15. continue
  16. spent_30d = vwap_30d * traded_30d
  17. yield spent_30d, price['MaterialTicker']
  18. class RawPrice(typing.TypedDict):
  19. MaterialTicker: str
  20. ExchangeCode: str
  21. VWAP30D: float | None
  22. Traded30D: float | None
  23. if __name__ == '__main__':
  24. main()