def fileLineToBar(line): bar_data = line.split(',') bar = VtBarData() bar.symbol = bar_data[0] bar.vtSymbol = bar_data[1] bar.exchange = bar_data[2] bar.open = float(bar_data[3]) bar.high = float(bar_data[4]) bar.low = float(bar_data[5]) bar.close = float(bar_data[6]) bar.date = bar_data[7] bar.time = bar_data[8] bar.datetime = datetime.strptime(bar_data[9], "%Y-%m-%d %H:%M:%S") bar.volume = int(bar_data[10]) bar.openInterest = int(bar_data[11]) bar.TradingDay = bar_data[12] return bar
def mongodbRowToBar(row_bar): bar = VtBarData() bar.symbol = row_bar['symbol'] bar.vtSymbol = row_bar['symbol'] bar.exchange = row_bar['exchange'] bar.open = float(row_bar['open']) bar.high = float(row_bar['high']) bar.low = float(row_bar['low']) bar.close = float(row_bar['close']) bar.date = row_bar['date'] bar.time = row_bar['time'] #bar.datetime = datetime.strptime(row_bar['datetime'], "%Y-%m-%d %H:%M:%S") bar.datetime = row_bar['datetime'] bar.volume = int(row_bar['volume']) bar.openInterest = int(row_bar['openInterest']) bar.TradingDay = row_bar['TradingDay'] return bar
def handleDayBar(self, bar): contact_ = bar.vtSymbol today = todayDate() todayStr = today.strftime("%Y%m%d") d = {'TradingDay': todayStr} barData = self.mainEngine.dbQuery(MINUTE_60_DB_NAME, contact_, d, 'TradingDay') day_bar = None for bar in barData: # 尚未创建对象 if not day_bar: day_bar = VtBarData() day_bar.vtSymbol = bar['vtSymbol'] day_bar.symbol = bar['symbol'] day_bar.exchange = bar['exchange'] day_bar.open = bar['open'] day_bar.high = bar['high'] day_bar.low = bar['low'] # 累加老K线 else: day_bar.high = max(day_bar.high, bar['high']) day_bar.low = min(day_bar.low, bar['low']) # 通用部分 day_bar.close = bar['close'] day_bar.datetime = bar['datetime'] day_bar.TradingDay = bar['TradingDay'] day_bar.openInterest = bar['openInterest'] day_bar.volume += int(bar['volume']) if day_bar: day_bar.datetime = datetime(today.year, today.month, today.day) day_bar.date = day_bar.datetime.strftime('%Y%m%d') day_bar.time = day_bar.datetime.strftime('%H:%M:%S.%f') self.mainEngine.dbInsert(DAY_DB_NAME, contact_, day_bar.__dict__)