def historyActive(self, symbol, freq, size=None, start=None, end=None, check_result=True): """ 获取bar数据,包含未完成bar和最新1mbar的时间。 symbol: str, 品种名 freq: str, 周期, 可被转化成标准周期 size: int or None, 数据长度 start: datetime or None, 开始时间 end: datetime or None, 结束时间 check_result: bool, 是否检查结果, 结果不符合条件(长度, 起止时间等)时抛出异常 return: list(VtBarData), last datetime """ freq = standardize_freq(freq) self.check_freq(freq) multipler, unit = split_freq(freq) complete = self.read(symbol, multipler, unit, size, start, end, False, check_result) active = self.read(symbol, 1, "m", start=complete[-1].datetime, keep_active=True, check_result=False) grouper = groupers[unit] for bar in join_bar(active, grouper, multipler): if bar.datetime > complete[-1].datetime: complete.append(bar) return complete, active[-1].datetime
def map_frequency(freq): freq = standardize_freq(freq) mul, unit = split_freq(freq) if freq == "1d": s = "D" elif freq == "1w": s = "W" s = unit.upper() + str(mul) try: return OandaCandlesGranularity(s).value except: raise ValueError("无法向Oanda获取%s频率的K线数据" % freq)
def history(self, symbol, freq, size=None, start=None, end=None, check_result=True): """ 获取bar数据,不包含未完成bar symbol: str, 品种名 freq: str, 周期, 可被转化成标准周期 size: int or None, 数据长度 start: datetime or None, 开始时间 end: datetime or None, 结束时间 check_result: bool, 是否检查结果, 结果不符合条件(长度, 起止时间等)时抛出异常 return: list(VtBarData) """ freq = standardize_freq(freq) self.check_freq(freq) multipler, unit = split_freq(freq) return self.read(symbol, multipler, unit, size, start, end, False, check_result)
def check_freq(self, freq): multipler, unit = split_freq(freq) if unit in {"d", "w"} and (multipler > 1): raise ValueError("Frequency extension not supported: %s" % freq)