market.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. if (high := price['HighYesterday']) is None or (low := price['LowYesterday']) is None:
  14. continue
  15. if (high - low) / high < 0.1:
  16. continue
  17. spread = (price['Ask'] - price['Bid']) / price['Ask']
  18. if spread < 0.15:
  19. continue
  20. markets.append(Market(price['FullTicker'], bid=price['Bid'], ask=price['Ask'], spread=spread, traded=traded))
  21. markets.sort(key=lambda m: (m.ask - m.bid) * m.traded, reverse=True)
  22. print(f'{"mat":^8} {"bid":^5} {"ask":^5} spread {"traded":^7} ')
  23. for market in markets:
  24. print(f'{market.full_ticker:>8} {market.bid:5} {market.ask:5} {market.spread*100: 5.0f}% {market.traded:7}')
  25. class RawPrice(typing.TypedDict):
  26. FullTicker: str
  27. Bid: float | None
  28. Ask: float | None
  29. HighYesterday: float | None
  30. LowYesterday: float | None
  31. AverageTraded7D: float | None # averaged daily traded volume over last 7 days
  32. @dataclasses.dataclass(eq=False, slots=True)
  33. class Market:
  34. full_ticker: str
  35. bid: float
  36. ask: float
  37. spread: float
  38. traded: float
  39. if __name__ == '__main__':
  40. main()