-
Notifications
You must be signed in to change notification settings - Fork 37
/
ib_spike.py
35 lines (24 loc) · 956 Bytes
/
ib_spike.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
"""
Run `j IBCMacos-3.18.0` in terminal to switch to IBC folder
Then `./gatewaystartmacos.sh -inline` to start TWS
Port 7497 is for connection to TWS using paper trading account
Port 7496 is for connection to TWS using real trading account
Port 4002 is for connection to IB Gateway using paper trading account
Port 4001 is for connection to IB Gateway using real trading account
"""
# pip install ib_insync
# https://ib-insync.readthedocs.io/recipes.html
import ib_async
from ib_async import *
from common.ib import setup_ib
# util.startLoop() # uncomment this line when in a notebook
util.logToConsole("DEBUG")
ib = setup_ib()
print(ib_async.__all__)
contract = Stock("TSLA", "SMART", "USD")
print(ib.reqContractDetails(contract))
print(ib.qualifyContracts(contract))
chains = ib.reqSecDefOptParams(contract.symbol, "", contract.secType, contract.conId)
chain = next(c for c in chains if c.tradingClass == "TSLA")
print(chain)
ib.disconnect()