def tickPrice(self, tickerId: TickerId, tickType: TickType, price: float, attrib): super().tickPrice(tickerId, tickType, price, attrib) # print(current_fn_name(), vars()) # bid是指卖出外汇的价格,即我要卖出外汇,标一个价格为bid。 # ask是指买入外汇的价格,即我要买入外汇,询问得价格为ask。 if (tickerId == 9005 and TickTypeEnum.to_str(tickType) == "BID" and self.USD_HKD_BID != 0): self.USD_HKD_BID = price elif (tickerId == 9005 and TickTypeEnum.to_str(tickType) == "ASK" and self.USD_HKD_ASK != 0): self.USD_HKD_ASK = price # print(current_fn_name(), tickerId, TickTypeEnum.to_str(tickType), price, attrib, file=sys.stderr) elif (tickerId == 9006 and TickTypeEnum.to_str(tickType) == "BID" and self.CNH_HKD_BID != 0): self.CNH_HKD_BID = price elif (tickerId == 9006 and TickTypeEnum.to_str(tickType) == "ASK" and self.CNH_HKD_ASK != 0): self.CNH_HKD_ASK = price print(current_fn_name(), tickerId, TickTypeEnum.to_str(tickType), price, attrib, file=sys.stderr)
def tickPrice(self, reqId ,tickType, price,attrib): if tickType == 68: myDict['68'] = price print(TickTypeEnum.to_str(tickType), price) if len(myDict) > 4: self.processTickLine() #myDict['68'] = float(price) #dict['School'] = "DPS School"; # Add new entry print(TickTypeEnum.to_str(tickType), price) #print(app.reqCurrentTime()) #print(app.twsConnectionTime()) if tickType == 72:#Este tickType solo viene cuando cerro el mercado myDict['72'] = price print(TickTypeEnum.to_str(tickType), price) if tickType == 73:#Este tickType solo viene cuando cerro el mercado myDict['73'] = price print(TickTypeEnum.to_str(tickType), price) if tickType == 75:#Este tickType solo viene una vez myDict['75'] = price print(TickTypeEnum.to_str(tickType), price) #print("paso por el 75") if len(myDict) > 4: self.processTickLine()
def tickPrice(self, reqId, tickType, price, attrib): global line1 global line2 global line3 global line4 global line5 global values if tickType == 68: line1 = int(price) #line1 = TickTypeEnum.to_str(tickType) + str(price) #self.processTickLine(line) print(TickTypeEnum.to_str(tickType), price) if tickType == 72: line2 = int(price) #line2 = TickTypeEnum.to_str(tickType) + str(price) #self.processTickLine(line) print(TickTypeEnum.to_str(tickType), price) if tickType == 73: line3 = int(price) #line3 = TickTypeEnum.to_str(tickType) + str(price) #self.processTickLine(line) print(TickTypeEnum.to_str(tickType), price) if tickType == 75: line4 = int(price) #line4 = TickTypeEnum.to_str(tickType) + str(price) #self.processTickLine(line) print(TickTypeEnum.to_str(tickType), price) else: line4 = 0
def tickPrice(self, req_id, tick_type, price, attrib): # print("Id:", req_id, "Type:", TickTypeEnum.to_str(tick_type), "Price:", price, end=' ') ticker_id = req_id if TickTypeEnum.to_str(tick_type) == 'BID' or TickTypeEnum.to_str( tick_type) == 'ASK' or TickTypeEnum.to_str( tick_type) == 'LAST' or TickTypeEnum.to_str( tick_type) == 'CLOSE': self.output_df.loc[ticker_id, TickTypeEnum.to_str(tick_type)] = price
def tickSize(self, reqId, tickType, size): insertSql = """ insert into tick_market_data values ({tickerId}, CURRENT_TIMESTAMP, "{tickType}", {price}) """.format(tickerId=reqId, tickType=TickTypeEnum.to_str(tickType), price=size) #print(insertSql) print('tickSize: ', reqId, TickTypeEnum.to_str(tickType)) self.dbConn.execute(insertSql) self.dbConn.commit()
def tickSize(self, reqId, tickType, size): self.sqlLink.insertRow(self.sizeTableNameIndex[reqId], "Size", size, "quote_type", TickTypeEnum.to_str(tickType)) print("Ticker Size. Ticker Id:", reqId, " Table Name:", self.sizeTableNameIndex[reqId], "ticktype:", TickTypeEnum.to_str(tickType), "Size:", size, end='\n')
def tickPrice(self, tickerId: TickerId, tickType: TickType, price: float, attrib): super().tickPrice(tickerId, tickType, price, attrib) print(current_fn_name(), tickerId, TickTypeEnum.to_str(tickType), price, attrib, file=sys.stderr) #tickPrice 1001 LAST 264.42 0,0 if (TickTypeEnum.to_str(tickType) == 'LAST'): self.cDataPrice = price
def tickSize(self, reqId, tickType, size): if tickType == 74: line5 = TickTypeEnum.to_str(tickType) + str(size) #self.processTickLine(line) print("Tick Size.Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Size:", size) values = [line1, line2, line3, line4, line5] for i in values: if i == None: return else: self.processTickLine(values)
def tickPrice(self, reqId, tickType, price, attribute): self.file.write("ticktype:" + TickTypeEnum.to_str(tickType) + ", Price:" + str(price) + "\n") self.file.flush() os.fsync(self.file.fileno()) print("Ticker Price. Ticker Id:", reqId, "ticktype:", TickTypeEnum.to_str(tickType), "Price:", price, end='\n')
def tickPrice(self, reqId, tickType, price, attribute): self.sqlLink.insertRow(self.priceTableNameIndex[reqId], "price", price, "quote_type", TickTypeEnum.to_str(tickType)) print("Ticker Price. Ticker Id:", reqId, " Table Name:", self.priceTableNameIndex[reqId], "ticktype:", TickTypeEnum.to_str(tickType), "Price:", price, "Attribute", attribute, end='\n')
def tickOptionComputation( self, reqId: int, tickType: TickType, impliedVol: float, delta: float, optPrice: float, pvDividend: float, gamma: float, vega: float, theta: float, undPrice: float, ): log.info("Running...") log.info(reqId) log.debug(locals()) obs: Observable[Any] = self.state.getObservable(reqId) obs.on_next( { "tickType": TickTypeEnum.to_str(tickType), "impliedVolatility": impliedVol, "optPrice": optPrice, "undPrice": undPrice, "pvDividend": pvDividend, "delta": delta, "gamma": gamma, "vega": vega, "theta": theta, } )
def tickPrice(self, reqId, tickType, price, attrib): if tickType == 68: line = TickTypeEnum.to_str(tickType) + str(price) self.processTickLine(line) #print(TickTypeEnum.to_str(tickType), price) if tickType == 72: line = TickTypeEnum.to_str(tickType) + str(price) self.processTickLine(line) #print(TickTypeEnum.to_str(tickType), price) if tickType == 73: line = TickTypeEnum.to_str(tickType) + str(price) self.processTickLine(line) #print(TickTypeEnum.to_str(tickType), price) if tickType == 75: line = TickTypeEnum.to_str(tickType) + str(price) self.processTickLine(line)
def tickSize(self, tickerId: TickerId, tickType: TickType, size: int): super().tickSize(tickerId, tickType, size) print(current_fn_name(), tickerId, TickTypeEnum.to_str(tickType), size, file=sys.stderr)
def tickPrice(self, tickerId: TickerId, tickType: TickType, price: float, attrib): symbol = self.marketDataLookup[tickerId] self.Logger.info('%s %s %s %s IB' % (datetime.datetime.now(), symbol, TickTypeEnum.to_str(tickType), price)) if tickerId in self.requestedMarketData: del self.requestedMarketData[tickerId]
def tickPrice(self, reqId, tickType, price, attrib): print("Tick Price. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, end=' ')
def tickPrice(self, reqId, tickType, price, attrib): print('Tick Price.Ticker Id:', reqId, 'tickType:', TickTypeEnum.to_str(tickType), 'Price:', price, end=' ')
def tickPrice(self, reqId, tickType, price, attrib): print("Ticker Price Data: Ticket ID: ", reqId, " ", "tickType: ", TickTypeEnum.to_str(tickType), "Price: ", price, end=" ")
def tickPrice(self, tickerId: TickerId, tickType: TickType, price: float, attrib): super().tickPrice(tickerId, tickType, price, attrib) print(current_fn_name(), tickerId, TickTypeEnum.to_str(tickType), price, attrib, file=sys.stderr)
def tickSize(self, tickerId: TickerId, tickType: TickType, size: int): super().tickSize(tickerId, tickType, size) print("Tick Size, Ticker Id:", tickerId, "tickType:", TickTypeEnum.to_str(tickType), "Size:", size, file=sys.stderr)
def tickPrice(self, reqId: TickerId, tickType: TickType, price: float, attrib: TickAttrib): print("Tick Price. Ticker Id:", reqId, "tick type:", TickTypeEnum.to_str(tickType), "Price:", price, end=" ")
def tickPrice(self, reqId ,tickType, price,attrib): if tickType == 68: myDict['68'] = price print(TickTypeEnum.to_str(tickType),"Price:", price) if len(myDict) > 4: self.processTickLine() if tickType == 72:#Este tickType solo viene cuando cerro el mercado myDict['72'] = price print(TickTypeEnum.to_str(tickType),"Price:", price) if tickType == 73:#Este tickType solo viene cuando cerro el mercado myDict['73'] = price print(TickTypeEnum.to_str(tickType),"Price:", price) if tickType == 75:#Este tickType solo viene una vez myDict['75'] = price print(TickTypeEnum.to_str(tickType),"Price:", price) if len(myDict) > 4: self.processTickLine()
def tickPrice(self, reqId, tickType, price, attrib): if tickType == 4: myDict['4'] = price print(TickTypeEnum.to_str(tickType), "Price:", price) if len(myDict) > 4: self.processTickLine() if tickType == 6: #Este tickType solo viene cuando cerro el mercado myDict['6'] = price print(TickTypeEnum.to_str(tickType), "Price:", price) if tickType == 7: #Este tickType solo viene cuando cerro el mercado myDict['7'] = price print(TickTypeEnum.to_str(tickType), "Price:", price) if tickType == 9: #Este tickType solo viene una vez myDict['9'] = price print(TickTypeEnum.to_str(tickType), "Price:", price) if len(myDict) > 4: self.processTickLine()
def tickSize(self, reqId, tickType, size): if tickType == 74: line5 = int(size) #line5 = TickTypeEnum.to_str(tickType) + str(size) #self.processTickLine(line) print("Tick Size.Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Size:", size) if line1 != None and line2 != None and line3 != None and line4 != None and line5 != None: self.processTickLine(line1, line2, line3, line4, line5) else: print("paso por aqui")
def tickPrice(self, reqId, tickType, price, attribute): #self.file.write("ticktype:"+TickTypeEnum.to_str(tickType)+", Price:"+str(price)+"\n") #self.file.flush() #os.fsync(self.file.fileno()) #self.sqlLink.insertRow('USD.CAD', "price", price, "quote_type", TickTypeEnum.to_str(tickType)) print("Ticker Price. Ticker Id:", reqId, "ticktype:", TickTypeEnum.to_str(tickType), "Price:", price, end='\n')
def tickPrice(self, reqId, tickType, price, attrib): global contador print("Tick Price. Ticket Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, end='') if contador == 5: self.disconnect() else: contador += 1
def tickPrice(self, tickerId: TickerId, tickType: TickType, price: float, attrib): super().tickPrice(tickerId, tickType, price, attrib) print("Tick Price, Ticker Id:", tickerId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, " Time:", attrib.time, file=sys.stderr, end=" ")
def tickPrice(self, reqId, BID, price, attrib): # EWrapper Function f = open("./marketData/priceAppleStock3.txt", "a") #Con este append 'a' agrega los datos uno tras otro print("Tick Price. Ticket Id:", reqId, "tickType:", TickTypeEnum.to_str(BID), "Price:", price, end='') #f.write(str("Tick Price. Ticket Id:",reqId,"tickType:",TickTypeEnum.to_str(tickType),"Price:",price, end='')) f.write(str(price)) f.write(" ")
def tickPrice(self, reqId ,tickType, price,attrib): if tickType == 68: line1 = float(price) print(TickTypeEnum.to_str(tickType), price) print("paso por el 68") # else: # line1 = 0 if tickType == 72: line2 = float(price) print(TickTypeEnum.to_str(tickType), price) print("paso por el 72") #else: # line2 = 0 if tickType == 73: line3 = float(price) print(TickTypeEnum.to_str(tickType), price) print("paso por el 73") #else: # line3 = 0 if tickType == 75: line4 = float(price) print(TickTypeEnum.to_str(tickType), price) print("paso por el 75")
def tickPrice(self, reqId, tickType, price, attrib): # print(f"Ticket ID: {reqId} tickType: {TickTypeEnum.to_str(tickType)} Price: {price}", end="\n") stock_dick[reqId] = price # print only indeces data ''' NASDAQ = 55555 DOW = 77777 SNP = 88888 VIX = 11111 R2K = 22222 ''' if reqId > 10000: if tickType == 9 or tickType == 37 or tickType == 4: # 37 = MARK_PRICE, 4 = LAST_PRICE, 9 = CLOSE print("Ticker Price Data: Ticket ID: ", reqId, " ","tickType: ", TickTypeEnum.to_str(tickType), "Price: ", price, end="\n") # Tick types: https://interactivebrokers.github.io/tws-api/tick_types.html # Extracting Previous Close price if tickType == 9: # stock_close[reqId] = price if reqId < 10000: stock = StockData.objects.get(id=reqId) stock.prev_close = price stock.save() # Updating Indices DB else: index = IndicesData.objects.get(index_api_id=reqId) # print(f'INDEX: {reqId} PREV_PRICE: {price}') index.index_prev_close = price index.save() # REPLACED WITH SCRAPER -- # Setting last value to index if tickType == 37 and reqId > 10000: index = IndicesData.objects.get(index_api_id=reqId) # print(f'INDEX: {reqId} CURRENT_PRICE: {price}') index.index_current_value = price index.save() # Extracting Open price if tickType == 14: if reqId < 10000: stock = StockData.objects.get(id=reqId) stock.todays_open = price stock.save()
def tickPrice(self, reqId, tickType, price, attrib): print("TickPrice. TickerId:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, "CanAutoExecute:", attrib.canAutoExecute, "PastLimit:", attrib.pastLimit, end=' ') # update stocks tracking table if TickTypeEnum.BID == tickType or TickTypeEnum.DELAYED_BID == tickType: update_price(reqId, 'bid', price) if TickTypeEnum.ASK == tickType or TickTypeEnum.DELAYED_ASK == tickType: update_price(reqId, 'ask', price) if TickTypeEnum.LAST == tickType or TickTypeEnum.DELAYED_LAST == tickType: update_price(reqId, 'last_price', price) if tickType == TickTypeEnum.BID or tickType == TickTypeEnum.ASK: print("PreOpen:", attrib.preOpen) else: print()