本文整理汇总了Python中vnpy.trader.vtObject.VtBarData.time方法的典型用法代码示例。如果您正苦于以下问题:Python VtBarData.time方法的具体用法?Python VtBarData.time怎么用?Python VtBarData.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vnpy.trader.vtObject.VtBarData
的用法示例。
在下文中一共展示了VtBarData.time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadTdxCsv
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def loadTdxCsv(fileName, dbName, symbol):
"""将通达信导出的csv格式的历史分钟数据插入到Mongo数据库中"""
import csv
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:
bar = VtBarData()
bar.vtSymbol = symbol
bar.symbol = symbol
bar.open = float(d[2])
bar.high = float(d[3])
bar.low = float(d[4])
bar.close = float(d[5])
bar.date = datetime.strptime(d[0], '%Y/%m/%d').strftime('%Y%m%d')
bar.time = d[1][:2]+':'+d[1][2:4]+':00'
bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S')
bar.volume = d[6]
bar.openInterest = d[7]
flt = {'datetime': bar.datetime}
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
print bar.date, bar.time
print u'插入完毕,耗时:%s' % (time()-start)
示例2: loadRqBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def loadRqBar(self, symbol, days):
"""从RQData加载K线数据"""
endDate = datetime.now()
startDate = endDate - timedelta(days)
df = self.rq.get_price(symbol.upper(),
frequency='1m',
fields=['open', 'high', 'low', 'close', 'volume'],
start_date=startDate,
end_date=endDate)
l = []
for ix, row in df.iterrows():
bar = VtBarData()
bar.symbol = symbol
bar.vtSymbol = symbol
bar.open = row['open']
bar.high = row['high']
bar.low = row['low']
bar.close = row['close']
bar.volume = row['volume']
bar.datetime = row.name
bar.date = bar.datetime.strftime("%Y%m%d")
bar.time = bar.datetime.strftime("%H:%M:%S")
l.append(bar)
return l
示例3: loadOKEXCsv
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def loadOKEXCsv(fileName, dbName, symbol):
"""将OKEX导出的csv格式的历史分钟数据插入到Mongo数据库中"""
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(open(fileName,"r"))
for d in reader:
if len(d[1]) > 10:
bar = VtBarData()
bar.vtSymbol = symbol
bar.symbol = symbol
bar.datetime = datetime.strptime(d[1], '%Y-%m-%d %H:%M:%S')
bar.date = bar.datetime.date().strftime('%Y%m%d')
bar.time = bar.datetime.time().strftime('%H:%M:%S')
bar.open = float(d[2])
bar.high = float(d[3])
bar.low = float(d[4])
bar.close = float(d[5])
bar.volume = float(d[6])
bar.tobtcvolume = float(d[7])
flt = {'datetime': bar.datetime}
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
print('%s \t %s' % (bar.date, bar.time))
print u'插入完毕,耗时:%s' % (time()-start)
示例4: loadMcCsv
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def loadMcCsv(fileName, dbName, symbol):
"""将Multicharts导出的csv格式的历史数据插入到Mongo数据库中"""
import csv
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.DictReader(file(fileName, 'r'))
for d in reader:
bar = VtBarData()
bar.vtSymbol = symbol
bar.symbol = symbol
bar.open = float(d['Open'])
bar.high = float(d['High'])
bar.low = float(d['Low'])
bar.close = float(d['Close'])
bar.date = datetime.strptime(d['Date'], '%Y-%m-%d').strftime('%Y%m%d')
bar.time = d['Time']
bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S')
bar.volume = d['TotalVolume']
flt = {'datetime': bar.datetime}
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
print bar.date, bar.time
print u'插入完毕,耗时:%s' % (time()-start)
示例5: onTick
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def onTick(self, tick):
"""收到行情TICK推送(必须由用户继承实现)"""
# 计算K线
tickMinute = tick.datetime.minute
if tickMinute != self.barMinute:
if self.bar:
self.onBar(self.bar)
bar = VtBarData()
bar.vtSymbol = tick.vtSymbol
bar.symbol = tick.symbol
bar.exchange = tick.exchange
bar.open = tick.lastPrice
bar.high = tick.lastPrice
bar.low = tick.lastPrice
bar.close = tick.lastPrice
bar.date = tick.date
bar.time = tick.time
bar.datetime = tick.datetime # K线的时间设为第一个Tick的时间
self.bar = bar # 这种写法为了减少一层访问,加快速度
self.barMinute = tickMinute # 更新当前的分钟
else: # 否则继续累加新的K线
bar = self.bar # 写法同样为了加快速度
bar.high = max(bar.high, tick.lastPrice)
bar.low = min(bar.low, tick.lastPrice)
bar.close = tick.lastPrice
示例6: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(row):
"""生成K线"""
bar = VtBarData()
symbol, exchange = row['symbol'].split('.')
bar.symbol = symbol
bar.exchange = exchangeMapReverse[exchange]
if bar.exchange in ['SSE', 'SZSE']:
bar.vtSymbol = '.'.join([bar.symbol, bar.exchange])
else:
bar.vtSymbol = bar.symbol
bar.open = row['open']
bar.high = row['high']
bar.low = row['low']
bar.close = row['close']
bar.volume = row['volume']
bar.date = str(row['date'])
bar.time = str(row['time']).rjust(6, '0')
#将bar的时间改成提前一分钟
hour=bar.time[0:2]
minute=bar.time[2:4]
sec=bar.time[4:6]
if minute=="00":
minute="59"
h = int(hour)
if h == 0:
h = 24
hour=str(h-1).rjust(2,'0')
else:
minute=str(int(minute)-1).rjust(2,'0')
bar.time=hour+minute+sec
bar.datetime = datetime.strptime(' '.join([bar.date, bar.time]), '%Y%m%d %H%M%S')
return bar
示例7: downloadEquityDailyBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def downloadEquityDailyBar(self, symbol):
"""
下载股票的日行情,symbol是股票代码
"""
print u'开始下载%s日行情' %symbol
# 查询数据库中已有数据的最后日期
cl = self.dbClient[DAILY_DB_NAME][symbol]
cx = cl.find(sort=[('datetime', pymongo.DESCENDING)])
if cx.count():
last = cx[0]
else:
last = ''
# 开始下载数据
path = 'api/market/getMktEqud.json'
params = {}
params['ticker'] = symbol
if last:
params['beginDate'] = last['date']
data = self.datayesClient.downloadData(path, params)
if data:
# 创建datetime索引
self.dbClient[DAILY_DB_NAME][symbol].ensure_index([('datetime', pymongo.ASCENDING)],
unique=True)
for d in data:
bar = VtBarData()
bar.vtSymbol = symbol
bar.symbol = symbol
try:
bar.exchange = DATAYES_TO_VT_EXCHANGE.get(d.get('exchangeCD', ''), '')
bar.open = d.get('openPrice', 0)
bar.high = d.get('highestPrice', 0)
bar.low = d.get('lowestPrice', 0)
bar.close = d.get('closePrice', 0)
bar.date = d.get('tradeDate', '').replace('-', '')
bar.time = ''
bar.datetime = datetime.strptime(bar.date, '%Y%m%d')
bar.volume = d.get('turnoverVol', 0)
except KeyError:
print d
flt = {'datetime': bar.datetime}
self.dbClient[DAILY_DB_NAME][symbol].update_one(flt, {'$set':bar.__dict__}, upsert=True)
print u'%s下载完成' %symbol
else:
print u'找不到合约%s' %symbol
示例8: downloadEquityDailyBarts
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def downloadEquityDailyBarts(self, symbol):
"""
下载股票的日行情,symbol是股票代码
"""
print u'开始下载%s日行情' %symbol
# 查询数据库中已有数据的最后日期
cl = self.dbClient[DAILY_DB_NAME][symbol]
cx = cl.find(sort=[('datetime', pymongo.DESCENDING)])
if cx.count():
last = cx[0]
else:
last = ''
# 开始下载数据
import tushare as ts
if last:
start = last['date'][:4]+'-'+last['date'][4:6]+'-'+last['date'][6:]
data = ts.get_k_data(symbol,start)
if not data.empty:
# 创建datetime索引
self.dbClient[DAILY_DB_NAME][symbol].ensure_index([('datetime', pymongo.ASCENDING)],
unique=True)
for index, d in data.iterrows():
bar = VtBarData()
bar.vtSymbol = symbol
bar.symbol = symbol
try:
bar.open = d.get('open')
bar.high = d.get('high')
bar.low = d.get('low')
bar.close = d.get('close')
bar.date = d.get('date').replace('-', '')
bar.time = ''
bar.datetime = datetime.strptime(bar.date, '%Y%m%d')
bar.volume = d.get('volume')
except KeyError:
print d
flt = {'datetime': bar.datetime}
self.dbClient[DAILY_DB_NAME][symbol].update_one(flt, {'$set':bar.__dict__}, upsert=True)
print u'%s下载完成' %symbol
else:
print u'找不到合约%s' %symbol
示例9: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(row, symbol):
"""生成K线"""
bar = VtBarData()
bar.symbol = symbol
bar.vtSymbol = symbol
bar.open = row['open']
bar.high = row['high']
bar.low = row['low']
bar.close = row['close']
bar.volume = row['volume']
bar.datetime = row.name
bar.date = bar.datetime.strftime("%Y%m%d")
bar.time = bar.datetime.strftime("%H:%M:%S")
return bar
示例10: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(symbol, d):
"""生成K线"""
bar = VtBarData()
bar.symbol = symbol
bar.vtSymbol = symbol
bar.datetime = datetime.datetime.strptime(d['time_open'], '%Y-%m-%dT%H:%M:%S.%f0Z')
bar.date = bar.datetime.strftime('%Y%m%d')
bar.time = bar.datetime.strftime('%H:%M:%S')
bar.open = d['price_open']
bar.high = d['price_high']
bar.low = d['price_low']
bar.close = d['price_close']
bar.volume = d['volume_traded']
return bar
示例11: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(row):
"""生成K线"""
bar = VtBarData()
bar.symbol = row['code']
bar.exchange = generateExchange(bar.symbol)
bar.vtSymbol = '.'.join([bar.symbol, bar.exchange])
bar.open = row['open']
bar.high = row['high']
bar.low = row['low']
bar.close = row['close']
bar.volume = row['vol']
bar.datetime = row.name
bar.date = bar.datetime.strftime("%Y%m%d")
bar.time = bar.datetime.strftime("%H:%M:%S")
return bar
示例12: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(d):
"""生成K线"""
bar = VtBarData()
bar.symbol = d['symbol']
bar.vtSymbol = d['symbol']
bar.date = d['date']
bar.time = ':'.join([d['time'][:2], d['time'][2:]])
bar.open = d['open']
bar.high = d['high']
bar.low = d['low']
bar.close = d['close']
bar.volume = d['volume']
bar.openInterest = d['openInterest']
bar.datetime = datetime.datetime.strptime(' '.join([bar.date, bar.time]), '%Y%m%d %H:%M')
return bar
示例13: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(vtSymbol, d):
"""生成K线"""
bar = VtBarData()
bar.vtSymbol = vtSymbol
bar.symbol, bar.exchange = bar.vtSymbol.split('.')
bar.datetime = datetime.datetime.fromtimestamp(d['time'])
bar.date = bar.datetime.strftime('%Y%m%d')
bar.time = bar.datetime.strftime('%H:%M:%S')
bar.open = d['open']
bar.high = d['high']
bar.low = d['low']
bar.close = d['close']
bar.volume = d['volumeto']
return bar
示例14: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(symbol, d):
"""生成K线"""
l = symbol.split('_')
bar = VtBarData()
bar.symbol = l[-2] + l[-1]
bar.exchange = l[0]
bar.vtSymbol = '/'.join([bar.symbol, bar.exchange])
bar.datetime = datetime.datetime.strptime(d['time_open'], '%Y-%m-%dT%H:%M:%S.%f0Z')
bar.date = bar.datetime.strftime('%Y%m%d')
bar.time = bar.datetime.strftime('%H:%M:%S')
bar.open = d['price_open']
bar.high = d['price_high']
bar.low = d['price_low']
bar.close = d['price_close']
bar.volume = d['volume_traded']
return bar
示例15: generateVtBar
# 需要导入模块: from vnpy.trader.vtObject import VtBarData [as 别名]
# 或者: from vnpy.trader.vtObject.VtBarData import time [as 别名]
def generateVtBar(symbol, d):
"""生成K线"""
bar = VtBarData()
bar.symbol = symbol
bar.vtSymbol = symbol
bar.open = d['open']
bar.high = d['high']
bar.low = d['low']
bar.close = d['close']
bar.volume = d['volume']
bar.openInterest = d['open_oi']
bar.datetime = datetime.fromtimestamp(d['datetime']/1000000000)
bar.date = bar.datetime.strftime("%Y%m%d")
bar.time = bar.datetime.strftime("%H:%M:%S")
return bar