-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbid.py
More file actions
327 lines (266 loc) · 15.9 KB
/
bid.py
File metadata and controls
327 lines (266 loc) · 15.9 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
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
import time
from operator import itemgetter
from frames.misc.auctions import Card, PlayerCard, EventType
def increment(bid):
if bid < 1000:
return 50
elif bid < 10000:
return 100
elif bid < 50000:
return 250
elif bid < 100000:
return 500
else:
return 1000
def decrement(bid):
if bid <= 1000:
return 50
elif bid <= 10000:
return 100
elif bid <= 50000:
return 250
elif bid <= 100000:
return 500
else:
return 1000
def roundBid(bid):
return int(increment(bid) * round(float(bid)/increment(bid)))
def bid(q, api, playerList, settings):
pileFull = False
auctionsWon = 0
trades = {}
playersIds = {p.playerid : p for p in playerList} # dict of ids
api.resetSession()
for item in api.watchlist():
trades[item['tradeId']] = item['resourceId']
# Grab all items from tradepile
tradepile = api.tradepile()
# Log selling players
for trade in tradepile:
asset = api.cardInfo(trade['resourceId'])
try:
if str(asset['Item']['ItemType']).startswith('Player'):
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
else:
displayName = asset['Item']['Desc']
except:
displayName = "Unknown"
card = PlayerCard(trade, displayName)
q.put((card, EventType.SELLING, api.credits))
for player in playerList:
if player.maxBuy < 100:
continue
try:
# How many of this item do we already have listed?
listed = sum([str(api.baseId(item['resourceId'])) == player.playerid for item in tradepile])
# Only bid if we don't already have a full trade pile and don't own too many of this player
binWon = False
if not pileFull and api.credits > settings['minCredits'] and listed < settings['maxPlayer']:
# Look for any BIN less than the BIN price
for item in api.searchAuctions('player', defId=player.playerid, max_buy=player.maxBuy, start=0, page_size=50):
# player safety checks for every possible bid
if listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
break
# No Dups
if item['tradeId'] in trades:
continue
# Must have contract
if item['contract'] < 1:
continue
# Buy!!!
if api.bid(item['tradeId'], item['buyNowPrice']):
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)
q.put((card, EventType.BIN, api.credits))
q.put('%s Card Purchased: BIN %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['buyNowPrice'], asset['Item']['FirstName'], asset['Item']['LastName']))
trades[item['tradeId']] = item['resourceId']
binWon = True
listed += 1
else:
q.put('%s Bid Error: You are not allowed to bid on this trade\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
# Search first 50 items in my price range to bid on within 5 minutes
if not settings['snipeOnly']:
bidon = 0
subtract = decrement(player.maxBuy)
for item in api.searchAuctions('player', defId=player.playerid, max_price=player.maxBuy-subtract, start=0, page_size=50):
# player safety checks for every possible bid
# Let's look at last 5 minutes for now and bid on 5 players max
if item['expires'] > 300 or bidon >= 5 or listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
break
# No Dups
if item['tradeId'] in trades:
continue
# Must have contract
if item['contract'] < 1:
continue
# Set my initial bid
if item['currentBid']:
bid = item['currentBid'] + increment(item['currentBid'])
else:
bid = item['startingBid']
# Bid!!!
if api.bid(item['tradeId'], bid):
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)
card.currentBid = bid
q.put((card, EventType.NEWBID, api.credits))
q.put('%s New Bid: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), bid, asset['Item']['FirstName'], asset['Item']['LastName']))
trades[item['tradeId']] = item['resourceId']
bidon += 1
else:
q.put('%s Bid Error: You are not allowed to bid on this trade\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
if not settings['snipeOnly'] and trades:
# Update watched items
q.put('%s Updating watched items...\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
for item in api.tradeStatus([tradeId for tradeId in trades]):
item['resourceId'] = trades[item['tradeId']]
baseId = str(abs(item['resourceId'] + 0x80000000))
if baseId not in playersIds:
continue
maxBid = playersIds[baseId].maxBuy
sell = playersIds[baseId].sell
binPrice = playersIds[baseId].bin
# How many of this item do we already have listed?
listed = sum([str(api.baseId(trade['resourceId'])) == baseId for trade in tradepile])
tradeId = item['tradeId']
if tradeId not in trades:
continue
asset = api.cardInfo(trades[tradeId])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)
# Update the card, regardless what will happen
q.put((card, EventType.UPDATE, api.credits))
# Handle Expired Items
if item['expires'] == -1:
if (item['bidState'] == 'highest' or (item['tradeState'] == 'closed' and item['bidState'] == 'buyNow')):
# We won! Send to Pile!
q.put((card, EventType.BIDWON, api.credits))
q.put('%s Auction Won: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['currentBid'], asset['Item']['FirstName'], asset['Item']['LastName']))
if api.sendToTradepile(tradeId, item['id'], safe=True):
# List on market
if api.sell(item['id'], sell, binPrice):
auctionsWon += 1
listed += 1
# No need to keep track of expired bids
del trades[tradeId]
q.put('%s Item Listed: %s %s for %d (%d BIN)\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], sell, binPrice))
pileFull = False
else:
q.put('%s Error: %s %s could not be placed in the tradepile...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName']))
pileFull = True
else:
if api.watchlistDelete(tradeId):
if item['currentBid'] < maxBid:
q.put((card, EventType.LOST, api.credits))
q.put('%s TOO SLOW: %s %s went for %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], item['currentBid']))
else:
q.put((card, EventType.LOST, api.credits))
q.put('%s Auction Lost: %s %s went for %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], item['currentBid']))
# No need to keep track of expired bids
del trades[tradeId]
elif item['bidState'] != 'highest':
# Continue if we already have too many listed or we don't have enough credits
if listed >= settings['maxPlayer'] or api.credits < settings['minCredits']:
continue
# We were outbid
newBid = item['currentBid'] + increment(item['currentBid'])
if newBid > maxBid:
if api.watchlistDelete(tradeId):
q.put((card, EventType.OUTBID, api.credits))
q.put('%s Outbid: Won\'t pay %d for %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), newBid, asset['Item']['FirstName'], asset['Item']['LastName']))
del trades[tradeId]
else:
if api.bid(tradeId, newBid):
card.currentBid = newBid
q.put((card, EventType.BIDWAR, api.credits))
q.put('%s Bidding War: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), newBid, asset['Item']['FirstName'], asset['Item']['LastName']))
else:
q.put('%s Bid Error: You are not allowed to bid on this trade\n' % (time.strftime('%Y-%m-%d %H:%M:%S')))
# buy now goes directly to unassigned now
if binWon:
for item in api.unassigned():
baseId = str(abs(item['resourceId'] + 0x80000000))
if baseId not in playersIds:
continue
sell = playersIds[baseId].sell
binPrice = playersIds[baseId].bin
tradeId = item['tradeId'] if item['tradeId'] is not None else -1
asset = api.cardInfo(item['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(item, displayName)
# We won! Send to Pile!
q.put((card, EventType.BIDWON, api.credits))
q.put('%s Auction Won: %d on %s %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), item['lastSalePrice'], asset['Item']['FirstName'], asset['Item']['LastName']))
if api.sendToTradepile(tradeId, item['id'], safe=True):
# List on market
if api.sell(item['id'], sell, binPrice):
auctionsWon += 1
# No need to keep track of expired bids
if tradeId > 0:
del trades[tradeId]
q.put('%s Item Listed: %s %s for %d (%d BIN)\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], sell, binPrice))
pileFull = False
else:
q.put('%s Error: %s %s could not be placed in the tradepile...\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName']))
pileFull = True
# relist items
expired = sum([i['tradeState'] == 'expired' for i in tradepile])
if expired > 0:
relistFailed = False
if settings['relistAll']:
try:
api.relist()
except InternalServerError:
relistFailed = True
pass
if not settings['relistAll'] or relistFailed:
q.put('%s Manually re-listing %d players.\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), expired))
for i in tradepile:
baseId = str(abs(i['resourceId'] + 0x80000000))
if baseId in playersIds:
sell = i['startingBid'] if settings['relistAll'] else playersIds[baseId].sell
binPrice = i['buyNowPrice'] if settings['relistAll'] else playersIds[baseId].bin
if i['tradeState'] == 'expired' and sell and binPrice:
api.sell(i['id'], sell, binPrice)
else:
if i['tradeState'] == 'expired':
# If we don't follow this player, then just relist it with the same price
asset = api.cardInfo(i['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
q.put('%s Re-listing %s at the same price. (Player not in target list)\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), displayName))
api.sell(i['id'], i['startingBid'], i['buyNowPrice'])
# Log sold items
sold = sum([i['tradeState'] == 'closed' for i in tradepile])
if sold > 0:
for i in tradepile:
if i['tradeState'] == 'closed':
asset = api.cardInfo(i['resourceId'])
displayName = asset['Item']['CommonName'] if asset['Item']['CommonName'] else asset['Item']['LastName']
card = PlayerCard(i, displayName)
q.put((card, EventType.SOLD, api.credits))
q.put('%s Item Sold: %s %s for %d\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), asset['Item']['FirstName'], asset['Item']['LastName'], i['currentBid']))
api.tradepileDelete(i['tradeId'])
pileFull = False
# Sleep if we have no more space left
if pileFull:
# Update tradepile and verify that we are really full and it just wasn't an error
tradepile = api.tradepile()
if len(tradepile) >= api.tradepile_size:
# No use in trying more until min trade is done
selling = sorted(tradepile, key=itemgetter('expires'), reverse=True)
q.put('%s Trade Pile Full! Resume bidding in %d seconds\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), selling[0]['expires']))
time.sleep(selling[0]['expires'])
q.put((auctionsWon, sold, api.credits))
# re-sync tradepile if we won something
if auctionsWon or expired or sold:
tradepile = api.tradepile()
# Reset auctions won
auctionsWon = 0
except (FutError, RequestException) as e:
q.put(e)
# update our api
q.put(api)
from fut.exceptions import FutError, InternalServerError
from requests.exceptions import RequestException