Skip to content

Commit

Permalink
[Fix] 反转数据顺序,按时间顺序升序排列
Browse files Browse the repository at this point in the history
  • Loading branch information
Edanflame committed Nov 11, 2021
1 parent cfdff34 commit 04a1668
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions vnpy_tushare/tushare_datafeed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import timedelta, datetime
from pytz import timezone
from typing import List, Optional
from typing import Dict, List, Optional
from copy import deepcopy

import pandas as pd
Expand All @@ -9,7 +9,7 @@
from vnpy.trader.setting import SETTINGS
from vnpy.trader.datafeed import BaseDatafeed
from vnpy.trader.constant import Exchange, Interval
from vnpy.trader.object import BarData, TickData, HistoryRequest
from vnpy.trader.object import BarData, HistoryRequest
from vnpy.trader.utility import round_to

INTERVAL_VT2TS = {
Expand Down Expand Up @@ -190,6 +190,8 @@ def query_bar_history(self, req: HistoryRequest) -> Optional[List[BarData]]:
)
df = pd.concat([df[:-1], d1])

bar_keys: List[datetime] = []
bar_dict: Dict[datetime, BarData] = {}
data: List[BarData] = []

if df is not None:
Expand All @@ -206,7 +208,7 @@ def query_bar_history(self, req: HistoryRequest) -> Optional[List[BarData]]:

dt = CHINA_TZ.localize(dt)

bar = BarData(
bar: BarData = BarData(
symbol=symbol,
exchange=exchange,
interval=interval,
Expand All @@ -221,6 +223,11 @@ def query_bar_history(self, req: HistoryRequest) -> Optional[List[BarData]]:
gateway_name="TS"
)

data.append(bar)
bar_dict[dt] = bar

bar_keys = bar_dict.keys()
bar_keys = sorted(bar_keys, reverse=False)
for i in bar_keys:
data.append(bar_dict[i])

return data

0 comments on commit 04a1668

Please sign in to comment.