|
|
@@ -18,29 +18,29 @@ def main() -> None:
|
|
|
executor.submit(get_raw_prices),
|
|
|
executor.submit(get_total_buy), # what we need to buy
|
|
|
executor.submit(supply.warehouse_inventory), # what we have
|
|
|
+ executor.submit(get_planet_exports),
|
|
|
executor.submit(get_bids), # what we already are bidding for
|
|
|
]
|
|
|
- raw_prices, buy, warehouse, (bids, orders) = (f.result() for f in futures)
|
|
|
+ raw_prices, buy, warehouse, exports, (bids, orders) = (f.result() for f in futures)
|
|
|
executor.shutdown()
|
|
|
|
|
|
# what's left to buy
|
|
|
materials: list[Material] = []
|
|
|
for mat, amount in buy.items():
|
|
|
- remaining = amount - bids[mat] - warehouse.get(mat, 0)
|
|
|
- if remaining <= 0:
|
|
|
- continue
|
|
|
+ remaining = max(amount - bids[mat] - warehouse.get(mat, 0) - exports.get(mat, 0), 0)
|
|
|
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, bids=bids[mat], warehouse=warehouse.get(mat, 0),
|
|
|
+ materials.append(Material(mat, amount=amount, bids=bids[mat], have=warehouse.get(mat, 0) + exports.get(mat, 0),
|
|
|
spread=spread, savings=spread * remaining))
|
|
|
materials.sort(reverse=True)
|
|
|
|
|
|
print('mat want bids have buy savings')
|
|
|
for m in materials:
|
|
|
- print(f'{m.ticker:4} {m.amount:>5} {m.bids:>5} {m.warehouse:>5} {m.amount - m.bids - m.warehouse:>5} {m.savings:8.0f}')
|
|
|
+ buy = max(m.amount - m.bids - m.have, 0)
|
|
|
+ print(f'{m.ticker:4} {m.amount:>5} {m.bids:>5} {m.have:>5} {buy:>5} {m.savings:8.0f}')
|
|
|
|
|
|
# deposits of current bids
|
|
|
orders.sort(key=lambda order: order['Limit'] * order['Amount'], reverse=True)
|
|
|
@@ -61,6 +61,16 @@ def get_total_buy() -> typing.Mapping[str, int]:
|
|
|
buy[mat] += amount
|
|
|
return buy
|
|
|
|
|
|
+def get_planet_exports() -> typing.Mapping[str, int]:
|
|
|
+ fio_burn: typing.Sequence[supply.FIOBurn] = cache.get('https://rest.fnar.net/fioweb/burn/user/' + config.username,
|
|
|
+ headers={'Authorization': config.fio_api_key})
|
|
|
+ avail = collections.defaultdict(int)
|
|
|
+ for burn in fio_burn:
|
|
|
+ planet = supply.Planet(burn)
|
|
|
+ for mat in planet.exporting:
|
|
|
+ avail[mat] += planet.inventory.get(mat, 0)
|
|
|
+ return avail
|
|
|
+
|
|
|
def get_bids() -> tuple[typing.Mapping[str, int], list[market.ExchangeOrder]]:
|
|
|
orders: typing.Sequence[market.ExchangeOrder] = cache.get('https://rest.fnar.net/cxos/' + config.username,
|
|
|
headers={'Authorization': config.fio_api_key})
|
|
|
@@ -77,7 +87,7 @@ class Material:
|
|
|
ticker: str
|
|
|
amount: int
|
|
|
bids: int
|
|
|
- warehouse: int
|
|
|
+ have: int
|
|
|
spread: float
|
|
|
savings: float
|
|
|
|