示例#1
0
 def loadKData(self, market, code, ktype, start_ix, end_ix, out_buffer):
     """
     【重载接口】(必须)按指定的位置[start_ix, end_ix)读取K线数据至out_buffer
     
     :param str market: 市场标识
     :param str code: 证券代码
     :param KQuery.KType ktype: K线类型
     :param int start_ix: 起始位置
     :param int end_ix: 结束位置
     :param KRecordListPtr out_buffer: 传入的数据缓存,读取数据后使用 
                                        out_buffer.append(krecord) 加入数据        
     """
     if start_ix >= end_ix or start_ix <0 or end_ix <0:
         return
     
     data = self._get_bars(market, code, ktype)
                 
     if len(data) < start_ix:
         return
     
     total = end_ix if end_ix < len(data) else len(data)
     for i in range(start_ix, total):
         record = KRecord()
         record.datetime = Datetime(data[i].get('datetime'))
         record.openPrice = data[i].get('open')
         record.highPrice = data[i].get('high')
         record.lowPrice = data[i].get('low')
         record.closePrice = data[i].get('close')
         record.transAmount = data[i].get('amount')
         record.transCount = data[i].get('vol')
         out_buffer.append(record)
示例#2
0
 def getKRecord(self, market, code, pos, ktype):
     """
     【重载接口】(必须)获取指定位置的K线记录
     
     :param str market: 市场标识
     :param str code: 证券代码
     :param int pos: 指定位置(大于等于0)
     :param KQuery.KType ktype: K线类型        
     """
     record = KRecord()
     if pos < 0:
         return record
     
     data = self._get_bars(market, code, ktype)
     if data is None:
         return record
     
     if pos < len(data):
         record.datetime = Datetime(data[pos].get('datetime'))
         record.openPrice = data[pos].get('open')
         record.highPrice = data[pos].get('high')
         record.lowPrice = data[pos].get('low')
         record.closePrice = data[pos].get('close')
         record.transAmount = data[pos].get('amount')
         record.transCount = data[pos].get('vol')
         
     return record