ibkr/get_streaming_quote_example.py

16 lines
516 B
Python
Raw Normal View History

2023-11-06 19:55:16 +00:00
from datetime import datetime
from ib_insync import Option
from ibkr.client import Client
from ibkr.exchange import SMART
client = Client(host = '127.0.0.1', port = 7497)
expiration = datetime.now().strftime('%Y%m%d')
contract = Option('SPX', expiration, 4350.0, 'P', exchange = SMART, currency = 'USD')
contract.tradingClass = 'SPXW'
market_data = client.get_market_data(contract, streaming = True)
while True:
print('Bid:', market_data.bid)
print('Ask:', market_data.ask)
client.ib.sleep(secs = 2.0)