Observing changes in sub-scenarios
The Change Observer block watches a set of sub-scenarios for changes in the value of one of the sub-scenario variables. You specify which variable you want to watch. When the value changes, the Change Observer block sends data to its
change output feed. The output feed indicates the old value and the new value. You use one Change Observer block for each variable that you want to observe. See
Change Observer v2.0 for details.
For example, suppose your main scenario uses the Trader scenario block and the Price Checker scenario block. The Trader scenario block output fields include:
instance id [string] instance owner [string] instance created [Boolean] instance ended [Boolean] instance status [UNKNOWN, RUNNING, ENDED or FAILED] trading [Boolean] The Price Checker scenario block output fields include the following:
instance id [string] instance owner [string] instance created [Boolean] instance ended [Boolean] instance status [UNKNOWN, RUNNING, ENDED or FAILED] price [number] In your main scenario, you create several Trader sub-scenarios — each one trades in a different market. When a Trader sub-scenario finishes trading, it sends data to its output feed and this data includes trading=false.
You also create several Price Checker sub-scenarios — one for each type of stock symbol you are trading. When the price of a stock being checked changes, the Price Checker sub-scenario sends data to its output feed and this data includes the new price.
In your main scenario, you want to monitor changes in the Trader trading field and in the Price Checker price field. To do this, use an instance of the Change Observer block for each field. The block wiring would look like this:
The Change Observer_PRICE CHECKER block sends an output feed whenever a Price Checker sub-scenario sends a price change to its output feed. The Change Observer_TRADER block sends an output feed whenever a Trader sub-scenario stops trading or starts trading, as indicated by the trading field in its output feed. You would wire their fields as follows:
Wire Price Checker 1 Output Feed | To Change Observer_PRICE CHECKER Input Feed |
Output feed: output | Input feed: input |
instance id [string] output field | stream [string] input field |
price [float] output field | watchValue [string] input field |
Wire Trader 1 Output Feed | To Change Observer_TRADER Input Feed |
Output feed: output | Input feed: input |
instance id [string] output field | stream [string] input field |
trading [boolean] output field | watchValue [string] input field |
The rules to implement this would look something like the following: (Note that the name of the Change Observer block output feed is change.