當前位置: 首頁>>代碼示例>>Python>>正文


Python vtObject.VtBarData類代碼示例

本文整理匯總了Python中vnpy.trader.vtObject.VtBarData的典型用法代碼示例。如果您正苦於以下問題:Python VtBarData類的具體用法?Python VtBarData怎麽用?Python VtBarData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了VtBarData類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: loadBar

 def loadBar(self, dbName, collectionName, days):
     """從數據庫中讀取Bar數據,startDate是datetime對象"""
     startDate = self.today - timedelta(days)
     
     d = {'datetime':{'$gte':startDate}}
     barData = self.mainEngine.dbQuery(dbName, collectionName, d)
     
     l = []
     for d in barData:
         bar = VtBarData()
         bar.__dict__ = d
         l.append(bar)
     return l
開發者ID:porfavor,項目名稱:vnpy,代碼行數:13,代碼來源:ctaEngine.py

示例2: loadBar

    def loadBar(self, dbName, collectionName, days):
        """從數據庫中讀取Bar數據,startDate是datetime對象"""
        print "%s.%s.%s" % (__name__, self.__class__.__name__, get_current_function_name())
        startDate = self.today - timedelta(days)

        d = {'datetime': {'$gte': startDate}}
        barData = self.mainEngine.dbQuery(dbName, collectionName, d, 'datetime')

        l = []
        for d in barData:
            bar = VtBarData()
            bar.__dict__ = d
            l.append(bar)
        return l
開發者ID:QuantFeng,項目名稱:vnpy,代碼行數:14,代碼來源:ctaEngine.py

示例3: loadBar

 def loadBar(self, dbName, collectionName, days):
     """從數據庫中讀取Bar數據,startDate是datetime對象"""
     # 優先嘗試從RQData獲取數據
     if dbName == MINUTE_DB_NAME and collectionName.upper() in self.rqSymbolSet:
         l = self.loadRqBar(collectionName, days)
         return l
     
     # 如果沒有則從數據庫中讀取數據
     startDate = self.today - timedelta(days)
     
     d = {'datetime':{'$gte':startDate}}
     barData = self.mainEngine.dbQuery(dbName, collectionName, d, 'datetime')
     
     l = []
     for d in barData:
         bar = VtBarData()
         bar.__dict__ = d
         l.append(bar)
     return l
開發者ID:roccox,項目名稱:vnpy,代碼行數:19,代碼來源:ctaEngine.py

示例4: loadData

 def loadData(self):
     """加載數據"""
     mc = MongoClient()
     db = mc[DAILY_DB_NAME]
     
     for vtSymbol in self.vtSymbolList:
         flt = {'datetime':{'$gte':self.startDt,
                            '$lte':self.endDt}} 
         
         collection = db[vtSymbol]
         cursor = collection.find(flt).sort('datetime')
         
         for d in cursor:
             bar = VtBarData()
             bar.__dict__ = d
             
             barDict = self.dataDict.setdefault(bar.datetime, OrderedDict())
             barDict[bar.vtSymbol] = bar
         
         self.output(u'%s數據加載完成,總數據量:%s' %(vtSymbol, cursor.count()))
     
     self.output(u'全部數據加載完成')
開發者ID:viponedream,項目名稱:vnpy,代碼行數:22,代碼來源:turtleEngine.py

示例5: loadCsv

def loadCsv(filename):
    """"""
    symbol = filename.split('.')[0]
    
    mc = MongoClient()
    db = mc[DAILY_DB_NAME]
    collection = db[symbol]
    
    with open(filename) as f:
        r = DictReader(f)
        for d in r:
            bar = VtBarData()
            bar.datetime = datetime.strptime(d['date'], '%Y/%m/%d')
            bar.vtSymbol = symbol
            bar.open = float(d['open'])
            bar.high = float(d['high'])
            bar.low = float(d['low'])
            bar.close = float(d['close'])
            bar.volume= int(d['volume'])
        
            collection.insert(bar.__dict__)
開發者ID:roccox,項目名稱:vnpy,代碼行數:21,代碼來源:loadCsv.py

示例6: generateVtBar

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
開發者ID:aaront2000,項目名稱:vnpy,代碼行數:16,代碼來源:dataService.py

示例7: downloadEquityDailyBar

    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    
開發者ID:BetabrainLEE,項目名稱:vnpy,代碼行數:52,代碼來源:ctaHistoryData.py

示例8: loadMcCsv

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)
開發者ID:GenesisOrg,項目名稱:vnpy,代碼行數:32,代碼來源:ctaHistoryData.py

示例9: loadOKEXCsv

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)
開發者ID:GenesisOrg,項目名稱:vnpy,代碼行數:35,代碼來源:ctaHistoryData.py

示例10: generateVtBar

def generateVtBar(row):
    """生成K線"""
    bar = VtBarData()
    
    bar.symbol = row['code']
    bar.exchange = ''
    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.datetime = datetime.strptime(row['time_key'], '%Y-%m-%d %H:%M:%S')
    bar.date = bar.datetime.strftime("%Y%m%d")
    bar.time = bar.datetime.strftime("%H:%M:%S")
    
    return bar
開發者ID:KobeZhao,項目名稱:vnpy,代碼行數:17,代碼來源:dataService.py

示例11: generateVtBar

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
開發者ID:KobeZhao,項目名稱:vnpy,代碼行數:17,代碼來源:dataService.py

示例12: loadRqBar

 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
開發者ID:roccox,項目名稱:vnpy,代碼行數:29,代碼來源:ctaEngine.py

示例13: VtBarData

print u'數據下載完成'

# 創建MongoDB連接
client = pymongo.MongoClient('localhost', 27017)
collection = client[DAILY_DB_NAME][vtSymbol]
collection.create_index('datetime')

print u'MongoDB連接成功'

# 將數據插入曆史數據庫
for row in data.iterrows():
    date = row[0]
    data = row[1]
    
    bar = VtBarData()
    bar.vtSymbol = vtSymbol
    bar.symbol = symbol
    bar.exchange = exchange
    bar.date = date
    bar.datetime = datetime.strptime(date, '%Y-%m-%d')
    bar.open = data['open']
    bar.high = data['high']
    bar.low = data['low']
    bar.close = data['close']
    bar.volume = data['volume']
    
    flt = {'datetime': bar.datetime}
    collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)

print u'數據插入完成'
開發者ID:cydrain,項目名稱:Coding_Practice,代碼行數:30,代碼來源:method_vnpy.py

示例14: generateVtBar

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
開發者ID:roccox,項目名稱:vnpy,代碼行數:16,代碼來源:dataService.py

示例15: downloadFuturesDailyBar

    def downloadFuturesDailyBar(self, symbol):
        """
        下載期貨合約的日行情,symbol是合約代碼,
        若最後四位為0000(如IF0000),代表下載連續合約。
        """
        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 = ''
        
        # 主力合約
        if '0000' in symbol:
            path = 'api/market/getMktMFutd.json'
            
            params = {}
            params['contractObject'] = symbol.replace('0000', '')
            params['mainCon'] = 1
            if last:
                params['startDate'] = last['date']
        # 交易合約
        else:
            path = 'api/market/getMktFutd.json'
            
            params = {}
            params['ticker'] = symbol
            if last:
                params['startDate'] = 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)
                    bar.openInterest = d.get('openInt', 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
開發者ID:BetabrainLEE,項目名稱:vnpy,代碼行數:65,代碼來源:ctaHistoryData.py


注:本文中的vnpy.trader.vtObject.VtBarData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。