LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.
A live quote stream is a contract description plus a market-data request, with a wrapper callback that receives each tick. The lesson asks Interactive Brokers for an SPY call and prints two fields as they arrive: the option price and the price of the underlying. The request is a stream, so the callback keeps firing after the script has moved on. That is the raw feed later rules would read.
Why it matters
A connected session can sit idle and still teach nothing about prices. Strategies that compare a live price with a threshold need a continuous feed, not a one-time snapshot. The lesson uses an option so the callback is the one that carries option fields: implied volatility, delta, the option price, a dividend, gamma, vega, theta, and the underlying price, along with the request id and the tick type. Printing two of those fields is enough to see that the gateway, the contract, and the callback agree.
The idea in plain words
The contract object names the instrument. For this option the lesson sets the symbol to SPY, the security type to OPT, the exchange to SMART, and the currency to USD. The right is a call, the strike is 395, and the last trade date is 30 June 2020, which the lesson writes as the contract month 20200630. Those fields are what the broker needs before it can choose a single listed contract.
The request itself is a client call, request market data, made on the socket side of the trading application from the earlier connection lesson. It takes a request id, the contract, a tick type, a snapshot flag, and a regulatory-snapshot flag, plus an options string. The lesson uses request id 1000, leaves the tick type blank, passes false and false so the feed stays live, and passes an empty options string. False for the snapshot flag is the difference between one picture and a continuing stream.
Replies do not return from that call. They arrive in the wrapper method tick option computation. The lesson calls the base implementation with the arguments the server sent, then prints the underlying price and the option price. Creating the trading application, with the gateway already logged in, starts the prints. The lesson compares the stream with a public quote page and says the figures are relatively similar. It notes that the broker print for the option runs to many decimal places, against a public last price it describes as 0.01.
How to use it
Import the contract class from the API's contract module. Build one contract and assign symbol, security type, exchange, currency, right, strike, and last trade date as above. On the client side, call the market-data request with id 1000, that contract, an empty tick type, both snapshot flags false, and an empty options list or string as the binding expects. On the wrapper side, implement tick option computation. Pass every server argument through to the superclass, then print the underlying price and the option price. Run the application object. The connected session from the gateway should begin printing.
The lesson's sketch of a rule sits on top of those prints. A later condition can buy when the option price falls through a chosen level and sell when it rises through another, and the same idea applies to the underlying price. The session itself stops at showing the numbers.
What usually goes wrong
A snapshot flag left true ends the lesson's stream after one computation. The callback may fire and then go quiet, which looks like a broken gateway. An expired last-trade date, or a strike and right that do not match a listed series, produces an empty stream with a valid connection. The June 2020 date belongs to the lesson's example. Reusing it later will not resolve to a live contract.
Request ids have to stay unique among streams you still want. Reusing 1000 cancels or confuses the prior request. The callback also receives many fields the lesson does not print. Reading the option price from the wrong argument shifts every comparison. Calling the superclass with the server's arguments keeps the library's own handling intact before the print.
Public pages and the broker feed can differ in the last digits. The lesson treats a many-decimal broker price as the feed to trust for the contract it requested, and it only claims that the public last, given as 0.01, is in the same neighborhood.
Questions people ask
Which contract does the lesson stream?
An SPY call, strike 395, expiry 30 June 2020, exchange SMART, currency USD.
How is a stream different from a snapshot?
The lesson passes false for the snapshot flags and keeps request id 1000 open so tick option computation keeps receiving updates.
Which fields arrive in the callback?
Request id, tick type, implied volatility, delta, option price, dividend, gamma, vega, theta, and the underlying price. The lesson prints the underlying price and the option price.