From b5c547f1348a78160a4fc8fdf68b3f4eead1096e Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Tue, 27 Sep 2022 12:21:55 -0600 Subject: [PATCH] Fix request tickdata realtime exception (#96) * Fix broken example. * Change bid ask sizes in bid ask ticks to floats. --- examples/example_all_functionality.py | 17 +++++++++-------- examples/example_read_only_functionality.py | 17 +++++++++-------- src/deephaven_ib/_tws/ib_type_logger.py | 4 ++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/example_all_functionality.py b/examples/example_all_functionality.py index 34f6bd44..8269b2d4 100644 --- a/examples/example_all_functionality.py +++ b/examples/example_all_functionality.py @@ -90,14 +90,15 @@ def get_contracts() -> Dict[str, Contract]: contract.secType = "FUT" contract.exchange = "GLOBEX" contract.currency = "USD" - contract.lastTradeDateOrContractMonth = "202209" + contract.lastTradeDateOrContractMonth = "202212" rst["future_1"] = contract + # find more contracts at https://www.cmegroup.com/markets/equities/sp/e-mini-sandp500.quotes.html contract = Contract() contract.secType = "FUT" contract.exchange = "GLOBEX" contract.currency = "USD" - contract.localSymbol = "MESU2" + contract.localSymbol = "ESZ2" rst["future_2"] = contract contract = Contract() @@ -105,7 +106,7 @@ def get_contracts() -> Dict[str, Contract]: contract.secType = "FUT" contract.exchange = "EUREX" contract.currency = "EUR" - contract.lastTradeDateOrContractMonth = "202209" + contract.lastTradeDateOrContractMonth = "202212" contract.multiplier = "1" rst["future_3"] = contract @@ -357,8 +358,8 @@ def get_contracts() -> Dict[str, Contract]: bar_type=dhib.BarDataType.ASK) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False) -client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, - bar_type=dhib.BarDataType.AGGTRADES) +# client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, +# bar_type=dhib.BarDataType.AGGTRADES) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False) @@ -482,7 +483,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 3000 +order.lmtPrice = 100 print("Placing order: START") client.order_place(rc, order) @@ -493,7 +494,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 2600 +order.lmtPrice = 90 print("Placing order: START") client.order_place(rc, order) @@ -504,7 +505,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 2700 +order.lmtPrice = 91 print("Placing order: START") req = client.order_place(rc, order) diff --git a/examples/example_read_only_functionality.py b/examples/example_read_only_functionality.py index 4fd31eb6..f78f1c89 100644 --- a/examples/example_read_only_functionality.py +++ b/examples/example_read_only_functionality.py @@ -86,14 +86,15 @@ def get_contracts() -> Dict[str, Contract]: contract.secType = "FUT" contract.exchange = "GLOBEX" contract.currency = "USD" - contract.lastTradeDateOrContractMonth = "202209" + contract.lastTradeDateOrContractMonth = "202212" rst["future_1"] = contract + # find more contracts at https://www.cmegroup.com/markets/equities/sp/e-mini-sandp500.quotes.html contract = Contract() contract.secType = "FUT" contract.exchange = "GLOBEX" contract.currency = "USD" - contract.localSymbol = "MESU2" + contract.localSymbol = "ESZ2" rst["future_2"] = contract contract = Contract() @@ -101,7 +102,7 @@ def get_contracts() -> Dict[str, Contract]: contract.secType = "FUT" contract.exchange = "EUREX" contract.currency = "EUR" - contract.lastTradeDateOrContractMonth = "202209" + contract.lastTradeDateOrContractMonth = "202212" contract.multiplier = "1" rst["future_3"] = contract @@ -353,8 +354,8 @@ def get_contracts() -> Dict[str, Contract]: bar_type=dhib.BarDataType.ASK) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False) -client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, - bar_type=dhib.BarDataType.AGGTRADES) +# client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, +# bar_type=dhib.BarDataType.AGGTRADES) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False) @@ -478,7 +479,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 3000 +order.lmtPrice = 100 print("Placing order -- confirm fail: START") try: @@ -495,7 +496,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 2600 +order.lmtPrice = 90 print("Placing order -- confirm fail: START") try: @@ -512,7 +513,7 @@ def get_contracts() -> Dict[str, Contract]: order.action = "BUY" order.orderType = "LIMIT" order.totalQuantity = 1 -order.lmtPrice = 2700 +order.lmtPrice = 91 print("Placing order -- confirm fail: START") try: diff --git a/src/deephaven_ib/_tws/ib_type_logger.py b/src/deephaven_ib/_tws/ib_type_logger.py index 0eed72f3..89edffba 100644 --- a/src/deephaven_ib/_tws/ib_type_logger.py +++ b/src/deephaven_ib/_tws/ib_type_logger.py @@ -362,8 +362,8 @@ def _details_historical_tick_bid_ask() -> List[Tuple]: ("Timestamp", dtypes.DateTime, lambda t: unix_sec_to_dh_datetime(t.time)), ("BidPrice", dtypes.float64, lambda t: t.priceBid), ("AskPrice", dtypes.float64, lambda t: t.priceAsk), - ("BidSize", dtypes.int64, lambda t: t.sizeBid), - ("AskSize", dtypes.int64, lambda t: t.sizeAsk), + ("BidSize", dtypes.float64, lambda t: t.sizeBid), + ("AskSize", dtypes.float64, lambda t: t.sizeAsk), *_include_details(_details_tick_attrib_bid_ask(), lambda t: t.tickAttribBidAsk), ]