market.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import annotations
  2. import dataclasses
  3. import typing
  4. import cache
  5. def main() -> None:
  6. raw_prices: list[RawPrice] = cache.get('https://refined-prun.github.io/refined-prices/all.json')
  7. markets: list[Market] = []
  8. for price in raw_prices:
  9. if (traded := price['AverageTraded7D']) is None or traded < 100:
  10. continue
  11. if price['Bid'] is None or price['Ask'] is None:
  12. continue
  13. spread = (price['Ask'] - price['Bid']) / price['Ask']
  14. if spread < 0.15:
  15. continue
  16. markets.append(Market(price['FullTicker'], bid=price['Bid'], ask=price['Ask'], spread=spread, traded=traded))
  17. markets.sort(key=lambda m: (m.ask - m.bid) * m.traded, reverse=True)
  18. print(f'{"mat":^8} {"bid":^5} {"ask":^5} spread {"traded":^7} ')
  19. for market in markets:
  20. print(f'{market.full_ticker:>8} {market.bid:5} {market.ask:5} {market.spread*100: 5.0f}% {market.traded:7}')
  21. class RawPrice(typing.TypedDict):
  22. FullTicker: str
  23. Bid: float | None
  24. Ask: float | None
  25. AverageTraded7D: float | None # averaged daily traded volume over last 7 days
  26. @dataclasses.dataclass(eq=False, slots=True)
  27. class Market:
  28. full_ticker: str
  29. bid: float
  30. ask: float
  31. spread: float
  32. traded: float
  33. if __name__ == '__main__':
  34. main()