A comprehensive C# client library for the Saxo Bank OpenAPI, providing a strongly, idiomatic interface to all Saxo Bank API services.
-
Complete Authentication Support
-
OAuth2 Authorization Code Flow
-
PKCE Flow for public clients
-
Certificate-Based Authentication (CBA)
-
Automatic token management
-
Trading & Orders
-
Single orders
-
Multi-leg option strategies
-
OCO (One-Cancels-Other) orders
-
Algorithmic orders
-
Conditional orders
-
Block orders
-
Portfolio Management
-
Position tracking
-
Order management
-
Account balances
-
Performance metrics
-
Report generation
-
Market Data
-
Real-time price streaming
-
Market depth
-
Historical data
-
Options chain
-
Trade messages
-
Real-time Updates
-
WebSocket streaming
-
Event notifications
-
Connection management
-
Automatic reconnection
dotnet add package SaxoOpenAPIClient- Configure Services
services.AddSaxoClient(options =>
{
options.AppKey = "your-app-key";
options.AppSecret = "your-app-secret";
options.BaseUrl = "https://gateway.saxobank.com/sim/openapi/";
});- Authentication
// OAuth2 Authorization Code Flow
var authService = serviceProvider.GetService<IAuthenticationService>();
var authUrl = await authService.GetAuthorizationUrlAsync(new AuthorizationRequest
{
ClientId = "your-client-id",
RedirectUri = "your-redirect-uri",
State = "random-state"
});
// Handle callback and get token
var token = await authService.GetTokenFromCodeAsync(new TokenRequest
{
Code = "auth-code-from-callback",
ClientId = "your-client-id",
RedirectUri = "your-redirect-uri"
});- Place an Order
var orderService = serviceProvider.GetService<IOrdersService>();
var response = await orderService.PlaceOrderAsync(new OrderRequest
{
AccountKey = "your-account",
AssetType = "FxSpot",
BuySell = "Buy",
Amount = 10000,
Uic = 21, // EURUSD
OrderType = "Market"
});- Stream Real-time Prices
var marketDataService = serviceProvider.GetService<IMarketDataService>();
var subscription = await marketDataService.SubscribeToPricesAsync(
assetType: "FxSpot",
uic: 21,
refreshRate: 1000
);
// Handle price updates
subscription.PriceUpdated += (sender, price) =>
{
Console.WriteLine($"New price: Bid={price.Quote.Bid}, Ask={price.Quote.Ask}");
};For detailed documentation, see the Documentation directory:
The Examples directory contains complete working examples:
- Basic order placement
- Real-time price streaming
- Portfolio management
- OAuth2 authentication flows
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
dotnet testThe test suite includes:
- Unit tests
- Integration tests (requires Saxo Bank simulation environment)
- Performance tests
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please:
- Check the Documentation
- Search Issues
- Create a new issue if needed
This library follows security best practices:
- No sensitive data logging
- Secure token handling
- PKCE support for public clients
- Certificate validation
Feel free to open an issue or contact the maintainers.