from __future__ import annotations

import sys
import typing

import cache

def main() -> None:
	cx = sys.argv[1]
	for spent_30d, ticker in sorted(items(cx), reverse=True):
		print(f'{ticker:4} {spent_30d:11,.0f}')

def items(cx: str) -> typing.Iterator[tuple[float, str]]:
	raw_prices: list[RawPrice] = cache.get('https://refined-prun.github.io/refined-prices/all.json')
	for price in raw_prices:
		if price['ExchangeCode'] != cx:
			continue
		if (vwap_30d := price['VWAP30D']) is None or (traded_30d := price['Traded30D']) is None:
			continue
		spent_30d = vwap_30d * traded_30d
		yield spent_30d, price['MaterialTicker']

class RawPrice(typing.TypedDict):
	MaterialTicker: str
	ExchangeCode: str
	VWAP30D: float | None
	Traded30D: float | None

if __name__ == '__main__':
	main()
