Przeglądaj źródła

market: show CXOS for items waiting to be flipped

raylu 3 tygodni temu
rodzic
commit
a014c9d266
1 zmienionych plików z 23 dodań i 0 usunięć
  1. 23 0
      market.py

+ 23 - 0
market.py

@@ -51,8 +51,17 @@ def main() -> None:
 		print()
 
 def check_warehouses() -> None:
+	orders: typing.Sequence[ExchangeOrder] = cache.get('https://rest.fnar.net/cxos/' + config.username,
+			headers={'Authorization': config.fio_rest_key})
+	trades: dict[str, list] = collections.defaultdict(list)
+	for order in orders:
+		if order['OrderType'] != 'BUYING' or order['Status'] == 'PLACED' or order['ExchangeCode'] != 'IC1':
+			continue
+		trades[order['MaterialTicker']].extend(order['Trades'])
+
 	warehouses: typing.Sequence[Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
 			headers={'Authorization': config.fio_rest_key})
+	now = datetime.datetime.now(datetime.UTC)
 	for warehouse in warehouses:
 		storage: Storage = cache.get(f'https://rest.fnar.net/storage/{config.username}/{warehouse["StoreId"]}',
 			headers={'Authorization': config.fio_rest_key})
@@ -62,6 +71,13 @@ def check_warehouses() -> None:
 			threshold = config.market.mm_items.get(item['MaterialTicker'])
 			if threshold is not None and item['MaterialAmount'] > threshold:
 				print(f'{item["MaterialAmount"] - threshold} {item["MaterialTicker"]} at {warehouse["LocationNaturalId"]}')
+				mat_trades = trades.get(item['MaterialTicker'], [])
+				mat_trades.sort(key=lambda t: t['TradeTimeEpochMs'], reverse=True)
+				for trade in mat_trades:
+					dt = datetime.datetime.fromtimestamp(trade["TradeTimeEpochMs"] // 1000, datetime.UTC)
+					if now - dt > datetime.timedelta(days=7):
+						break
+					print(f'  {dt} {trade["PartnerName"]} {trade["Amount"]} @ {trade["Price"]}')
 
 def analyze_markets(raw_prices: typing.Sequence[RawPrice]) -> typing.Iterator[MarketHealth]:
 	'''score IC1 based on how much better the other CXes are'''
@@ -192,6 +208,13 @@ class ExchangeOrder(typing.TypedDict):
 	Status: typing.Literal['FILLED', 'PARTIALLY_FILLED']
 	Amount: int
 	Limit: float
+	Trades: typing.Sequence[ExchangeTrade]
+
+class ExchangeTrade(typing.TypedDict):
+	TradeTimeEpochMs: int
+	Amount: int
+	Price: float
+	PartnerName: str
 
 class ExchangeSummary(typing.TypedDict):
 	MaterialTicker: str