Skip to content

Commit

Permalink
refine relist strategy, add option to relist at current or previous p…
Browse files Browse the repository at this point in the history
…rice, display sold player information in console and watch frame, fix bug with futbin if the player has no price listed
  • Loading branch information
hunterjm committed Nov 26, 2015
1 parent 99b4c23 commit b83d6c0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
69 changes: 40 additions & 29 deletions core/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,49 +241,60 @@ def bid(q, api, playerList, settings):
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

completedTrades = sum([i['tradeState'] in ('expired', 'closed') for i in tradepile])
sold = 0
if completedTrades > 0:
try:
# Clean up Trade Pile & relist items
sold = api.relist(clean=True)
if sold:
q.put('%s Trade Status: %d items sold\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), sold))
pileFull = False
except InternalServerError:
# auto re-list is down. We have to do this manually...
q.put('%s Manually re-listing %d players.\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), completedTrades))
# 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(api.baseId(i['resourceId']))
if baseId in bidDetails:
sell = bidDetails[baseId]['sell']
binPrice = bidDetails[baseId]['binPrice']
if i['tradeState'] == 'closed':
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.SOLD, api.credits))
api.tradepileDelete(i['tradeId'])
sold += 1
sell = i['startingBid'] if settings['relistAll'] else bidDetails[baseId]['sell']
binPrice = i['buyNowPrice'] if settings['relistAll'] else bidDetails[baseId]['binPrice']
if i['tradeState'] == 'expired' and sell and binPrice:
api.sell(i['id'], sell, binPrice)

pass
# 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:

# 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'])
# 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 sold:
if auctionsWon or expired or sold:
tradepile = api.tradepile()
auctionsWon = 0

# Reset auctions won
auctionsWon = 0

except (FutError, RequestException) as e:
q.put(e)
Expand Down
20 changes: 17 additions & 3 deletions frames/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, master, controller):
self.sell = tk.StringVar()
self.bin = tk.StringVar()
self.snipeOnly = tk.IntVar()
self.relistAll = tk.IntVar()

self.settings = {
'rpm': 20,
Expand All @@ -48,7 +49,8 @@ def __init__(self, master, controller):
'buy': 0.9,
'sell': 1,
'bin': 1.25,
'snipeOnly': 0
'snipeOnly': 0,
'relistAll': 1
}

# Search for settings
Expand All @@ -67,6 +69,7 @@ def __init__(self, master, controller):
self.sell.set(int(self.settings['sell']*100))
self.bin.set(int(self.settings['bin']*100))
self.snipeOnly.set(self.settings['snipeOnly'])
self.relistAll.set(self.settings['relistAll'])

# Setup traces
self.rpm.trace('w', self.save_settings)
Expand All @@ -77,6 +80,7 @@ def __init__(self, master, controller):
self.sell.trace('w', self.save_settings)
self.bin.trace('w', self.save_settings)
self.snipeOnly.trace('w', self.save_settings)
self.relistAll.trace('w', self.save_settings)

# Setup GUI
options = tk.Frame(self)
Expand Down Expand Up @@ -160,8 +164,13 @@ def __init__(self, master, controller):
snipeOnlyCheckbox = tk.Checkbutton(form, variable=self.snipeOnly)
snipeOnlyCheckbox.grid(column=1, row=7, sticky='w')

relistAllLbl = tk.Label(form, text='Relist at same price:')
relistAllLbl.grid(column=0, row=8, sticky='e')
relistAllCheckbox = tk.Checkbutton(form, variable=self.relistAll)
relistAllCheckbox.grid(column=1, row=8, sticky='w')

self.bidbtn = tk.Button(form, text='Start Bidding', command=self.start)
self.bidbtn.grid(column=0, row=8, columnspan=2, padx=5, pady=5)
self.bidbtn.grid(column=0, row=9, columnspan=2, padx=5, pady=5)

self.checkQueue()
self.clearErrors()
Expand Down Expand Up @@ -291,6 +300,8 @@ def lookup_bin(self, player):
}).json()
for p in response['data']:
if p[len(p)-2] == player['id']:
if not p[6]: p[6] = 0
if not p[8]: p[8] = 0
r = {'xbox': int(p[8]), 'ps4': int(p[6])}
return r

Expand Down Expand Up @@ -321,6 +332,8 @@ def checkQueue(self):
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='lost')
elif (msg[1] == EventType.BIDWON or msg[1] == EventType.BIN):
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='won')
elif msg[1] == EventType.SOLD:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid, tag='sold')
elif msg[1] == EventType.UPDATE:
self.auctionStatus.update_status(msg[0], time.strftime('%Y-%m-%d %H:%M:%S'), msg[0].currentBid)
self.controller.status.set_credits(msg[2])
Expand Down Expand Up @@ -401,7 +414,8 @@ def save_settings(self, *args):
'buy': int(self.buy.get())/100 if self.buy.get() else 0,
'sell': int(self.sell.get())/100 if self.sell.get() else 0,
'bin': int(self.bin.get())/100 if self.bin.get() else 0,
'snipeOnly': self.snipeOnly.get()
'snipeOnly': self.snipeOnly.get(),
'relistAll': self.relistAll.get()
}
with open(constants.SETTINGS_FILE, 'w') as f:
json.dump(self.settings, f)
Expand Down
4 changes: 2 additions & 2 deletions frames/misc/auctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def __init__(self, frame):
self.tree.heading("bin", text="BIN")
self.tree.heading("expires", text="Expires")

self.tree.tag_configure('won', foreground='#006400', background='grey')
self.tree.tag_configure('bid', foreground='#006400')
self.tree.tag_configure('war', foreground='#B77600')
self.tree.tag_configure('sold', foreground='#1C7CA9', background='grey')
self.tree.tag_configure('lost', foreground='#B70000', background='grey')
self.tree.tag_configure('won', foreground='#006400', background='grey')
self.tree.tag_configure('sold', foreground='#1C7CA9', background='grey')

# scrollbar
ysb = ttk.Scrollbar(self.view, orient='vertical', command=self.tree.yview)
Expand Down

0 comments on commit b83d6c0

Please sign in to comment.