-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodSpread.py
More file actions
65 lines (47 loc) · 1.67 KB
/
Copy pathmodSpread.py
File metadata and controls
65 lines (47 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import os.path
from mod import Order, Mod
import itemUpdate
ordersUrl = "https://api.warframe.market/v1/items/{}/orders"
rarities = ["common", "uncommon", "rare", "legendary"]
def run(rarity="legendary"):
assert(rarity in rarities)
modRestrict = rarities[rarities.index(rarity):]
if not os.path.isfile("cache/moditems"):
itemUpdate.run()
modList = []
with open("cache/moditems", 'r') as f:
modList = [Mod(*l.split()) for l in f.readlines() if l.strip() != ""]
#fill bid and ask calc spread
modCount = len(modList)
spreads = []
for i, mod in enumerate(modList):
if not mod.rarity in modRestrict:
continue
r = requests.get(ordersUrl.format(mod.url_name))
print(f"{i} of {modCount}: {mod.url_name}")
data = r.json()
data = data["payload"]["orders"]
modBids = []
modAsks = []
for order in data:
marketOperation = Order(order["id"], order["platinum"], order["mod_rank"], order["user"]["status"])
if order["order_type"] == "sell":
modAsks.append(marketOperation)
else:
modBids.append(marketOperation)
mod.setAsk(modAsks)
mod.setBid(modBids)
spread = mod.calSpread()
if spread is None or spread > 0:
continue
spreads.append((mod.calSpread(), mod))
spreads.sort(key=lambda tup: tup[0])
return spreads
def render(spreads):
for s, m in spreads:
print(m.url_name)
print(f"plat spread: {s}")
print(f"endo cost: {m.calCostEndo()}")
print(f"credit cost: {m.calCostCredits()}")
print()