From 00e4238c8a155eac608f31e7a7627df3d2ce8c62 Mon Sep 17 00:00:00 2001 From: Chip Kent Date: Sat, 7 Oct 2023 16:42:22 -0600 Subject: [PATCH 1/7] Support historical data bar updates. --- src/deephaven_ib/_tws/tws_client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/deephaven_ib/_tws/tws_client.py b/src/deephaven_ib/_tws/tws_client.py index 8bd8f8ad..c666c5f9 100644 --- a/src/deephaven_ib/_tws/tws_client.py +++ b/src/deephaven_ib/_tws/tws_client.py @@ -915,6 +915,10 @@ def historicalDataEnd(self, reqId: int, start: str, end: str): # do not ned to implement EWrapper.historicalDataEnd(self, reqId, start, end) + def historicalDataUpdate(self, reqId: int, bar: BarData): + EWrapper.historicalDataUpdate(self, reqId, bar) + self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) + #### # reqRealTimeBars #### From 09b9e5f3a0d427b0edc81bf87b24497be6063057 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:43:42 -0600 Subject: [PATCH 2/7] Only log new bars that contain volume or bar count data --- src/deephaven_ib/_tws/tws_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deephaven_ib/_tws/tws_client.py b/src/deephaven_ib/_tws/tws_client.py index c666c5f9..9e29e33c 100644 --- a/src/deephaven_ib/_tws/tws_client.py +++ b/src/deephaven_ib/_tws/tws_client.py @@ -917,7 +917,9 @@ def historicalDataEnd(self, reqId: int, start: str, end: str): def historicalDataUpdate(self, reqId: int, bar: BarData): EWrapper.historicalDataUpdate(self, reqId, bar) - self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) + + if bd.volume >= 0 or bd.barCount >= 0: + self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) #### # reqRealTimeBars From c7b73cbb47d35b6d753decd49ba56c7f5cbaf5b0 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:49:15 -0600 Subject: [PATCH 3/7] Fixed when bars will be updated --- src/deephaven_ib/_tws/tws_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deephaven_ib/_tws/tws_client.py b/src/deephaven_ib/_tws/tws_client.py index 9e29e33c..0e11b7a1 100644 --- a/src/deephaven_ib/_tws/tws_client.py +++ b/src/deephaven_ib/_tws/tws_client.py @@ -918,7 +918,7 @@ def historicalDataEnd(self, reqId: int, start: str, end: str): def historicalDataUpdate(self, reqId: int, bar: BarData): EWrapper.historicalDataUpdate(self, reqId, bar) - if bd.volume >= 0 or bd.barCount >= 0: + if bd.volume > 0 or bd.barCount > 0: self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) #### From bebe6f8f8fa6603ecfd41e06d95df530ba8166fe Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:34:25 -0600 Subject: [PATCH 4/7] Updated bar processing to show only the latest bars to be consistent with the response from IB. --- src/deephaven_ib/__init__.py | 4 ++-- src/deephaven_ib/_tws/tws_client.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/deephaven_ib/__init__.py b/src/deephaven_ib/__init__.py index 31b9f0b0..8986fe31 100644 --- a/src/deephaven_ib/__init__.py +++ b/src/deephaven_ib/__init__.py @@ -407,7 +407,7 @@ class IbSessionTws: * **ticks_trade**: real-time tick market data of trade prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. * **ticks_bid_ask**: real-time tick market data of bid and ask prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. * **ticks_mid_point**: real-time tick market data of mid-point prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. - * **bars_historical**: historical price bars requested via ``request_bars_historical``. + * **bars_historical**: historical price bars requested via ``request_bars_historical`` . Real-time bars change as new data arrives. * **bars_realtime**: real-time price bars requested via ``request_bars_realtime``. #### @@ -638,7 +638,7 @@ def deephaven_ib_parse_note(note:str, key:str) -> Optional[str]: "orders_status": tables_raw["raw_orders_status"] \ .last_by("PermId") \ .move_columns_up(["ReceiveTime", "PermId", "ClientId", "OrderId", "ParentId"]), - "bars_historical": annotate_ticks(tables_raw["raw_bars_historical"]), + "bars_historical": annotate_ticks(tables_raw["raw_bars_historical"]).last_by(["Request", "Timestamp", "ContractId"]), "bars_realtime": annotate_ticks(tables_raw["raw_bars_realtime"]), "ticks_efp": annotate_ticks(tables_raw["raw_ticks_efp"]), "ticks_generic": annotate_ticks(tables_raw["raw_ticks_generic"]), diff --git a/src/deephaven_ib/_tws/tws_client.py b/src/deephaven_ib/_tws/tws_client.py index 0e11b7a1..c666c5f9 100644 --- a/src/deephaven_ib/_tws/tws_client.py +++ b/src/deephaven_ib/_tws/tws_client.py @@ -917,9 +917,7 @@ def historicalDataEnd(self, reqId: int, start: str, end: str): def historicalDataUpdate(self, reqId: int, bar: BarData): EWrapper.historicalDataUpdate(self, reqId, bar) - - if bd.volume > 0 or bd.barCount > 0: - self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) + self._table_writers["bars_historical"].write_row([reqId, *logger_bar_data.vals(bar)]) #### # reqRealTimeBars From 663f88db6c9bf2342607271fe784b27837f5b3ac Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:34:52 -0600 Subject: [PATCH 5/7] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b0b9d3f..9cc3b363 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ These tables include: * `ticks_trade`: real-time tick market data of trade prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. * `ticks_bid_ask`: real-time tick market data of bid and ask prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. * `ticks_mid_point`: real-time tick market data of mid-point prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. - * `bars_historical`: historical price bars requested via `request_bars_historical`. + * `bars_historical`: historical price bars requested via `request_bars_historical`. Real-time bars change as new data arrives. * `bars_realtime`: real-time price bars requested via `request_bars_realtime`. * Order Management System (OMS) * `orders_submitted`: submitted orders **FOR THE THE CLIENT'S ID**. A client ID of 0 contains manually entered orders. Automatically populated. From d1b1fb125cd3cf9655f948e6fb1ccd24c0065253 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:35:50 -0600 Subject: [PATCH 6/7] Fixed a comment --- src/deephaven_ib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deephaven_ib/__init__.py b/src/deephaven_ib/__init__.py index 8986fe31..a26af40b 100644 --- a/src/deephaven_ib/__init__.py +++ b/src/deephaven_ib/__init__.py @@ -407,7 +407,7 @@ class IbSessionTws: * **ticks_trade**: real-time tick market data of trade prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. * **ticks_bid_ask**: real-time tick market data of bid and ask prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. * **ticks_mid_point**: real-time tick market data of mid-point prices requested via ``request_tick_data_historical`` or ``request_tick_data_realtime``. - * **bars_historical**: historical price bars requested via ``request_bars_historical`` . Real-time bars change as new data arrives. + * **bars_historical**: historical price bars requested via ``request_bars_historical``. Real-time bars change as new data arrives. * **bars_realtime**: real-time price bars requested via ``request_bars_realtime``. #### From 9834413766968baa2ce1de224a2ba530acf500ca Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:36:34 -0600 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cc3b363..a23c4022 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ These tables include: * `ticks_trade`: real-time tick market data of trade prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. * `ticks_bid_ask`: real-time tick market data of bid and ask prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. * `ticks_mid_point`: real-time tick market data of mid-point prices requested via `request_tick_data_historical` or `request_tick_data_realtime`. - * `bars_historical`: historical price bars requested via `request_bars_historical`. Real-time bars change as new data arrives. + * `bars_historical`: historical price bars requested via `request_bars_historical`. Real-time bars change as new data arrives. * `bars_realtime`: real-time price bars requested via `request_bars_realtime`. * Order Management System (OMS) * `orders_submitted`: submitted orders **FOR THE THE CLIENT'S ID**. A client ID of 0 contains manually entered orders. Automatically populated.