Example #1
0
 def translate_tick_record(self, r):
     
     if r.entryType == '2': #TRADE
         r = r._replace(
             date = qtemporal.from_raw_qtemporal(r.date, qtype.QDATE).astype(datetime),
             tradeDate = qtemporal.from_raw_qtemporal(r.tradeDate, qtype.QDATE).astype(datetime),
             time = utils.dt64_to_dt_local(qtemporal.from_raw_qtemporal(r.time, qtype.QTIMESTAMP)),
             settleDate = qtemporal.from_raw_qtemporal(r.settleDate, qtype.QDATE),
             entryTime = utils.dt64_to_dt_local(qtemporal.from_raw_qtemporal(r.entryTime, qtype.QTIMESTAMP)),
             priceLevel = 0,
             numOrders = 0,
             tradingSessionID = 0,
             openCloseSettleFlag = 0,
             quoteType = 0,
             price = float(r.price)
         )
     elif r.entryType == '0' or r.entryType == '1': #QUOTE
         r = r._replace(
             date = qtemporal.from_raw_qtemporal(r.date, qtype.QDATE).astype(datetime),
             tradeDate = qtemporal.from_raw_qtemporal(r.tradeDate, qtype.QDATE).astype(datetime),
             time = utils.dt64_to_dt_local(qtemporal.from_raw_qtemporal(r.time, qtype.QTIMESTAMP)),
             settleDate = qtemporal.from_raw_qtemporal(r.settleDate, qtype.QDATE),
             entryTime = utils.dt64_to_dt_local(qtemporal.from_raw_qtemporal(r.entryTime, qtype.QTIMESTAMP)),
             tickDirection=0,
             openCloseSettleFlag=0,
             tradeVolume=0,
             quoteType=0,
             aggressorSide=0,
             tradeID=0,
             price = float(r.price),
             size = int(r.size),
             numOrders = int(r.numOrders)
         )
     
     return r
Example #2
0
 def _read_temporal(self, qtype):
     try:
         fmt = STRUCT_MAP[qtype]
         conversion = FROM_Q[qtype]
         return from_raw_qtemporal(conversion(self._buffer.get(fmt)), qtype = qtype)
     except KeyError:
         raise QReaderException('Unable to deserialize q type: %s' % hex(qtype))
Example #3
0
 def _read_temporal(self, qtype):
     try:
         fmt = STRUCT_MAP[qtype]
         conversion = PY_TYPE[qtype]
         temporal = from_raw_qtemporal(conversion(self._buffer.get(fmt)), qtype = qtype)
         return temporal if self._options.numpy_temporals else qtemporal(temporal, qtype = qtype)
     except KeyError:
         raise QReaderException('Unable to deserialize q type: %s' % hex(qtype))
Example #4
0
 def _read_temporal(self, qtype, options):
     try:
         fmt = STRUCT_MAP[qtype]
         conversion = PY_TYPE[qtype]
         temporal = from_raw_qtemporal(conversion(self._buffer.get(fmt)), qtype = qtype)
         return temporal if options.numpy_temporals else qtemporal(temporal, qtype = qtype)
     except KeyError:
         raise QReaderException('Unable to deserialize q type: %s' % hex(qtype))
def init_kdb(stock_id, source, db_name, q):
	if db_name =='volume':
		for data in source:
			query = '`volume insert(`' + str(stock_id) + '; ' + str(from_raw_qtemporal(data[3], qtype=QDATE)).replace('-','.') + '; 0n; 0n; 0n; 0n; 0n; 0n)'
			df = q(query)
	elif db_name == 'trending':
		for data in source:
			query = '`trending insert(`' + str(stock_id) + '; ' + str(from_raw_qtemporal(data[3], qtype=QDATE)).replace('-','.') + '; 0n; 0n; 0n; 0n; 0n)'
			df = q(query)
	elif db_name == 'momentum':
		for data in source:
			query = '`momentum insert(`' + str(stock_id) + '; ' + str(from_raw_qtemporal(data[3], qtype=QDATE)).replace('-','.') + '; 0n; 0n; 0n)'
			df = q(query)
	elif db_name == 'resource':
		for data in source:
			query = '`resource insert(`' + str(stock_id) + '; ' + str(from_raw_qtemporal(data[3], qtype=QDATE)).replace('-','.') + '; 0n; 0n)'
			df = q(query)
Example #6
0
 def __getitem__(self, idx):
     return from_raw_qtemporal(numpy.ndarray.__getitem__(self, idx), -abs(self.meta.qtype))
Example #7
0
 def __getitem__(self, idx):
     return qtemporal(from_raw_qtemporal(numpy.ndarray.__getitem__(self, idx), -abs(self.meta.qtype)), qtype = -abs(self.meta.qtype))