forked from deephaven-examples/deephaven-ib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_market_data.py
36 lines (25 loc) · 1.17 KB
/
example_market_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Run this example in the Deephaven IDE Console
from ibapi.contract import Contract
import deephaven_ib as dhib
print("==============================================================================================================")
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")
client = dhib.IbSessionTws(host="localhost", port=7497, download_short_rates=False)
client.connect()
# Makes all tables global variables so that they are displayed in the user interface
for k, v in client.tables.items():
globals()[k] = v
# Use delayed market data if you do not have access to real-time
# client.set_market_data_type(dhib.MarketDataType.DELAYED)
client.set_market_data_type(dhib.MarketDataType.REAL_TIME)
c = Contract()
c.symbol = 'AAPL'
c.secType = 'STK'
c.exchange = 'SMART'
c.currency = 'USD'
rc = client.get_registered_contract(c)
print(rc)
client.request_market_data(rc)
client.request_tick_data_realtime(rc, dhib.TickDataType.BID_ASK)
client.request_tick_data_realtime(rc, dhib.TickDataType.LAST)
client.request_tick_data_realtime(rc, dhib.TickDataType.MIDPOINT)