Skip to content

Alpaca Streaming API

Oleg Rakhmatulin edited this page Jul 21, 2019 · 18 revisions

Alpaca Streaming API .NET Client

All WebSocket-based streaming messages described here are available for you via events of Alpaca.Markets.SockClient class. All these events provides you read-only interfaces for related JSON objects.

Client instance creation

For creating instance of Alpaca.Markets.SockClient object you have to specify API ID, secret key and API endpoint URL. You have two main options - provide these values as parameters in constructor (last parameter is optional and can be omitted):

var client = new Alpaca.Markets.SockClient(
    KEY_ID, SECRET_KEY, alpacaRestApi: new Uri(API_URL));

or use IConfiguration interface for providing data from configuration providers. In 2nd case API ID and secret key should be provided as configuration values keyId and secretKey respectively and endpoint URL can be optionally provided as alpacaRestApi configuration value.

General usage pattern

You have to call ConnectAsync method for connecting stream and DisconnectAsync for disconnecting. It also would be very helpful to dispose instance of Alpaca.Markets.SockClient object using standard .NET IDisposable pattern.

Examples

See usage examples for each event in unit test SockClientTest.cs.

Clone this wiki locally