from typing import Dict
from deephaven.time import to_datetime
from ibapi.contract import Contract
from ibapi.order import Order
import deephaven_ib as dhib
###########################################################################
# WARNING: THIS SCRIPT EXECUTES TRADES!! ONLY USE ON PAPER TRADING ACCOUNTS
###########################################################################
print("==============================================================================================================")
print("==== Create a client and connect.")
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")
client = dhib.IbSessionTws(host="host.docker.internal", port=7497, client_id=0, download_short_rates=False, read_only=False)
print(f"IsConnected: {client.is_connected()}")
client.connect()
print(f"IsConnected: {client.is_connected()}")
print("==============================================================================================================")
print("==== Request tick data.")
print("==============================================================================================================")
contract = Contract()
contract.symbol = "GOOG"
contract.secType = "STK"
contract.currency = "USD"
contract.exchange = "SMART"
rc = client.get_registered_contract(contract)
print(contract)
now = to_datetime("2021-01-01T00:00:00 NY")
# client.request_tick_data_historical(rc, dhib.TickDataType.MIDPOINT, 100, start=now)
# client.request_tick_data_historical(rc, dhib.TickDataType.MIDPOINT, 100, end=now)
# client.request_tick_data_realtime(rc, dhib.TickDataType.MIDPOINT)
client.request_tick_data_realtime(rc, dhib.TickDataType.BID_ASK) #TODO: broken ***
# client.request_tick_data_historical(rc, dhib.TickDataType.LAST, 100, start=now)
# client.request_tick_data_historical(rc, dhib.TickDataType.LAST, 100, end=now)
# client.request_tick_data_realtime(rc, dhib.TickDataType.LAST)
yields:
ERROR:root:TableWriter column type and value type are mismatched: column_name=AskSize column_type=long value_type=<class 'float'> value=900.0
File "/usr/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/opt/deephaven-venv/lib/python3.7/site-packages/ibapi-10.16.1-py3.7.egg/ibapi/client.py", line 263, in run
self.decoder.interpret(fields)
File "/opt/deephaven-venv/lib/python3.7/site-packages/ibapi-10.16.1-py3.7.egg/ibapi/decoder.py", line 1379, in interpret
handleInfo.processMeth(self, iter(fields))
File "/opt/deephaven-venv/lib/python3.7/site-packages/ibapi-10.16.1-py3.7.egg/ibapi/decoder.py", line 1086, in processTickByTickMsg
askSize, tickAttribBidAsk)
File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/_tws/tws_client.py", line 886, in tickByTickBidAsk
self._table_writers["ticks_bid_ask"].write_row([reqId, *logger_hist_tick_bid_ask.vals(t)])
File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/_internal/tablewriter.py", line 76, in write_row
self._check_logged_value_types(values)
File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/_internal/tablewriter.py", line 60, in _check_logged_value_types
f"TableWriter column type and value type are mismatched: column_name={n} column_type={t} value_type={type(v)} value={v}\n{trace_str()}\n-----")
File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/_internal/trace.py", line 9, in trace_str
return "".join(traceback.format_stack())
yields: