forked from arturino009/POEcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
priceGetter.py
335 lines (302 loc) · 12.3 KB
/
priceGetter.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import requests
import time
from json import loads as load
import statistics
import math
import json
headers = requests.utils.default_headers()
#How long (in seconds) to wait between requests to trade API
#Current rate-limit header rules: 5:10:60,15:60:300,30:300:1800
timeBetweenRequests = 10
headers.update({
'User-Agent': "IDareYouLV's cluster notable combination price checker",
'From': '[email protected]'
})
def getLeague():
leagues = requests.get('http://api.pathofexile.com/leagues', headers=headers)
leagues = leagues.json()
current_league = leagues[4]['id'] # current challenge league
return current_league
def getCurrencies(league):
response = requests.get(
'https://poe.ninja/api/data/currencyoverview?league=' + current_league + '&type=Currency', headers=headers)
currencies = load(response.text)['lines']
rates = {
c['currencyTypeName']: c['chaosEquivalent'] for c in currencies
}
with open('currency.json') as json_file:
currShort = json.load(json_file)
arr = []
for name in currShort:
for name_a in rates:
if name == name_a:
x = {
'currFull': name,
'curr': currShort[name],
'rate': rates[name]
}
arr.append(x)
return arr
def get_category_jewel_price(a, ilvl):
data_set = { # structure for API request. All info from https://www.reddit.com/r/pathofexiledev/comments/7aiil7/how_to_make_your_own_queries_against_the_official/ . Absolutely no other documentation
"query": {
"status": {
"option": "online"
},
"stats": [{
"type": "and",
"filters": [{"id": 'enchant.stat_3948993189', "value": {"option": a['clusterId']}}]
}],
"filters": {
"type_filters": {
"filters": {
"rarity": {
"option": "nonunique"
}
}
},
"misc_filters": {
"filters": {
"corrupted": {
"option": "false"
},
"ilvl": {
"min": ilvl
}
}
},
"trade_filters": {
"filters": {
"sale_type": {
"option": "priced"
}
}
}
}
},
"sort": {
"price": "asc"
}
}
# send the request to API
while True:
response = requests.post(
'https://www.pathofexile.com/api/trade/search/' + current_league, json=data_set, headers=headers)
response = response.json()
if 'error' in response:
print(response['error']['message'])
time.sleep(60)
continue
else:
break
result = response['result']
id = response['id']
size = response['total']
if size == 0:
return 0
# if there are more than 10 listings, strip all of them away after 10th. We cant request info about items more than 10 items at once
if size > 10:
del result[10:]
# make correct formatting
if size > 1:
str1 = ','.join(result)
else:
str1 = result
# get all actual listings of items
address = 'https://www.pathofexile.com/api/trade/fetch/' + \
str(str1) + '?query=' + id
request = requests.get(address, headers=headers)
results_json = request.json()
# list to hold all prices of an item. Later used to calculate medium price
medium = list()
print("Base: " + a['clusterName'])
print("ilvl: " + str(ilvl))
print('Listings:' + str(size))
for p in results_json['result']:
# conversion for some more valuable currency
currency = p['listing']['price']['currency']
if currency != 'chaos' or currency == 'p':
try:
curr = [dictionary for dictionary in rates if dictionary["curr"]
== p['listing']['price']['currency']]
p['listing']['price']['amount'] = p['listing']['price']['amount'] * curr[0]['rate']
p['listing']['price']['currency'] = "chaos"
except:
continue
medium.append(p['listing']['price']['amount'])
# get the average median of all listed prices for an item
if medium == 0:
avg = 1
else:
avg = statistics.median_grouped(medium)
print("Average median price: " + str(round(avg, 2)) + '\n')
# time delay, so API wont rate limit me
time.sleep(timeBetweenRequests)
return avg
def getNotablePrice(a, b, query, inp, jewel_price):
if query == 1:
ilvl = b['notableLevel']
else:
ilvl = max(b[0]['notableLevel'], b[1]['notableLevel'])
data_set = { # structure for API request. All info from https://www.reddit.com/r/pathofexiledev/comments/7aiil7/how_to_make_your_own_queries_against_the_official/ . Absolutely no other documentation
"query": {
"status": {
"option": "online"
},
"type": "Small Cluster Jewel" if inp == 1 else "Medium Cluster Jewel",
"stats": [{
"type": "and",
"filters": [{"id": b['notableId']}] if query == 1 else [{"id": b[0]['notableId']}, {"id": b[1]['notableId']}]
}],
"filters": {
"type_filters": {
"filters": {
"rarity": {
"option": "nonunique"
}
}
},
"trade_filters": {
"filters": {
"sale_type": {
"option": "priced"
}
}
}
}
},
"sort": {
"price": "asc"
}
}
# send the request to API
while True:
response = requests.post(
'https://www.pathofexile.com/api/trade/search/' + current_league, json=data_set, headers=headers)
response = response.json()
if 'error' in response:
print(response['error']['message'])
time.sleep(60)
continue
else:
break
result = response['result']
id = response['id']
size = response['total']
# if there are less than 10 listings for an item, we just just skip it (no demand)
if size < 10:
print("Not enough items!(" + str(size) + ") Skipping... " + b['notableName'] if query == 1 else (b[0]['notableName'] + " and " + b[1]['notableName']) +"\n")
return 0
# if there are more than 10 listings, strip all of them away after 10th. We cant request info about items more than 10 items at once
if size > 10:
del result[10:]
# make correct formatting
if size > 1:
str1 = ','.join(result)
else:
str1 = result
# get all actual listings of items
address = 'https://www.pathofexile.com/api/trade/fetch/' + \
str(str1) + '?query=' + id
request = requests.get(address, headers=headers)
results_json = request.json()
# probability to get an item while crafting. Formula is mostly correct
altPrice = [dictionary for dictionary in rates if dictionary["currFull"]
== "Orb of Alteration"][0]['rate']
augPrice = [dictionary for dictionary in rates if dictionary["currFull"]
== "Orb of Augmentation"][0]['rate']
if query == 1:
probability = b['notableWeight']/a['clusterWeightPrefix']
tries = math.ceil(1 / probability)
alt_count = tries
aug_count = math.ceil(alt_count/4)
craft_price = alt_count * altPrice + aug_count * augPrice
else:
regalPrice = [
dictionary for dictionary in rates if dictionary["currFull"] == "Regal Orb"][0]['rate']
scourPrice = [dictionary for dictionary in rates if dictionary["currFull"]
== "Orb of Scouring"][0]['rate']
transPrice = [dictionary for dictionary in rates if dictionary["currFull"]
== "Orb of Transmutation"][0]['rate']
suffixWeight = 14150
probabilityFirst = b[0]['notableWeight'] / a['clusterWeightPrefix']
probabilityFirstSecond = b[1]['notableWeight'] / \
(a['clusterWeightPrefix'] + suffixWeight - b[0]['notableWeight'])
probabilityFirstSucess = probabilityFirst * probabilityFirstSecond
probabilitySecond = b[1]['notableWeight'] / a['clusterWeightPrefix']
probabilitySecondFirst = b[0]['notableWeight'] / \
(a['clusterWeightPrefix'] + suffixWeight - b[1]['notableWeight'])
probabilitySecondSucess = probabilitySecond * probabilitySecondFirst
probability = probabilityFirstSucess + \
probabilitySecondSucess # overall probability to hit both
probability_first = (b[0]['notableWeight'] + b[1]
['notableWeight']) / a['clusterWeightPrefix']
probability_second = probability/probability_first
tries = math.ceil(1 / probability)
regal_count = math.ceil(1 / probability_second)
scour_count = regal_count - 1
trans_count = regal_count - 1
alt_count = tries - trans_count
aug_count = math.ceil((tries + alt_count) / 4) + 1
craft_price = alt_count * altPrice + aug_count * augPrice + regal_count * \
regalPrice + scour_count * scourPrice + trans_count * transPrice
craft_and_jewel_price = craft_price + jewel_price
# list to hold all prices of an item. Later used to calculate medium price
medium = list()
if query == 1:
print(b['notableName'] + ": " + str(round(probability*100, 3)) + "%" +
" Cost for rerolls: " + str(round(craft_price, 2)) + " Tries: " + str(round(tries)))
print('Listings:' + str(size))
else:
print(b[0]['notableName'] + " and " + b[1]['notableName'] + ": " + str(round(probability*100, 3)
) + "%" + " Cost for rerolls: " + str(round(craft_price, 2)) + " Tries: " + str(round(tries)))
print('Listings:' + str(size))
for p in results_json['result']:
# conversion for some more valuable currency
currency = p['listing']['price']['currency']
if currency != 'chaos' or currency == 'p':
try:
curr = [dictionary for dictionary in rates if dictionary["curr"]
== p['listing']['price']['currency']]
price = p['listing']['price']['amount'] * curr[0]['rate']
p['listing']['price']['amount'] = price
p['listing']['price']['currency'] = "chaos"
except:
continue
medium.append(p['listing']['price']['amount'])
print("Price: ", p['listing']['price']['amount'],
" ", p['listing']['price']['currency'], '\n')
# get the average median of all listed prices for an item
avg = statistics.median_grouped(medium)
# profit margin
profit = avg - craft_and_jewel_price
PPT = profit/tries
if len(medium) > 1:
first = (medium[0]+medium[1])/2
else:
first = medium[0]
LPPT = (first - craft_and_jewel_price)/tries
print("The average median is ", round(avg, 2),
" Profit:", round(profit, 2), '\n')
x = {
'name': b['notableName'] if query == 1 else (b[0]['notableName'] + " and " + b[1]['notableName']),
'listings': size,
'tries': round(tries),
'craft_price': round(craft_price, 2),
'first': round(first, 2),
'average_price': round(avg, 2),
'profit': round(profit, 2),
'PPT': round(PPT, 3),
'LPPT': round(LPPT, 3), # when first item is a lot cheaper than average
'category': a['clusterName'],
'request': data_set,
'category_full': a,
'notable_full': b,
'ilvl': ilvl,
'id': id
}
# time delay, so API won't rate limit me
time.sleep(timeBetweenRequests)
return x
current_league = getLeague()
rates = getCurrencies(current_league)