首页 > 其他分享 >vnpy tqsdk 修改,增加主力合约和指数

vnpy tqsdk 修改,增加主力合约和指数

时间:2023-01-08 21:36:56浏览次数:44  
标签:vnpy req tqsdk exchange symbol 888 tq 合约 self

    def query_bar_history(self, req: HistoryRequest) -> Optional[List[BarData]]:
        """查询k线数据"""
        # 初始化API
        try:
            api: TqApi = TqApi(auth=TqAuth(self.username, self.password))
        except Exception:
            traceback.print_exc()
            return None

        # 查询数据
        # 888 主力:m
        # 000 指数:i
        if req.symbol.find("888") > 0 :
            req.symbol = req.symbol.rstrip("888")
            tq_symbol: str = f"KQ.m@{req.exchange.value}.{req.symbol}"
        elif req.symbol.find("000") > 0:
            req.symbol = req.symbol.rstrip("000")
            tq_symbol: str = f"KQ.i@{req.exchange.value}.{req.symbol}"
        else:
            tq_symbol: str = f"{req.exchange.value}.{req.symbol}"

 

标签:vnpy,req,tqsdk,exchange,symbol,888,tq,合约,self
From: https://www.cnblogs.com/kingkaixuan/p/17035406.html

相关文章