From ee09013921357a9b378fa82bb1137e3a4d28135d Mon Sep 17 00:00:00 2001 From: noranhe <63988546+noranhe@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:22:29 +0800 Subject: [PATCH 1/2] [Fix] issue 10 --- vnpy_postgresql/postgresql_database.py | 83 +++++++++++++------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/vnpy_postgresql/postgresql_database.py b/vnpy_postgresql/postgresql_database.py index 3e979bc..0936b74 100644 --- a/vnpy_postgresql/postgresql_database.py +++ b/vnpy_postgresql/postgresql_database.py @@ -13,7 +13,8 @@ fn, chunked, Asc, - Desc + Desc, + EXCLUDED ) from vnpy.trader.constant import Exchange, Interval @@ -184,13 +185,13 @@ def save_bar_data(self, bars: list[BarData], stream: bool = False) -> bool: for c in chunked(data, 100): DbBarData.insert_many(c).on_conflict( update={ - DbBarData.volume: DbBarData.volume, - DbBarData.turnover: DbBarData.turnover, - DbBarData.open_interest: DbBarData.open_interest, - DbBarData.open_price: DbBarData.open_price, - DbBarData.high_price: DbBarData.high_price, - DbBarData.low_price: DbBarData.low_price, - DbBarData.close_price: DbBarData.close_price + DbBarData.volume: EXCLUDED.volume, + DbBarData.turnover: EXCLUDED.turnover, + DbBarData.open_interest: EXCLUDED.open_interest, + DbBarData.open_price: EXCLUDED.open_price, + DbBarData.high_price: EXCLUDED.high_price, + DbBarData.low_price: EXCLUDED.low_price, + DbBarData.close_price: EXCLUDED.close_price }, conflict_target=( DbBarData.symbol, @@ -270,39 +271,39 @@ def save_tick_data(self, ticks: list[TickData], stream: bool = False) -> bool: for c in chunked(data, 100): DbTickData.insert_many(c).on_conflict( update={ - DbTickData.name: DbTickData.name, - DbTickData.volume: DbTickData.volume, - DbTickData.turnover: DbTickData.turnover, - DbTickData.open_interest: DbTickData.open_interest, - DbTickData.last_price: DbTickData.last_price, - DbTickData.last_volume: DbTickData.last_volume, - DbTickData.limit_up: DbTickData.limit_up, - DbTickData.limit_down: DbTickData.limit_down, - DbTickData.open_price: DbTickData.open_price, - DbTickData.high_price: DbTickData.high_price, - DbTickData.low_price: DbTickData.low_price, - DbTickData.pre_close: DbTickData.pre_close, - DbTickData.bid_price_1: DbTickData.bid_price_1, - DbTickData.bid_price_2: DbTickData.bid_price_2, - DbTickData.bid_price_3: DbTickData.bid_price_3, - DbTickData.bid_price_4: DbTickData.bid_price_4, - DbTickData.bid_price_5: DbTickData.bid_price_5, - DbTickData.ask_price_1: DbTickData.ask_price_1, - DbTickData.ask_price_2: DbTickData.ask_price_2, - DbTickData.ask_price_3: DbTickData.ask_price_3, - DbTickData.ask_price_4: DbTickData.ask_price_4, - DbTickData.ask_price_5: DbTickData.ask_price_5, - DbTickData.bid_volume_1: DbTickData.bid_volume_1, - DbTickData.bid_volume_2: DbTickData.bid_volume_2, - DbTickData.bid_volume_3: DbTickData.bid_volume_3, - DbTickData.bid_volume_4: DbTickData.bid_volume_4, - DbTickData.bid_volume_5: DbTickData.bid_volume_5, - DbTickData.ask_volume_1: DbTickData.ask_volume_1, - DbTickData.ask_volume_2: DbTickData.ask_volume_2, - DbTickData.ask_volume_3: DbTickData.ask_volume_3, - DbTickData.ask_volume_4: DbTickData.ask_volume_4, - DbTickData.ask_volume_5: DbTickData.ask_volume_5, - DbTickData.localtime: DbTickData.localtime, + DbTickData.name: EXCLUDED.name, + DbTickData.volume: EXCLUDED.volume, + DbTickData.turnover: EXCLUDED.turnover, + DbTickData.open_interest: EXCLUDED.open_interest, + DbTickData.last_price: EXCLUDED.last_price, + DbTickData.last_volume: EXCLUDED.last_volume, + DbTickData.limit_up: EXCLUDED.limit_up, + DbTickData.limit_down: EXCLUDED.limit_down, + DbTickData.open_price: EXCLUDED.open_price, + DbTickData.high_price: EXCLUDED.high_price, + DbTickData.low_price: EXCLUDED.low_price, + DbTickData.pre_close: EXCLUDED.pre_close, + DbTickData.bid_price_1: EXCLUDED.bid_price_1, + DbTickData.bid_price_2: EXCLUDED.bid_price_2, + DbTickData.bid_price_3: EXCLUDED.bid_price_3, + DbTickData.bid_price_4: EXCLUDED.bid_price_4, + DbTickData.bid_price_5: EXCLUDED.bid_price_5, + DbTickData.ask_price_1: EXCLUDED.ask_price_1, + DbTickData.ask_price_2: EXCLUDED.ask_price_2, + DbTickData.ask_price_3: EXCLUDED.ask_price_3, + DbTickData.ask_price_4: EXCLUDED.ask_price_4, + DbTickData.ask_price_5: EXCLUDED.ask_price_5, + DbTickData.bid_volume_1: EXCLUDED.bid_volume_1, + DbTickData.bid_volume_2: EXCLUDED.bid_volume_2, + DbTickData.bid_volume_3: EXCLUDED.bid_volume_3, + DbTickData.bid_volume_4: EXCLUDED.bid_volume_4, + DbTickData.bid_volume_5: EXCLUDED.bid_volume_5, + DbTickData.ask_volume_1: EXCLUDED.ask_volume_1, + DbTickData.ask_volume_2: EXCLUDED.ask_volume_2, + DbTickData.ask_volume_3: EXCLUDED.ask_volume_3, + DbTickData.ask_volume_4: EXCLUDED.ask_volume_4, + DbTickData.ask_volume_5: EXCLUDED.ask_volume_5, + DbTickData.localtime: EXCLUDED.localtime, }, conflict_target=( DbTickData.symbol, From 6b28fb3311d63aa1f1bfc19b142743402b2022ce Mon Sep 17 00:00:00 2001 From: noranhe <63988546+noranhe@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:25:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Del]=20=E9=87=8D=E5=A4=8D=E5=86=99?= =?UTF-8?q?=E5=85=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy_postgresql/postgresql_database.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/vnpy_postgresql/postgresql_database.py b/vnpy_postgresql/postgresql_database.py index 0936b74..1d6a9dd 100644 --- a/vnpy_postgresql/postgresql_database.py +++ b/vnpy_postgresql/postgresql_database.py @@ -256,18 +256,6 @@ def save_tick_data(self, ticks: list[TickData], stream: bool = False) -> bool: # 使用upsert操作将数据更新到数据库中 with self.db.atomic(): - for d in data: - DbTickData.insert(d).on_conflict( - update=d, - conflict_target=( - DbTickData.symbol, - DbTickData.exchange, - DbTickData.datetime, - - - ), - ).execute() - for c in chunked(data, 100): DbTickData.insert_many(c).on_conflict( update={