prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Bug：rqdata.py 中 RqdataClient 类的 to_rq_symbol 方法对连续和指数合约转换有问题
  ## 环境
  
  * 操作系统: 如Windows 10
  * Anaconda版本: Anaconda 18.12 Python 3.7 64位
  * vn.py版本: v2.0.3
  
  ## Issue类型
  三选一：Bug
  
  ## 预期程序行为
  正确将合约名转换至rqdata中的合约名
  
  ## 实际程序行为
  错误的将郑商所的合约连续和指数合约转换，例如将AP888会转换为AP2888，AP99会转换至AP199导致无法下载到数据。
  
  ## 重现步骤
  在回测模块中下载AP88数据即可。
  
  针对Bug类型Issue，请提供具体重现步骤以及报错截图
  
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `vnpy/trader/rqdata.py`
  Content:
  ```
  1 from datetime import datetime, timedelta
  2 from typing import List
  3 
  4 from rqdatac import init as rqdata_init
  5 from rqdatac.services.basic import all_instruments as rqdata_all_instruments
  6 from rqdatac.services.get_price import get_price as rqdata_get_price
  7 
  8 from .setting import SETTINGS
  9 from .constant import Exchange, Interval
  10 from .object import BarData, HistoryRequest
  11 
  12 
  13 INTERVAL_VT2RQ = {
  14     Interval.MINUTE: "1m",
  15     Interval.HOUR: "60m",
  16     Interval.DAILY: "1d",
  17 }
  18 
  19 INTERVAL_ADJUSTMENT_MAP = {
  20     Interval.MINUTE: timedelta(minutes=1),
  21     Interval.HOUR: timedelta(hours=1),
  22     Interval.DAILY: timedelta()         # no need to adjust for daily bar
  23 }
  24 
  25 
  26 class RqdataClient:
  27     """
  28     Client for querying history data from RQData.
  29     """
  30 
  31     def __init__(self):
  32         """"""
  33         self.username = SETTINGS["rqdata.username"]
  34         self.password = SETTINGS["rqdata.password"]
  35 
  36         self.inited = False
  37         self.symbols = set()
  38 
  39     def init(self):
  40         """"""
  41         if self.inited:
  42             return True
  43 
  44         if not self.username or not self.password:
  45             return False
  46 
  47         rqdata_init(self.username, self.password,
  48                     ('rqdatad-pro.ricequant.com', 16011))
  49 
  50         try:
  51             df = rqdata_all_instruments(date=datetime.now())
  52             for ix, row in df.iterrows():
  53                 self.symbols.add(row['order_book_id'])
  54         except RuntimeError:
  55             return False
  56 
  57         self.inited = True
  58         return True
  59 
  60     def to_rq_symbol(self, symbol: str, exchange: Exchange):
  61         """
  62         CZCE product of RQData has symbol like "TA1905" while
  63         vt symbol is "TA905.CZCE" so need to add "1" in symbol.
  64         """
  65         if exchange in [Exchange.SSE, Exchange.SZSE]:
  66             if exchange == Exchange.SSE:
  67                 rq_symbol = f"{symbol}.XSHG"
  68             else:
  69                 rq_symbol = f"{symbol}.XSHE"
  70         else:
  71             if exchange is not Exchange.CZCE:
  72                 return symbol.upper()
  73 
  74             for count, word in enumerate(symbol):
  75                 if word.isdigit():
  76                     break
  77 
  78             # noinspection PyUnboundLocalVariable
  79             product = symbol[:count]
  80             year = symbol[count]
  81             month = symbol[count + 1:]
  82 
  83             if year == "9":
  84                 year = "1" + year
  85             else:
  86                 year = "2" + year
  87 
  88             rq_symbol = f"{product}{year}{month}".upper()
  89 
  90         return rq_symbol
  91 
  92     def query_history(self, req: HistoryRequest):
  93         """
  94         Query history bar data from RQData.
  95         """
  96         symbol = req.symbol
  97         exchange = req.exchange
  98         interval = req.interval
  99         start = req.start
  100         end = req.end
  101 
  102         rq_symbol = self.to_rq_symbol(symbol, exchange)
  103         if rq_symbol not in self.symbols:
  104             return None
  105 
  106         rq_interval = INTERVAL_VT2RQ.get(interval)
  107         if not rq_interval:
  108             return None
  109 
  110         # For adjust timestamp from bar close point (RQData) to open point (VN Trader)
  111         adjustment = INTERVAL_ADJUSTMENT_MAP[interval]
  112 
  113         # For querying night trading period data
  114         end += timedelta(1)
  115 
  116         df = rqdata_get_price(
  117             rq_symbol,
  118             frequency=rq_interval,
  119             fields=["open", "high", "low", "close", "volume"],
  120             start_date=start,
  121             end_date=end
  122         )
  123 
  124         data: List[BarData] = []
  125         for ix, row in df.iterrows():
  126             bar = BarData(
  127                 symbol=symbol,
  128                 exchange=exchange,
  129                 interval=interval,
  130                 datetime=row.name.to_pydatetime() - adjustment,
  131                 open_price=row["open"],
  132                 high_price=row["high"],
  133                 low_price=row["low"],
  134                 close_price=row["close"],
  135                 volume=row["volume"],
  136                 gateway_name="RQ"
  137             )
  138             data.append(bar)
  139 
  140         return data
  141 
  142 
  143 rqdata_client = RqdataClient()
  144
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/vnpy/trader/rqdata.py b/vnpy/trader/rqdata.py
  --- a/vnpy/trader/rqdata.py
  +++ b/vnpy/trader/rqdata.py
  @@ -36,11 +36,15 @@
           self.inited = False
           self.symbols = set()
   
  -    def init(self):
  +    def init(self, username="", password=""):
           """"""
           if self.inited:
               return True
   
  +        if username and password:
  +            self.username = username
  +            self.password = password
  +
           if not self.username or not self.password:
               return False
   
  @@ -75,6 +79,11 @@
                   if word.isdigit():
                       break
   
  +            # Check for index symbol
  +            time_str = symbol[count:]
  +            if time_str in ["88", "888", "99"]:
  +                return symbol
  +
               # noinspection PyUnboundLocalVariable
               product = symbol[:count]
               year = symbol[count]
  @@ -118,24 +127,27 @@
               frequency=rq_interval,
               fields=["open", "high", "low", "close", "volume"],
               start_date=start,
  -            end_date=end
  +            end_date=end,
  +            adjust_type="none"
           )
   
           data: List[BarData] = []
  -        for ix, row in df.iterrows():
  -            bar = BarData(
  -                symbol=symbol,
  -                exchange=exchange,
  -                interval=interval,
  -                datetime=row.name.to_pydatetime() - adjustment,
  -                open_price=row["open"],
  -                high_price=row["high"],
  -                low_price=row["low"],
  -                close_price=row["close"],
  -                volume=row["volume"],
  -                gateway_name="RQ"
  -            )
  -            data.append(bar)
  +
  +        if df is not None:
  +            for ix, row in df.iterrows():
  +                bar = BarData(
  +                    symbol=symbol,
  +                    exchange=exchange,
  +                    interval=interval,
  +                    datetime=row.name.to_pydatetime() - adjustment,
  +                    open_price=row["open"],
  +                    high_price=row["high"],
  +                    low_price=row["low"],
  +                    close_price=row["close"],
  +                    volume=row["volume"],
  +                    gateway_name="RQ"
  +                )
  +                data.append(bar)
   
           return data
  
verification_info: {"golden_diff": "diff --git a/vnpy/trader/rqdata.py b/vnpy/trader/rqdata.py\n--- a/vnpy/trader/rqdata.py\n+++ b/vnpy/trader/rqdata.py\n@@ -36,11 +36,15 @@\n         self.inited = False\n         self.symbols = set()\n \n-    def init(self):\n+    def init(self, username=\"\", password=\"\"):\n         \"\"\"\"\"\"\n         if self.inited:\n             return True\n \n+        if username and password:\n+            self.username = username\n+            self.password = password\n+\n         if not self.username or not self.password:\n             return False\n \n@@ -75,6 +79,11 @@\n                 if word.isdigit():\n                     break\n \n+            # Check for index symbol\n+            time_str = symbol[count:]\n+            if time_str in [\"88\", \"888\", \"99\"]:\n+                return symbol\n+\n             # noinspection PyUnboundLocalVariable\n             product = symbol[:count]\n             year = symbol[count]\n@@ -118,24 +127,27 @@\n             frequency=rq_interval,\n             fields=[\"open\", \"high\", \"low\", \"close\", \"volume\"],\n             start_date=start,\n-            end_date=end\n+            end_date=end,\n+            adjust_type=\"none\"\n         )\n \n         data: List[BarData] = []\n-        for ix, row in df.iterrows():\n-            bar = BarData(\n-                symbol=symbol,\n-                exchange=exchange,\n-                interval=interval,\n-                datetime=row.name.to_pydatetime() - adjustment,\n-                open_price=row[\"open\"],\n-                high_price=row[\"high\"],\n-                low_price=row[\"low\"],\n-                close_price=row[\"close\"],\n-                volume=row[\"volume\"],\n-                gateway_name=\"RQ\"\n-            )\n-            data.append(bar)\n+\n+        if df is not None:\n+            for ix, row in df.iterrows():\n+                bar = BarData(\n+                    symbol=symbol,\n+                    exchange=exchange,\n+                    interval=interval,\n+                    datetime=row.name.to_pydatetime() - adjustment,\n+                    open_price=row[\"open\"],\n+                    high_price=row[\"high\"],\n+                    low_price=row[\"low\"],\n+                    close_price=row[\"close\"],\n+                    volume=row[\"volume\"],\n+                    gateway_name=\"RQ\"\n+                )\n+                data.append(bar)\n \n         return data\n", "issue": "Bug\uff1arqdata.py \u4e2d RqdataClient \u7c7b\u7684 to_rq_symbol \u65b9\u6cd5\u5bf9\u8fde\u7eed\u548c\u6307\u6570\u5408\u7ea6\u8f6c\u6362\u6709\u95ee\u9898\n## \u73af\u5883\r\n\r\n* \u64cd\u4f5c\u7cfb\u7edf: \u5982Windows 10\r\n* Anaconda\u7248\u672c: Anaconda 18.12 Python 3.7 64\u4f4d\r\n* vn.py\u7248\u672c: v2.0.3\r\n\r\n## Issue\u7c7b\u578b\r\n\u4e09\u9009\u4e00\uff1aBug\r\n\r\n## \u9884\u671f\u7a0b\u5e8f\u884c\u4e3a\r\n\u6b63\u786e\u5c06\u5408\u7ea6\u540d\u8f6c\u6362\u81f3rqdata\u4e2d\u7684\u5408\u7ea6\u540d\r\n\r\n## \u5b9e\u9645\u7a0b\u5e8f\u884c\u4e3a\r\n\u9519\u8bef\u7684\u5c06\u90d1\u5546\u6240\u7684\u5408\u7ea6\u8fde\u7eed\u548c\u6307\u6570\u5408\u7ea6\u8f6c\u6362\uff0c\u4f8b\u5982\u5c06AP888\u4f1a\u8f6c\u6362\u4e3aAP2888\uff0cAP99\u4f1a\u8f6c\u6362\u81f3AP199\u5bfc\u81f4\u65e0\u6cd5\u4e0b\u8f7d\u5230\u6570\u636e\u3002\r\n\r\n## \u91cd\u73b0\u6b65\u9aa4\r\n\u5728\u56de\u6d4b\u6a21\u5757\u4e2d\u4e0b\u8f7dAP88\u6570\u636e\u5373\u53ef\u3002\r\n\r\n\u9488\u5bf9Bug\u7c7b\u578bIssue\uff0c\u8bf7\u63d0\u4f9b\u5177\u4f53\u91cd\u73b0\u6b65\u9aa4\u4ee5\u53ca\u62a5\u9519\u622a\u56fe\r\n\r\n\r\n\n", "before_files": [{"content": "from datetime import datetime, timedelta\nfrom typing import List\n\nfrom rqdatac import init as rqdata_init\nfrom rqdatac.services.basic import all_instruments as rqdata_all_instruments\nfrom rqdatac.services.get_price import get_price as rqdata_get_price\n\nfrom .setting import SETTINGS\nfrom .constant import Exchange, Interval\nfrom .object import BarData, HistoryRequest\n\n\nINTERVAL_VT2RQ = {\n    Interval.MINUTE: \"1m\",\n    Interval.HOUR: \"60m\",\n    Interval.DAILY: \"1d\",\n}\n\nINTERVAL_ADJUSTMENT_MAP = {\n    Interval.MINUTE: timedelta(minutes=1),\n    Interval.HOUR: timedelta(hours=1),\n    Interval.DAILY: timedelta()         # no need to adjust for daily bar\n}\n\n\nclass RqdataClient:\n    \"\"\"\n    Client for querying history data from RQData.\n    \"\"\"\n\n    def __init__(self):\n        \"\"\"\"\"\"\n        self.username = SETTINGS[\"rqdata.username\"]\n        self.password = SETTINGS[\"rqdata.password\"]\n\n        self.inited = False\n        self.symbols = set()\n\n    def init(self):\n        \"\"\"\"\"\"\n        if self.inited:\n            return True\n\n        if not self.username or not self.password:\n            return False\n\n        rqdata_init(self.username, self.password,\n                    ('rqdatad-pro.ricequant.com', 16011))\n\n        try:\n            df = rqdata_all_instruments(date=datetime.now())\n            for ix, row in df.iterrows():\n                self.symbols.add(row['order_book_id'])\n        except RuntimeError:\n            return False\n\n        self.inited = True\n        return True\n\n    def to_rq_symbol(self, symbol: str, exchange: Exchange):\n        \"\"\"\n        CZCE product of RQData has symbol like \"TA1905\" while\n        vt symbol is \"TA905.CZCE\" so need to add \"1\" in symbol.\n        \"\"\"\n        if exchange in [Exchange.SSE, Exchange.SZSE]:\n            if exchange == Exchange.SSE:\n                rq_symbol = f\"{symbol}.XSHG\"\n            else:\n                rq_symbol = f\"{symbol}.XSHE\"\n        else:\n            if exchange is not Exchange.CZCE:\n                return symbol.upper()\n\n            for count, word in enumerate(symbol):\n                if word.isdigit():\n                    break\n\n            # noinspection PyUnboundLocalVariable\n            product = symbol[:count]\n            year = symbol[count]\n            month = symbol[count + 1:]\n\n            if year == \"9\":\n                year = \"1\" + year\n            else:\n                year = \"2\" + year\n\n            rq_symbol = f\"{product}{year}{month}\".upper()\n\n        return rq_symbol\n\n    def query_history(self, req: HistoryRequest):\n        \"\"\"\n        Query history bar data from RQData.\n        \"\"\"\n        symbol = req.symbol\n        exchange = req.exchange\n        interval = req.interval\n        start = req.start\n        end = req.end\n\n        rq_symbol = self.to_rq_symbol(symbol, exchange)\n        if rq_symbol not in self.symbols:\n            return None\n\n        rq_interval = INTERVAL_VT2RQ.get(interval)\n        if not rq_interval:\n            return None\n\n        # For adjust timestamp from bar close point (RQData) to open point (VN Trader)\n        adjustment = INTERVAL_ADJUSTMENT_MAP[interval]\n\n        # For querying night trading period data\n        end += timedelta(1)\n\n        df = rqdata_get_price(\n            rq_symbol,\n            frequency=rq_interval,\n            fields=[\"open\", \"high\", \"low\", \"close\", \"volume\"],\n            start_date=start,\n            end_date=end\n        )\n\n        data: List[BarData] = []\n        for ix, row in df.iterrows():\n            bar = BarData(\n                symbol=symbol,\n                exchange=exchange,\n                interval=interval,\n                datetime=row.name.to_pydatetime() - adjustment,\n                open_price=row[\"open\"],\n                high_price=row[\"high\"],\n                low_price=row[\"low\"],\n                close_price=row[\"close\"],\n                volume=row[\"volume\"],\n                gateway_name=\"RQ\"\n            )\n            data.append(bar)\n\n        return data\n\n\nrqdata_client = RqdataClient()\n", "path": "vnpy/trader/rqdata.py"}], "after_files": [{"content": "from datetime import datetime, timedelta\nfrom typing import List\n\nfrom rqdatac import init as rqdata_init\nfrom rqdatac.services.basic import all_instruments as rqdata_all_instruments\nfrom rqdatac.services.get_price import get_price as rqdata_get_price\n\nfrom .setting import SETTINGS\nfrom .constant import Exchange, Interval\nfrom .object import BarData, HistoryRequest\n\n\nINTERVAL_VT2RQ = {\n    Interval.MINUTE: \"1m\",\n    Interval.HOUR: \"60m\",\n    Interval.DAILY: \"1d\",\n}\n\nINTERVAL_ADJUSTMENT_MAP = {\n    Interval.MINUTE: timedelta(minutes=1),\n    Interval.HOUR: timedelta(hours=1),\n    Interval.DAILY: timedelta()         # no need to adjust for daily bar\n}\n\n\nclass RqdataClient:\n    \"\"\"\n    Client for querying history data from RQData.\n    \"\"\"\n\n    def __init__(self):\n        \"\"\"\"\"\"\n        self.username = SETTINGS[\"rqdata.username\"]\n        self.password = SETTINGS[\"rqdata.password\"]\n\n        self.inited = False\n        self.symbols = set()\n\n    def init(self, username=\"\", password=\"\"):\n        \"\"\"\"\"\"\n        if self.inited:\n            return True\n\n        if username and password:\n            self.username = username\n            self.password = password\n\n        if not self.username or not self.password:\n            return False\n\n        rqdata_init(self.username, self.password,\n                    ('rqdatad-pro.ricequant.com', 16011))\n\n        try:\n            df = rqdata_all_instruments(date=datetime.now())\n            for ix, row in df.iterrows():\n                self.symbols.add(row['order_book_id'])\n        except RuntimeError:\n            return False\n\n        self.inited = True\n        return True\n\n    def to_rq_symbol(self, symbol: str, exchange: Exchange):\n        \"\"\"\n        CZCE product of RQData has symbol like \"TA1905\" while\n        vt symbol is \"TA905.CZCE\" so need to add \"1\" in symbol.\n        \"\"\"\n        if exchange in [Exchange.SSE, Exchange.SZSE]:\n            if exchange == Exchange.SSE:\n                rq_symbol = f\"{symbol}.XSHG\"\n            else:\n                rq_symbol = f\"{symbol}.XSHE\"\n        else:\n            if exchange is not Exchange.CZCE:\n                return symbol.upper()\n\n            for count, word in enumerate(symbol):\n                if word.isdigit():\n                    break\n\n            # Check for index symbol\n            time_str = symbol[count:]\n            if time_str in [\"88\", \"888\", \"99\"]:\n                return symbol\n\n            # noinspection PyUnboundLocalVariable\n            product = symbol[:count]\n            year = symbol[count]\n            month = symbol[count + 1:]\n\n            if year == \"9\":\n                year = \"1\" + year\n            else:\n                year = \"2\" + year\n\n            rq_symbol = f\"{product}{year}{month}\".upper()\n\n        return rq_symbol\n\n    def query_history(self, req: HistoryRequest):\n        \"\"\"\n        Query history bar data from RQData.\n        \"\"\"\n        symbol = req.symbol\n        exchange = req.exchange\n        interval = req.interval\n        start = req.start\n        end = req.end\n\n        rq_symbol = self.to_rq_symbol(symbol, exchange)\n        if rq_symbol not in self.symbols:\n            return None\n\n        rq_interval = INTERVAL_VT2RQ.get(interval)\n        if not rq_interval:\n            return None\n\n        # For adjust timestamp from bar close point (RQData) to open point (VN Trader)\n        adjustment = INTERVAL_ADJUSTMENT_MAP[interval]\n\n        # For querying night trading period data\n        end += timedelta(1)\n\n        df = rqdata_get_price(\n            rq_symbol,\n            frequency=rq_interval,\n            fields=[\"open\", \"high\", \"low\", \"close\", \"volume\"],\n            start_date=start,\n            end_date=end,\n            adjust_type=\"none\"\n        )\n\n        data: List[BarData] = []\n\n        if df is not None:\n            for ix, row in df.iterrows():\n                bar = BarData(\n                    symbol=symbol,\n                    exchange=exchange,\n                    interval=interval,\n                    datetime=row.name.to_pydatetime() - adjustment,\n                    open_price=row[\"open\"],\n                    high_price=row[\"high\"],\n                    low_price=row[\"low\"],\n                    close_price=row[\"close\"],\n                    volume=row[\"volume\"],\n                    gateway_name=\"RQ\"\n                )\n                data.append(bar)\n\n        return data\n\n\nrqdata_client = RqdataClient()\n", "path": "vnpy/trader/rqdata.py"}]}