def generate_QBO(self, time, countdown, lob, verbose): if len(self.qbo_orders) < 1: self.active = False order = None else: osrid = self.qbo_orders[0].osrid biid = self.qbo_orders[0].order.orderid bi_order = self.qbo_orders[0].order qty = bi_order.qty price = bi_order.price limitprice = bi_order.limitprice MES = bi_order.MES subtype = 'QBO' # check if the order request has expired >0.5? if time - self.qbo_orders[0].time > 0.5: self.active = False order = Order(self.tid, self.job, "CAN", price, qty, time, None, -1, limitprice, MES, subtype, None, osrid) else: self.active = True total_price = 0 total_qty = 0 for trn in self.qbo_orders[0].trns: total_price += trn['price']*trn['qty'] total_qty += trn['qty'] # price = total_price/total_qty # qty = random.randint(total_qty, qty) order = Order(self.tid, self.job, "LIM", price, qty, time, None, -1, limitprice, MES, subtype, 'Drk', osrid, biid) self.lastquote = order order.myref = bi_order.myref del self.qbo_orders[0] return order
def getorder(self, time, countdown, lob, verbose): if verbose: print('ZIP getorder(): LOB=%s' % lob) # random coefficient, multiplier on trader's own estimate of worst possible bid/ask prices # currently in arbitrarily chosen range [2, 5] worst_coeff = 2 + (3 * random.random()) if len(self.orders) < 1: self.active = False order = None else: self.active = True self.limit = self.orders[0].price self.job = self.orders[0].atype if self.job == 'Bid': # currently a buyer (working a bid order) self.margin = self.margin_buy # what is the worst bid price on the LOB right now? if len(lob['bids']['lob']) > 0 : # take price of final entry on LOB worst_bid = lob['bids']['lob'][-1][0] else: # local pessimistic estimate of the worst bid price (own version of stub quote) worst_bid = max(1, int(self.limit / worst_coeff)) if self.worst_bidprice == None: self.worst_bidprice = worst_bid elif self.worst_bidprice > worst_bid: self.worst_bidprice = worst_bid else: # currently a seller (working a sell order) self.margin = self.margin_sell # what is the worst ask price on the LOB right now? if len(lob['asks']['lob']) > 0 : # take price of final entry on LOB worst_ask = lob['asks']['lob'][-1][0] else: # local pessimistic estimate of the worst ask price (own version of stub quote) worst_ask = int(self.limit * worst_coeff) if self.worst_askprice == None: self.worst_askprice = worst_ask elif self.worst_askprice < worst_ask: self.worst_askprice = worst_ask quoteprice = int(self.limit * (1 + self.margin)) self.price = quoteprice # set limitprice and MES limitprice = quoteprice MES = 0 marketid = None # only big block order can be BI or BDN order subtype = None big_block = 200 # cancel BI order when its reputation is lower than threshold threshold = 50 if self.reputation < threshold: self.biweight = 0 if self.orders[0].qty >= big_block: subtype = random.choices(population=['BI','BDN', None],weights=[0.5, 0.5, 0],k=1)[0] order = Order(self.tid, self.job, "LIM", quoteprice, self.orders[0].qty, time, None, -1, limitprice, MES, subtype, marketid) order.myref = self.orders[0].assignmentid if self.orders[0].qty < big_block: print('Why') if subtype != 'BI': self.lastquote = order return order