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 callback prints a tick and then forgets it, unless the wrapper keeps a copy. The lesson adds three lists to the API controller: deltas, option prices, and underlying prices. Each time the option-computation callback arrives with a real value, that value is appended. A one-second loop on the trading application can print the delta list as it grows. The lists are the cache. Exporting them is left open.

Why it matters

A stream is only useful for a later study if the values survive the callback. The lesson is still on the option feed from the broker session: the same tick-option-computation method that can print a price can also store it. Stored deltas, option prices, and underlying prices can be written to a spreadsheet or a text file, or left in memory for a rule. The demonstration writes them to the console once a second so the growth of the list is visible.

The idea in plain words

The controller subclass owns the lists because it owns the callback. Its constructor creates three empty lists. Inside the callback, the lesson tests each field before appending. If delta is not None, append delta. If the option price is not None, append the option price. If the underlying price is not None, append the underlying price. The spoken rule is slightly sharper than a bare None check. The lesson says that a field with no change is not appended, and that a changed field is appended to its own list. In the code sketch, the guard actually written is the None test. Either reading has the same purpose: skip empty updates, keep the ones that carry a number.

The trading application inherits the controller, so a live instance exposes the lists as ordinary attributes. After app = TradingApplication, the expression that reads the option-price list is the instance's option-price attribute. You do not reach into a separate cache object. The application is the cache.

How to use it

Create the three lists in the controller constructor before any request is sent. In the option callback, append under the None guards above. Start the application the usual way, on its thread, with the gateway logged into paper trading and the contract request already in place. Then run a loop: while true, sleep one second, and print the delta list from the application instance. Import the time module for the sleep. The lesson's run shows a quiet list while delta is unchanged, then a longer list once delta moves. That growing list is the stored history for the contract being streamed.

The same attribute path works for the option-price list and the underlying-price list. A script can pass any of them to a file writer. The lesson does not pick a file format. It shows the lists filling, and says a spreadsheet or a text file would be a natural next handoff.

What usually goes wrong

Printing inside the callback shows the latest tick and keeps nothing. The next tick overwrites your attention. The bug is the missing append.

Appending without the None guard stores empty placeholders and makes later averages and plots stumble. The lesson's condition exists so a tick that did not include a given greek does not pollute that greek's list. There is a mismatch to watch: the prose says "only when the value changes," while the written condition is "not None." A feed that repeats the same delta on every tick would still grow the list under a None test. If the goal is a list of changes only, the callback also needs a comparison with the last stored value. The lesson names that change-only intent and shows the None test. Know which of the two you implemented.

The print loop and the callback share the lists without any lock in the lesson. For a classroom print once a second, that is the whole design. A later writer that deletes from the list while the callback appends can lose an item or throw. Treat the lists as append-only in this pattern.

The lists also live only as long as the process. Nothing in the lesson flushes them on exit. A crash drops the cache. Writing out on a timer is the step the console demo is standing in for.

Questions people ask

Where are the lists stored?

On the wrapper subclass, created in its constructor. The trading application inherits them, so the live instance can read them directly.

What gets appended?

Delta, the option price, and the underlying price, each into its own list, when the callback's value for that field is not None.

How does the lesson show the cache filling?

A loop sleeps one second and prints the delta list from the application instance. New deltas show up as new entries.