Sfoglia il codice sorgente

market: convert to a market making tool

raylu 2 settimane fa
parent
commit
c772b15403
3 ha cambiato i file con 9 aggiunte e 24 eliminazioni
  1. 1 1
      config.py
  2. 5 21
      market.py
  3. 3 2
      readme.md

+ 1 - 1
config.py

@@ -31,7 +31,7 @@ class Config:
 
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class MarketConfig:
-	ignore_warehouses: typing.Sequence[str]
+	mm_items: typing.Mapping[str, int]
 
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class SupplyConfig:

+ 5 - 21
market.py

@@ -23,6 +23,7 @@ def main() -> None:
 		return
 
 	check_cxos()
+	return
 
 	markets: dict[str, list[Market]] = collections.defaultdict(list)
 	with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
@@ -43,32 +44,15 @@ def main() -> None:
 		print()
 
 def check_cxos() -> None:
-	orders: typing.Sequence[ExchangeOrder] = cache.get('https://rest.fnar.net/cxos/' + config.username,
-			headers={'Authorization': config.fio_api_key})
-	summary: typing.Mapping[tuple[str, str], ExchangeSummary] = {
-		(summary['MaterialTicker'], summary['ExchangeCode']): summary
-		for summary in cache.get('https://rest.fnar.net/exchange/all')
-	}
-	for order in orders:
-		if order['Status'] == 'FILLED':
-			continue
-		state = summary[order['MaterialTicker'], order['ExchangeCode']]
-		if order['OrderType'] == 'BUYING' and state['Bid'] is not None and state['Bid'] > order['Limit']:
-			print('outbid on', f'{order["MaterialTicker"]}.{order["ExchangeCode"]}')
-		elif order['OrderType'] == 'SELLING' and state['Ask'] is not None and state['Ask'] < order['Limit']:
-			print('undercut on', f'{order["MaterialTicker"]}.{order["ExchangeCode"]}')
-	print()
-
 	warehouses: typing.Sequence[Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
 			headers={'Authorization': config.fio_api_key})
 	for warehouse in warehouses:
-		if warehouse['LocationNaturalId'] in config.market.ignore_warehouses:
-			continue
 		storage: Storage = cache.get(f'https://rest.fnar.net/storage/{config.username}/{warehouse["StoreId"]}',
 			headers={'Authorization': config.fio_api_key})
-		if storage['WeightLoad'] > 0 or storage['VolumeLoad'] > 0:
-			print('warehouse', warehouse['LocationNaturalId'], 'is not empty')
-	print()
+		for item in storage['StorageItems']:
+			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"]}')
 
 def analyze_raw_price(price: RawPrice) -> Market | None:
 	if (traded := price['AverageTraded7D']) is None or traded < 100:

+ 3 - 2
readme.md

@@ -6,9 +6,10 @@ get a FIO API key from https://fio.fnar.net/settings and create a `config.toml`
 ```toml
 username = 'raylu'
 fio_api_key = 'uuid_here'
+punoted_api_key = ''
 
-[market]
-ignore_warehouses = ['HRT']
+[market.mm_items]
+TCL = 0
 
 [supply.promitor]
 ignore_materials = ['RAT']