Skip to content

Environments Handling

Oleg Rakhmatulin edited this page Aug 20, 2021 · 5 revisions

Starting from version 3.5.0 of this SDK we replace clients' class initialization using arguments list with configuration object pattern. Now each client class has a related configuration class that contains all required and optional initialization parameters in the form of public properties. By default, each configuration object is initialized for work on the live Alpaca environment available for brokerage accounts.

If you want to use another environment (for paper-only accounts for example) you have to specify proper URLs and security Id/key values. Starting from version 3.5.0 SDK provides built-in information about proper URLs for both live and paper-only environments. This information available for users through Alpaca.Markets.Environments static class, Alpaca.Markets.IEnvironment interface, and a set of helper extension methods.

This static Alpaca.Markets.Environments class provides two public properties: Live and Paper that expose information about respective Alpaca environments. Each property implements the same interface Alpaca.Markets.IEnvironment that contains a set of proper URLs for this environment which can be used for initializing client instances.

Alpaca provides 3 different subscription plans for the Data API v2 real-time streaming data: Free, Unlimited, and Business. The first one provides only IEX data and has some subscription limits. Other plans provide full SIP data without data subscription limits. The IAlpacaDataStreamingClient interface and its implementation from SDK provide unified access for both streams.

Use the Alpaca.Markets.Environments.Paper property and GetAlpacaDataStreamingClient factory method for creating client connected to the Free IEX data stream. For the Unlimied and Business SIP data stream use the Alpaca.Markets.Environments.Live property and GetAlpacaDataStreamingClient method in your code. So Paper environment for free data tier and Live for paid subscriptions.

Version 3.5.0 of SDK also provides a set of helper extension methods for even simplifying code above. For example, you can use a next code snippet for achieving same result:

var client = new Alpaca.Markets.AlpacaTradingClient(
    Environments.Paper.GetAlpacaTradingClientConfiguration(
        new SecretKey(KEY_ID, SECRET_KEY)));

or even better:

var client = Environments.Paper.GetAlpacaTradingClient(
    new SecretKey(KEY_ID, SECRET_KEY));
Clone this wiki locally