Skip to content

Commit 31daedc

Browse files
committed
[Mod] 增加流式写入参数支持
1 parent c903930 commit 31daedc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

vnpy_postgresql/postgresql_database.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(self) -> None:
154154
self.db.connect()
155155
self.db.create_tables([DbBarData, DbTickData, DbBarOverview, DbTickOverview])
156156

157-
def save_bar_data(self, bars: List[BarData]) -> bool:
157+
def save_bar_data(self, bars: List[BarData], stream: bool = False) -> bool:
158158
"""保存K线数据"""
159159
# 读取主键参数
160160
bar = bars[0]
@@ -203,6 +203,9 @@ def save_bar_data(self, bars: List[BarData]) -> bool:
203203
overview.start = bars[0].datetime
204204
overview.end = bars[-1].datetime
205205
overview.count = len(bars)
206+
elif stream:
207+
overview.end = bars[-1].datetime
208+
overview.count += len(bars)
206209
else:
207210
overview.start = min(bars[0].datetime, overview.start)
208211
overview.end = max(bars[-1].datetime, overview.end)
@@ -218,7 +221,7 @@ def save_bar_data(self, bars: List[BarData]) -> bool:
218221

219222
return True
220223

221-
def save_tick_data(self, ticks: List[TickData]) -> bool:
224+
def save_tick_data(self, ticks: List[TickData], stream: bool = False) -> bool:
222225
"""保存TICK数据"""
223226
# 读取主键参数
224227
tick: TickData = ticks[0]
@@ -262,6 +265,9 @@ def save_tick_data(self, ticks: List[TickData]) -> bool:
262265
overview.start = ticks[0].datetime
263266
overview.end = ticks[-1].datetime
264267
overview.count = len(ticks)
268+
elif stream:
269+
overview.end = ticks[-1].datetime
270+
overview.count += len(ticks)
265271
else:
266272
overview.start = min(ticks[0].datetime, overview.start)
267273
overview.end = max(ticks[-1].datetime, overview.end)

0 commit comments

Comments
 (0)