Clone our Wealth-Lab 8 Extension Demo project on GitHub to get a head start in developing your own Extensions!

Streaming Data Provider API

This document details the API for building Streaming Data Provider extensions for Wealth-Lab 8. A Streaming Data Provider allows WL8 to subscribe to symbol updates and get notified live whenever trades (ticks) occur for the subscribed symbol(s).

Build Environment

You can create a Streaming Data Provider in a .NET development tool such as Visual Studio 2022. Create a class library project that targets .NET8, then reference the WealthLab.Core library DLL that you'll find in the WL8 installation folder.

Note: If you are using Visual Studio 2022, it will need to be updated to at least version 17.8.6 to use .NET8.

Your Streaming Data Provider will be a class in this library that descends from StreamingProviderBase, which is defined in the WealthLab.Core library, in the WealthLab.Data namespace. After you implement and build your library, simply copy the resulting assembly DLL into the WL8 installation folder. The next time WL8 starts up, it will discover your Streaming Data Provider, making it available in appropriate locations of the WL8 user interface.

Visual Studio 2022 Build Environment

Accessing the Host (WL8) Environment

The IHost interface allows your extension to access information about the user's WealthLab environment. For example, the location of the user data folder, or obtaining a list of DataSets defined by the user. At any point in your extension's code base, you can access an instance of the IHost interface using the singleton class WLHost and its Instance property. Example:

//get user data folder
string folder = WLHost.Instance.DataFolder;

Configuration of a Streaming Data Provider

StreamingProviderBase ultimately descends from the base class Configurable, which provides a way to allow the user to configure the Historical Data Provider. Consult the Configurable class reference for details.

By default, StreamingProviderBase assigns the enum value ParameterList to its ConfigurableType property, so the Streaming Data Provider will use a ParameterList containing Parameter instances for configuration. You'll define these Parameters in the GenerateParameters method.

You can create Parameter instances to represent things like usernames, passwords, or API keys. When the user configures your Provider, WL8 will show a dialog box allowing them to enter appropriate, typed, values for each Parameter instance.

You are free to change the ConfigurableType to the alternate option of VanillaString, in which case you'll need to work directly with the Configuration string rather than the Parameters instances. In this case, you'll need to create your own Editor, see the topic on Providing User Interfaces for WealthLab 8 Components for details.

Important Descriptive Properties

The Configurable class provides descriptive properties that control how your Streaming Data Provider appears in WL8. The most important ones to override are Name, GlyphResource, Description, and URL.

Initialization

public virtual void Initialize()

If your Streaming Data Provider requires any kind of initialization before use, you can override this method and implement it here.

Connecting to the Streaming Data Source

protected abstract bool Connect()

Override this method to connect to the streaming data source. Typical streaming sources are:

  • Socket connections to a remote service.
  • Websocket connections to a remote service.
  • Threads that periodically poll and scrape web pages for quotes.

The Connect method is synchronous. Return the result of the connection attempt as the return value.

public bool IsConnected

Returns true if a previous connection attempt has been successful.

public void Disconnect(string reason, Exception ex = null)

If you detect a disconnection in your connection to the streaming data source, you can call this method to inform WL8 that the connection has been shut down. Pass the reason, and an instance of an Exception in the ex parameter if available.

Subscribing to Streaming Data

protected abstract void SubscribeTo(string symbol)

Override this method to subscribe to streaming data for the specified symbol. As streaming data for the symbol is received, you'll call the UpdateTick and UpdateBidAsk methods below to notify WL8 of the updates. WL8 handles multiple subscriptions for the same symbol behind the scenes, so you need not code any special logic to check if a symbol subscription already exists before subscribing.

protected abstract void UnsubscribeFrom(string symbol)

WL8 calls this method when it no longer requires streaming data for the specified symbol. You should override this method and cease streaming data for the symbol at this point.

public void UpdateTick(string symbol, DateTime dt, double price, double size, double prevClose)

As streaming data is received from the source, call this method to notify WL8 about incoming streaming updates. You should pass the symbol that was updated, the timestamp of the update (dt parameter), the price of the tick, and the size, or volume. If your streaming data source can deliver the previous closing price, pass this value in the prevClose parameter.

Timestamp Note: Streaming Data Providers can potentially support streaming symbols that trade in multiple markets in multiple time zones. The DateTime you pass in the dt parameter should be in the time zone of the market that the symbol trades in. If the Streaming Data Provider has a companion Historical Data Provider, it should be the same market that is returned from the Historical Data Provider's GetSymbolMarket method.

public void UpdateBidAsk(string symbol, double bid, double ask)

As bid/ask updates are received from the streaming data source, call this method to notify WL8 about them. Pass the symbol, the bid price, and the ask price. If only one of the bid/ask values is available, you can pass Double.NaN or -1 as the other value.

public void UpdateHeartbeat(DateTime dt)

Streaming data sources typically provide a mechanism called a heartbeat to communicate the health of the streaming connection. A heartbeat can also be established by subscribing to a frequently traded symbol. You can call the UpdateHeartbeat method whenever a heartbeat update is received. WL8 uses the heartbeat to close pending streaming bars in a timely manner. For this reason, it's important to call UpdateHeartbeat very shortly after each one-minute time marker. For example, an ideal time to call UpdateHeartbeat would be with DateTime timestamps (in the dt parameter) one second after each minute.

Timestamp Note: The heartbeat is not connected to a specific symbol or market, so the DateTime you pass in the dt parameter should be in the computer's local time zone.

public void UpdateTicksHighLow(string symbol, DateTime dt, double high, double low, double close, double size, double prevClose)

Similar to UpdateTick described above, you can call this version instead if the source returns an aggregate tick containing high, low, last price (close), and aggregate tick volume (size).

public int SubscriptionCount

Returns the number of symbols that are currently subscribed to.

Subscribing to Streaming Bars

Some streaming data sources offer subscriptions to streaming bars of data. The streaming data source will send notifications whenever a new streaming bar of a specific interval is completed. If the streaming data source that your Streaming Data Provider connects to supports this feature, use these properties and methods to implement it.

public virtual bool SupportsStreamingBarInterval(int interval)

Override and return true if the streaming data source supports streaming bars for the specified one-minute interval.

protected virtual void SubscribeToStreamingBar(string symbol, HistoryScale scale)

Override this method to initiate a streaming bar subscription for the following symbol and scale.

protected virtual void UnsubscribeFromStreamingBar(string symbol, HistoryScale scale)

WL8 calls this method when it no longer requires a streaming bar subscription for a particular symbol/scale combination. Override this method to end the subscription.

public void UpdateStreamingBar(string symbol, HistoryScale scale, BarData barData)

Call this method when a complete streaming bar of data is received from the source. Pass the symbol and scale and construct an instance of the BarData class and pass this in the barData parameter to communicate back the completed bar data.