Skip to content

Alpaca Streaming API

Oleg Rakhmatulin edited this page May 18, 2020 · 18 revisions

Alpaca Streaming API .NET Clients

All WebSocket-based streaming messages described here and here is available for you via events of Alpaca.Markets.AlpacaStreamingClient and Alpaca.Markets.AlpacaDataStreamingClient classes respectively. All these events provide you read-only interfaces for related JSON objects.

Client Instance Creation

For creating an instance of each client class we recommend using special extension methods of the IEnvironment interface designed for this task.

For Alpaca.Markets.AlpacaStreamingClient class:

var client = Environments.Paper.GetAlpacaStreamingClient(new SecretKey(KEY_ID, SECRET_KEY));

For Alpaca.Markets.AlpacaDataStreamingClient class:

var client = Environments.Paper.AlpacaDataStreamingClient(new SecretKey(KEY_ID, SECRET_KEY));

You can read more about these extension methods on this Wiki page.

General Usage Pattern

You have to call the ConnectAsync method for connecting the stream and the DisconnectAsync method for disconnecting. It also would be very helpful to free resources used by the instance of Alpaca.Markets.AlpacaStreamingClient or Alpaca.Markets.AlpacaDataStreamingClient objects using standard .NET IDisposable pattern. Another helpful method is ConnectAndAuthenticateAsync - you can use it if you do not want to track connected and authenticated states separately.

Clone this wiki locally