Browse Source

sell: show instant cash and total loss

also show other listings that aren't in production
raylu 2 days ago
parent
commit
6b1a9d8a38
1 changed files with 22 additions and 7 deletions
  1. 22 7
      sell.py

+ 22 - 7
sell.py

@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+import collections
 import dataclasses
 import typing
 
@@ -18,7 +19,7 @@ def main() -> None:
 			headers={'Authorization': config.fio_api_key})
 	producing = frozenset(mat['MaterialTicker'] for planet in planets for mat in planet['OrderProduction']
 			if mat['MaterialTicker'] not in (c['MaterialTicker'] for c in planet['OrderConsumption']))
-	materials = []
+	materials: list[Material] = []
 	for mat in producing:
 		price = raw_prices[mat]
 		if price['Bid'] is None or price['Ask'] is None:
@@ -27,20 +28,34 @@ def main() -> None:
 		spread = (price['Ask'] - price['Bid']) / price['Ask']
 		chart_analysis = market.analyze_price_chart(mat + '.IC1', (price['Bid'] + price['Ask']) / 2)
 		ask_fill_ratio = chart_analysis.asks_filled / (chart_analysis.bids_filled + chart_analysis.asks_filled)
-		materials.append(Material(mat, spread=spread, bids_filled=chart_analysis.bids_filled,
-				asks_filled=chart_analysis.asks_filled, score=spread * ask_fill_ratio))
+		materials.append(Material(mat, spread=spread, bid=price['Bid'], ask=price['Ask'], score=spread * ask_fill_ratio))
 	materials.sort()
 
-	print(f'{"mat":^4} spread  bids filled  asks filled')
+	all_orders: typing.Sequence[market.ExchangeOrder] = cache.get('https://rest.fnar.net/cxos/' + config.username,
+			headers={'Authorization': config.fio_api_key})
+	orders: dict[str, int] = collections.defaultdict(int)
+	for order in all_orders:
+		if order['OrderType'] != 'SELLING' or order['Status'] == 'FILLED' or order['ExchangeCode'] != 'IC1':
+			continue
+		orders[order['MaterialTicker']] += order['Amount']
+
+	print(f'{"mat":^4} spread  asks  instant cash  loss')
 	for m in materials:
-		print(f'{m.ticker:4} {m.spread*100:5.1f}% {m.bids_filled:12.0f} {m.asks_filled:12.0f}')
+		print(f'{m.ticker:4} {m.spread*100:5.1f}%', end='')
+		if asks := orders.pop(m.ticker, None):
+			print(f' {asks:5} {asks * m.bid:13} {asks * (m.ask - m.bid):5}')
+		else:
+			print()
+	print('\nother listings:')
+	for mat, asks in orders.items():
+		print(f'{mat:4} {asks:5}')
 
 @dataclasses.dataclass(eq=False, slots=True)
 class Material:
 	ticker: str
 	spread: float
-	bids_filled: float
-	asks_filled: float
+	bid: float
+	ask: float
 	score: float
 
 	def __lt__(self, o) -> bool: