Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 3
0
    def getKRecord(self, market, code, pos, ktype):
        """
        【重载接口】(必须)获取指定位置的K线记录
        
        :param str market: 市场标识
        :param str code: 证券代码
        :param int pos: 指定位置(大于等于0)
        :param Query.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.index[pos])
            record.open = data['open'][pos]
            record.high = data['high'][pos]
            record.low = data['low'][pos]
            record.close = data['close'][pos]
            record.amount = data['money'][pos]
            record.volume = data['volume'][pos]

        return record
Exemplo n.º 4
0
    def getKRecordList(self, market, code, query):
        """
        【重载接口】(必须)按指定的位置[start_ix, end_ix)读取K线数据至out_buffer
        
        :param str market: 市场标识
        :param str code: 证券代码
        :param Query query: 查询条件
        :rtype: KRecordList
        """
        if query.query_type == Query.DATE:
            print("未实现按日期查询")
            return KRecordList()
        start_ix = query.start
        end_ix = query.end
        if start_ix >= end_ix or start_ix < 0 or end_ix < 0:
            return KRecordList()

        data = self._get_bars(market, code, query.ktype)

        if len(data) < start_ix:
            return KRecordList()

        total = end_ix if end_ix < len(data) else len(data)
        result = KRecordList()
        for i in range(start_ix, total):
            record = KRecord()
            record.datetime = Datetime(data[i].get('datetime'))
            record.open = data[i].get('open')
            record.high = data[i].get('high')
            record.low = data[i].get('low')
            record.close = data[i].get('close')
            record.amount = data[i].get('amount')
            record.volume = data[i].get('vol')
            result.append(record)
        return result
Exemplo n.º 5
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 Query.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.index[i])
            record.open = data['open'][i]
            record.high = data['high'][i]
            record.low = data['low'][i]
            record.close = data['close'][i]
            record.amount = data['money'][i]
            record.volume = data['volume'][i]
            out_buffer.append(record)