Environments Handling - alpacahq/alpaca-trade-api-csharp GitHub Wiki
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 must specify proper URLs and security ID/key values. Starting from version 3.5.0, SDK provides built-in information about URLs for live and paper-only environments. This information is 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 three different subscription plans for the Data API v2 real-time streaming data: Free, Unlimited, and Business. The first one offers only IEX data and has some subscription limits. Other plans provide complete 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, there is a Paper environment for the free data tier and a Live one for paid subscriptions.
Version 3.5.0 of SDK also provides helper extension methods to simplify the code above. For example, you can use the next code snippet to achieve 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));