| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- from __future__ import annotations
- import collections
- import dataclasses
- import typing
- import cache
- from config import config
- import supply
- if typing.TYPE_CHECKING:
- import market
- def main() -> None:
- raw_prices: typing.Mapping[str, market.RawPrice] = {p['MaterialTicker']: p
- for p in cache.get('https://refined-prun.github.io/refined-prices/all.json') if p['ExchangeCode'] == 'IC1'}
- planets = [supply.Planet(fio_burn) for fio_burn in cache.get('https://rest.fnar.net/fioweb/burn/user/' + config.username,
- headers={'Authorization': config.fio_api_key})]
- buy: dict[str, int] = collections.defaultdict(int)
- for planet in planets:
- for mat, amount in planet.buy_for_target(7).items():
- buy[mat] += amount
- materials: list[Material] = []
- for mat, amount in buy.items():
- price = raw_prices[mat]
- if price['Bid'] is None or price['Ask'] is None:
- print(mat, 'has no bid/ask')
- continue
- spread = price['Ask'] - price['Bid']
- materials.append(Material(mat, amount=amount, spread=spread, total=spread * amount))
- materials.sort(reverse=True)
- print('mat amount total')
- for m in materials:
- print(f'{m.ticker:4} {m.amount:>6} {m.total:6.0f}')
- @dataclasses.dataclass(eq=False, slots=True)
- class Material:
- ticker: str
- amount: int
- spread: float
- total: float
- def __lt__(self, o: Material) -> bool:
- return self.total < o.total
- if __name__ == '__main__':
- main()
|