def update_data(): global money global shares money = req_admxi.get_cash('hades') tmp = req_admxi.get_portfolio('hades') if not tmp: shares = 0 else: shares = tmp[0][4]
def portfolio(): tmp = req_admxi.get_portfolio('hades') print "MONEY: " + str(req_admxi.get_cash('hades')) + '$' if not tmp: print "SHARES : 0" else: shares = tmp[0] print "SHARES: NAME | NBR | TYPE | CUR" print " %s | %02d | %s | %s" % (shares[1],int(shares[4]),shares[2],shares[3])
def whattodo(figure): # convert list to string # do we need to account for each transaction as well global trader_overhead key=''.join(str(e) for e in figure) action=figdict[key][4] if "-" in action: action="sell" else: action="buy" elemental=figdict[key][2] # elemental="Earth" # action="sell" whichone=random.choice(company_dict[elemental]) print action,whichone,elemental if action=="buy": if portfolio[elemental].has_key(whichone): portfolio[elemental][whichone]+=1 else: portfolio.setdefault(elemental, {})[whichone] = 1 print "Buy", whichone bought=Share(whichone) print "Price", bought.get_price() # do buy action if we have da cash cash = req_admxi.get_cash(ALGO) if bought.get_price(): if cash>(float(bought.get_price())+trader_overhead): # 50 just in case exec_buy(whichone) trader_overhead+=1.0 elif action=="sell": #choose a random from elemental dict if portfolio[elemental].has_key(whichone): print portfolio # unless it is zero decrement it if portfolio[elemental][whichone]>0: portfolio[elemental][whichone]-=1 print "Sell", whichone sold=Share(whichone) print "Price", sold.get_price() exec_sell(whichone) trader_overhead+=1.0 else: print "No action taken" return (' '.join((action,whichone)))
def update(): cash = req_admxi.get_cash(ALGO) portfolio = req_admxi.get_portfolio(ALGO) print cash, portfolio print req_admxi.get_orders(ALGO)