The Alpaca C#/.NET SDK provides access to the Alpaca Trading API and Market Data API through strongly typed REST and streaming clients.
| Package | Stable | Pre-release |
|---|---|---|
| Alpaca.Markets | ||
| Alpaca.Markets.Extensions |
The NuGet packages support .NET Standard 2.0, .NET Standard 2.1, .NET Framework 4.6.2, .NET 8.0, and .NET 10.0. Consumers can choose the target framework appropriate for their application. They do not need the repository's pinned SDK unless they are building this project from source.
Building the repository requires the exact .NET SDK version pinned in global.json. SDK roll-forward is disabled. Running every test target also requires the .NET 8 runtime.
Install the main SDK package:
dotnet add package Alpaca.MarketsInstall the optional extensions package when you need its additional helpers:
dotnet add package Alpaca.Markets.Extensions- Create a new console application with
dotnet new console. - Set
APCA_API_KEY_IDandAPCA_API_SECRET_KEYto paper-account credentials from the Alpaca dashboard. Never commit credentials to source control. - Replace the generated
Program.cswith:
using System;
using Alpaca.Markets;
using System.Threading.Tasks;
namespace AlpacaExample
{
internal static class Program
{
public static async Task Main()
{
var keyId = Environment.GetEnvironmentVariable("APCA_API_KEY_ID")
?? throw new InvalidOperationException("APCA_API_KEY_ID is required.");
var secretKey = Environment.GetEnvironmentVariable("APCA_API_SECRET_KEY")
?? throw new InvalidOperationException("APCA_API_SECRET_KEY is required.");
var client = Environments.Paper
.GetAlpacaTradingClient(new SecretKey(keyId, secretKey));
var clock = await client.GetClockAsync();
if (clock != null)
{
Console.WriteLine(
"Timestamp: {0}, NextOpen: {1}, NextClose: {2}",
clock.TimestampUtc, clock.NextOpenUtc, clock.NextCloseUtc);
}
}
}
}- Run the application with
dotnet run. It prints the current market timestamp and the next market open and close times.
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 Environments.Paper.GetAlpacaDataStreamingClient(...) to connect to the Free IEX data stream. Use Environments.Live.GetAlpacaDataStreamingClient(...) for the Unlimited and Business SIP data stream. In this context, Paper selects the free data tier and Live selects a paid data tier; trading clients choose paper or live order routing separately.
- Alpaca.Markets API reference
- Alpaca.Markets.Extensions API reference
- Usage examples
- Core SDK tests and extensions tests
- C# SDK Wiki
- Alpaca API documentation
The usage examples demonstrate near-to-real-world strategies. The Wiki contains additional information about environment handling, authentication types, order placement approaches, streaming subscriptions, and other SDK features.
Clone this repository or your fork, then restore, build, and test from the repository root:
dotnet tool restore
dotnet restore --locked-mode
dotnet build --no-restore
dotnet test --no-build --no-restoreThe preview helper restores the pinned DocFX tool, builds the documentation, and starts DocFX's local server.
On macOS or Linux:
./Documentation/serve.shOn Windows:
Documentation\serve.cmdOpen the local URL printed by DocFX, usually http://localhost:8080. Stop the server with Ctrl+C.
- Library / SDK issues: Bugs, feature requests, or questions specific to this SDK → GitHub Issues.
- Security vulnerabilities: Do not report them publicly. Follow our Security Policy.
- Alpaca API bugs: Bugs in the Alpaca API itself, its OpenAPI specs, or its documentation → alpacahq/alpaca-api.
- Community: API feature requests, general questions, and dashboard bugs → Alpaca Community Forum or Slack.
- Account help: Questions about your account, funding, or orders → Support request.
- Outages: Service status and incident updates → Status page.
Contributions are welcome. See CONTRIBUTING.md for setup, contribution scope, API compatibility requirements, quality checks, and the pull-request workflow. Participation is governed by our Code of Conduct.
Thanks a lot for all the contributors. See the complete list of project supporters in the CONTRIBUTORS file.