From f55a70a158f932657ab71ef684ce36c9a85b1f3d Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:57:52 -0700 Subject: [PATCH] Support historical data bar updates (#113) * Support historical data bar updates. * Only log new bars that contain volume or bar count data * Fixed when bars will be updated * Updated bar processing to show only the latest bars to be consistent with the response from IB. * readme update * Fixed a comment * Update README.md --- README.md | 2 +- src/deephaven_ib/__init__.py | 4 ++-- src/deephaven_ib/_tws/tws_client.py | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b0b9d3f..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`. + * `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. diff --git a/src/deephaven_ib/__init__.py b/src/deephaven_ib/__init__.py index 31b9f0b0..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``. + * **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 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 ####