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[pos].get('datetime')) record.open = data[pos].get('open') record.high = data[pos].get('high') record.low = data[pos].get('low') record.close = data[pos].get('close') record.amount = data[pos].get('amount') record.volume = data[pos].get('vol') return record
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
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)