def generateVtTick(row): '生成tick' tick = VtTickData() tick.symbol = row['code'] tick.exchange = generateExchange(tick.symbol) tick.vtSymbol = '.'.ljust([tick.symbol, tick.exchange]) tick.lastPrice = row['close'] tick.datetime = row.name tick.highPrice = row['high'] tick.lowPrice = row['low']
def processLine(self, line): historyData = line.split(',') #historyDataLen = len(historyData) symbol = historyData[2] #print 'processLine, symbol:' + symbol #从list转化为tick对象 historytick = VtTickData() historytick._id = historyData[0] historytick.gatewayName = 'CTP' historytick.symbol = symbol historytick.TradingDay = historyData[1] historytick.exchange = historyData[3] historytick.vtSymbol = historytick.symbol # '.'.join([tick.symbol, tick.exchange]) historytick.lastPrice = self.convertFloatZero(historyData[5]) #lastVolume historytick.volume = historyData[12] historytick.openInterest = historyData[14] UpdateMillisec = int(historyData[20]) historytick.time = '.'.join([historyData[19], str(UpdateMillisec/ 100)]) historytick.date = historyData[42] historytick.datetime = datetime.strptime(' '.join([historytick.date, historytick.time]), '%Y%m%d %H:%M:%S.%f') historytick.openPrice = self.convertFloatZero(historyData[9]) historytick.highPrice = self.convertFloatZero(historyData[10]) historytick.lowPrice = self.convertFloatZero(historyData[11]) historytick.preClosePrice = self.convertFloatZero(historyData[12]) historytick.ClosePrice = self.convertFloatZero(historyData[15]) historytick.SettlementPrice = self.convertFloatZero(historyData[16]) historytick.upperLimit = self.convertFloatZero(historyData[17]) historytick.lowerLimit = self.convertFloatZero(historyData[18]) # CTP只有一档行情 historytick.bidPrice1 = self.convertFloatZero(historyData[21]) historytick.bidVolume1 = historyData[22] historytick.askPrice1 = self.convertFloatZero(historyData[23]) historytick.askVolume1 = historyData[24] historytick.AveragePrice = self.convertFloatZero(historyData[41]) return historytick
def loadqlCsv(fileName, dbName, symbol): """将TB极速版导出的csv格式的历史分钟数据插入到Mongo数据库中""" import csv count = 0 start = time() print u'开始读取CSV文件%s中的数据插入到%s的%s中' % (fileName, dbName, symbol) # 锁定集合,并创建索引 client = pymongo.MongoClient(globalSetting['mongoHost'], globalSetting['mongoPort']) collection = client[dbName][symbol] collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True) # 读取数据和插入到数据库 reader = csv.reader(file(fileName, 'r')) for d in reader: tick = VtTickData() tick.vtSymbol = symbol tick.symbol = symbol tick.lastPrice = float(d[5]) tick.volume = int(d[6]) tick.openPrice = float(d[9]) tick.highPrice = float(d[7]) tick.lowPrice = float(d[8]) tick.preClosePrice = float(d[20]) tick.askPrice1 = float(d[12]) tick.bidPrice1 = float(d[14]) tick.askVolume1 = float(d[13]) tick.bidVolume1 = float(d[15]) count += 1 tick.date = datetime.strptime(d[2], '%Y%m%d').strftime('%Y%m%d') if d[4] == '500': tick.time = d[3] + "." + "500000" else: tick.time = d[3] + "." + "000000" tick.datetime = datetime.strptime(tick.date + ' ' + tick.time, '%Y%m%d %H:%M:%S.%f') flt = {'datetime': tick.datetime} collection.update_one(flt, {'$set': tick.__dict__}, upsert=True) print u'插入完毕,耗时:%s插入数量' % (time() - start), count
def generateVtTick(row, symbol): """生成K线""" tick = VtTickData() tick.symbol = symbol tick.vtSymbol = symbol tick.lastPrice = row['last'] tick.volume = row['volume'] tick.openInterest = row['open_interest'] tick.datetime = row.name tick.openPrice = row['open'] tick.highPrice = row['high'] tick.lowPrice = row['low'] tick.preClosePrice = row['prev_close'] tick.upperLimit = row['limit_up'] tick.lowerLimit = row['limit_down'] tick.bidPrice1 = row['b1'] tick.bidPrice2 = row['b2'] tick.bidPrice3 = row['b3'] tick.bidPrice4 = row['b4'] tick.bidPrice5 = row['b5'] tick.bidVolume1 = row['b1_v'] tick.bidVolume2 = row['b2_v'] tick.bidVolume3 = row['b3_v'] tick.bidVolume4 = row['b4_v'] tick.bidVolume5 = row['b5_v'] tick.askPrice1 = row['a1'] tick.askPrice2 = row['a2'] tick.askPrice3 = row['a3'] tick.askPrice4 = row['a4'] tick.askPrice5 = row['a5'] tick.askVolume1 = row['a1_v'] tick.askVolume2 = row['a2_v'] tick.askVolume3 = row['a3_v'] tick.askVolume4 = row['a4_v'] tick.askVolume5 = row['a5_v'] return tick
def generateVtTick(row, symbol): """生成K线""" tick = VtTickData() tick.symbol = symbol tick.vtSymbol = symbol tick.lastPrice = row['last'] tick.volume = row['volume'] tick.openInterest = row['open_interest'] tick.datetime = row.name tick.openPrice = row['open'] tick.highPrice = row['high'] tick.lowPrice = row['low'] tick.preClosePrice = row['prev_close'] tick.upperLimit = row['limit_up'] tick.lowerLimit = row['limit_down'] tick.bidPrice1 = row['b1'] tick.bidPrice2 = row['b2'] tick.bidPrice3 = row['b3'] tick.bidPrice4 = row['b4'] tick.bidPrice5 = row['b5'] tick.bidVolume1 = row['b1_v'] tick.bidVolume2 = row['b2_v'] tick.bidVolume3 = row['b3_v'] tick.bidVolume4 = row['b4_v'] tick.bidVolume5 = row['b5_v'] tick.askPrice1 = row['a1'] tick.askPrice2 = row['a2'] tick.askPrice3 = row['a3'] tick.askPrice4 = row['a4'] tick.askPrice5 = row['a5'] tick.askVolume1 = row['a1_v'] tick.askVolume2 = row['a2_v'] tick.askVolume3 = row['a3_v'] tick.askVolume4 = row['a4_v'] tick.askVolume5 = row['a5_v'] return tick