def sellItem(itemhandler, goodprices): if (len(getOrderCache()) > 16): print( "will exceeded max orders, cancelling a leftoveritemhandler's cheapest sellorder" ) cancelOrder(getWorthlessLOIHSellorder()) return sellItem(itemhandler, goodprices) sellprice = goodprices[1] if (sellprice == -1): print("Warning, not selling item: " + api.getNameFromID(itemhandler.typeid) + " because there is no good price.") return sellprice = round(sellprice - random.random() / 7 - 0.01, 2) flag = sellitemininventory(itemhandler.typeid, sellprice) if (flag == 0): print("couldnt sell item from inventory, doesnt exist") return quantity = 0 if itemhandler.buyorder is None or itemhandler.buyorder.finished: #adjust the quantity if there are previous sellorders quantity = itemhandler.volume for sellorder in itemhandler.sellorderlist: quantity -= sellorder.volentered else: #we only get here once, because we check if sellorderlist has no #elements in the ifstatement in the selling part in itemhandler's handle() quantity = itemhandler.buyorder.volentered - itemhandler.buyorder.volremaining itemhandler.sellorderlist.append( cm.Order(itemhandler.typeid, -1, False, sellprice, quantity, quantity, cm.getEVETimestamp())) #this line sets the orderid from -1 to something else refreshAllOrders()
def menu(): order = common.Order() os.system('clear') common.divide() common.prCyan("======== RABBITMQ Micro-services DEMO ========") common.divide() common.prLightPurple("MENU") common.prLightPurple("1 - send the new order status") common.prLightPurple("2 - send the delivered status") common.prLightPurple("3 - add1 store service") common.divide() s = input() while s != "q": if s == "1": common.prPurple("Sending status \"new_order\"") common.divide() dict1 = { 'id': order.get_and_inc(), "status": "new_order", "what": "Coats" } sendmessage(dict1) if s == "2": common.prPurple("Sending status \"delivered\"") common.divide() dict1 = { 'id': order.get_id(), "status": "delivered", "what": "Coats", "name": "Jon Snow", "address": "Winterfell" } sendmessage(dict1) if s == "3": connection = pika.BlockingConnection( pika.ConnectionParameters(host='localhost', credentials=credentials)) channel = connection.channel() channel.queue_bind(queue="store_queue", exchange="orders", routing_key="#") connection.close() time.sleep(0.5) _thread.start_new(start_consumers, ( "Store", "store_queue", callbackstore, )) s = input()
def buyItem(itemhandler, goodprices): if (len(getOrderCache()) > 16): print( "will exceeded max orders, cancelling a leftoveritemhandler's cheapest sellorder" ) cancelOrder(getWorthlessLOIHSellorder()) return buyItem(itemhandler, goodprices) quantity = itemhandler.volume buyprice = goodprices[0] if (buyprice == -1): print("Warning, not buying item: " + api.getNameFromID(itemhandler.typeid) + " because there is no good price.") return buyprice = round(buyprice + random.random() / 7 + 0.01, 2) print("itemhandler called: " + api.getNameFromID(itemhandler.typeid) + " is initiating buyorder. price:" + str(buyprice) + ", quantity:" + str(quantity)) buyorder(itemhandler.typeid, buyprice, quantity) itemhandler.buyorder = cm.Order(itemhandler.typeid, -1, True, buyprice, quantity, quantity, cm.getEVETimestamp()) #this line sets the orderid from -1 to something else refreshAllOrders()
def menu(): order = common.Order() os.system('clear') common.divide() common.prCyan("======== KAFKA Micro-services DEMO ========") common.divide() common.prLightPurple("MENU") common.prLightPurple("1 - send the new order status") common.prLightPurple("2 - send the delivered status") common.prLightPurple("3 - add store service") common.divide() s = input() while s != "q": if s == "1": common.prPurple("Sending status \"new_order\"") common.divide() dict1 = { 'id': order.get_and_inc(), "status": "new_order", "what": "Coats" } sendmessage(dict1) if s == "2": common.prPurple("Sending status \"delivered\"") common.divide() dict1 = { 'id': order.get_id(), "status": "delivered", "what": "Coats", "name": "Jon Snow", "address": "Winterfell" } sendmessage(dict1) if s == "3": _thread.start_new(start_store_consumer, ()) s = input()
def getTopOrders(typeid): quickbar.openItem(typeid) cm.sleep(0.2) marketlogsfolder = os.path.expanduser( '~\\Documents\\EVE\\logs\\Marketlogs') deleteMarketLogs() cm.clickPointPNG("imgs/exporttofile.png", 5, 5, cache=True) loopidx = 0 while True: if (len(os.listdir(marketlogsfolder)) > 0): print("found file in marketlogs...") break if loopidx % 5 == 0: print("didn't open item") quickbar.openItem(typeid) cm.clickPointPNG("imgs/exporttofile.png", 5, 5, cache=True) else: cm.sleep(0.5) loopidx += 1 if os.listdir(marketlogsfolder)[-1].startswith('My Orders'): print("wrong file exported") return getTopOrders(typeid) logfile = marketlogsfolder + "\\" + os.listdir(marketlogsfolder)[-1] buyorders, sellorders = [], [] exitflag = False try: with open(logfile) as export: reader = csv.DictReader(export) for l in reader: #if we didnt wait long enough for item to load if (int(l['typeID']) != typeid): exitflag = True break if (int(l['jumps']) != 0): continue o = cm.Order(typeid, int(l['orderID']), str(l['bid']) == "True", float(l['price']), int(float(l['volEntered'])), int(float(l['volRemaining'])), DateUtilParser(l['issueDate']).timestamp()) if (o.bid): buyorders.append(o) else: sellorders.append(o) os.remove(logfile) except: print("exception while reading item export") cm.sleep(5) return getTopOrders(typeid) if (exitflag): print("wrong item was exported") quickbar.addItemToQuickbar(typeid) return getTopOrders(typeid) #highest first buyorders.sort(key=lambda x: x.price, reverse=True) #lowest first sellorders.sort(key=lambda x: x.price, reverse=False) return (buyorders[0:6], sellorders[0:6])
def loadOrders(): itemhandlerlist = variables.itemhandlerlist marketlogsfolder = os.path.expanduser( '~\\Documents\\EVE\\logs\\Marketlogs') deleteMarketLogs() cm.exportMyOrders() loopidx = 0 while True: if (len(os.listdir(marketlogsfolder)) > 0): break thing = pyautogui.locateOnScreen("imgs/nobuyorsell.png", confidence=0.9) if thing is not None: okbutton = cm.Point(thing.left + 169, thing.top + 194) cm.clickPoint(okbutton) return if loopidx % 5 == 0: cm.exportMyOrders() else: cm.sleep(0.5) loopidx += 1 if not os.listdir(marketlogsfolder)[-1].startswith('My Orders'): return loadOrders() logfile = marketlogsfolder + "\\" + os.listdir(marketlogsfolder)[-1] neworders = [] try: with open(logfile) as export: reader = csv.DictReader(export) for l in reader: neworders.append( cm.Order(int(l['typeID']), int(l['orderID']), str(l['bid']) == "True", float(l['price']), int(float(l['volEntered'])), int(float(l['volRemaining'])), DateUtilParser(l['issueDate']).timestamp())) os.remove(logfile) except: cm.sleep(5) return loadOrders() for no in neworders: if not any(no.typeid == ih.typeid for ih in itemhandlerlist): print("initiating leftoveritemhandler for order:" + api.getNameFromID(no.typeid)) itemhandlerlist.append(cm.LeftoverItemHandler(no.typeid, [], None)) quickbar.addItemToQuickbar(no.typeid) #sort each neworder back into the itemhandlers for itemhandler in itemhandlerlist: itemhandler.sellorderlist = [] itemhandler.buyorder = None for no in neworders: if (itemhandler.typeid == no.typeid): if no.bid: itemhandler.buyorder = no else: itemhandler.sellorderlist.append(no)
def refreshAllOrders(): itemhandlerlist = variables.itemhandlerlist marketlogsfolder = os.path.expanduser( '~\\Documents\\EVE\\logs\\Marketlogs') deleteMarketLogs() cm.exportMyOrders() loopidx = 0 while True: if (len(os.listdir(marketlogsfolder)) > 0): break thing = pyautogui.locateOnScreen("imgs/nobuyorsell.png", confidence=0.9) if thing is not None: okbutton = cm.Point(thing.left + 169, thing.top + 194) cm.clickPoint(okbutton) return if loopidx % 5 == 0: cm.exportMyOrders() else: cm.sleep(0.5) loopidx += 1 if not os.listdir(marketlogsfolder)[-1].startswith('My Orders'): return refreshAllOrders() logfile = marketlogsfolder + "\\" + os.listdir(marketlogsfolder)[-1] neworders = [] try: with open(logfile) as export: reader = csv.DictReader(export) for l in reader: neworders.append( cm.Order(int(l['typeID']), int(l['orderID']), str(l['bid']) == "True", float(l['price']), int(float(l['volEntered'])), int(float(l['volRemaining'])), DateUtilParser(l['issueDate']).timestamp())) os.remove(logfile) except: cm.sleep(5) return refreshAllOrders() oldorders = [] for itemhandler in itemhandlerlist: ihcopy = copy.deepcopy(itemhandler) if ihcopy.buyorder is not None: oldorders.append(ihcopy.buyorder) if ihcopy.sellorderlist: oldorders += ihcopy.sellorderlist newfromoldorders = [] #the newfromoldorders list will contain every order even finished ones, the itemhandler will remove those in its handle func for oo in oldorders: curorder = copy.deepcopy(oo) for no in neworders: if areOrdersTheSame(oo, no): curorder.volremaining = no.volremaining if (curorder.volremaining > curorder.volentered): curorder.volremaining = curorder.volentered if (curorder.orderid == -1): curorder.orderid = no.orderid curorder.issuedate = no.issuedate break curorder.finished = ( not any(areOrdersTheSame(oo, no) for no in neworders) and cm.getEVETimestamp() - oo.issuedate > 20) newfromoldorders.append(curorder) #the order export can be heavily delayed sometimes, so we just add old orders that are freshly made for oo in oldorders: if (not any(areOrdersTheSame(nfo, oo) for nfo in newfromoldorders) and cm.getEVETimestamp() - oo.issuedate < 20): newfromoldorders.append(oo) #sort each neworder back into the itemhandlers for itemhandler in itemhandlerlist: itemhandler.sellorderlist = [] itemhandler.buyorder = None for nfo in newfromoldorders: if (itemhandler.typeid == nfo.typeid): if nfo.bid: itemhandler.buyorder = nfo else: itemhandler.sellorderlist.append(nfo)