def buyTrades(deltaHoldings,inputUrl): for item in deltaHoldings: ticker = item.rsplit(" ",1)[0] position = item.rsplit(" ",1)[1] if deltaHoldings[item] < 0: # means we sold something # deltaHoldings will be negative if we sold something # change the orderType to its opposite so we sell instead of Buy. ordType = oppositeOrd(position) amount = abs(deltaHoldings[item]) print(str(ordType) + " " + str(amount) + " " + str(ticker)) buy.order(inputUrl,ticker,amount,ordType) else: # deltaHoldings will otherwise be positive, so buy normally. amount = deltaHoldings[item] print(str(position) + " " + str(amount) + " " + str(ticker)) buy.order(inputUrl,ticker,amount,position)
def buyTrades(deltaHoldings, inputUrl): for item in deltaHoldings: ticker = item.rsplit(" ", 1)[0] position = item.rsplit(" ", 1)[1] if deltaHoldings[item] < 0: # means we sold something # deltaHoldings will be negative if we sold something # change the orderType to its opposite so we sell instead of Buy. ordType = oppositeOrd(position) amount = abs(deltaHoldings[item]) print(str(ordType) + " " + str(amount) + " " + str(ticker)) buy.order(inputUrl, ticker, amount, ordType) else: # deltaHoldings will otherwise be positive, so buy normally. amount = deltaHoldings[item] print(str(position) + " " + str(amount) + " " + str(ticker)) buy.order(inputUrl, ticker, amount, position)
def makeTicket(transDict,elementIndex,inputUrl): f = open('transactions.log','a') # for saving transactions ticketString = ( str(transDict['name']) + ' --- ' + str(transDict['symbols'][elementIndex]) + ' --- ' + str(transDict['orderprice'][elementIndex]) + ' --- ' + str(transDict['orderamount'][elementIndex]) + ' --- ' + str(transDict['ordertype'][elementIndex]) + ' --- ' + str(transDict['orderdate'][elementIndex]) + ' --- ' + str(transDict['transdate'][elementIndex])) hashString = makeHash(ticketString) # search (grep) the transactions file to see if this order has been placed proc = subprocess.Popen(["cat transactions.log | grep -i " + hashString], stdout=subprocess.PIPE, shell=True) (out, err) = proc.communicate() if out == "": # grep will return empty if it can't find a matching hash. print("Adding new transaction...") ticketEntry = ticketString + ' --- ' + str(hashString) f.write(ticketEntry) # write the name and ticket to the file. f.close() import buy buy.order(inputUrl,transDict['symbols'][elementIndex],transDict['orderamount'][elementIndex],transDict['ordertype'][elementIndex]) else: dprint(debugMode,"Order already processed.")