-
-
Notifications
You must be signed in to change notification settings - Fork 78
Alpaca Streaming API
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.
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.
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.