# C# SDK

> Official .NET SDK for the STX trading API.

Source: https://docs.stxapp.io/sdks/csharp/

:::note
**.NET 8 and .NET 10.** Published to NuGet as [**STX.Sdk**](https://www.nuget.org/packages/STX.Sdk). MIT-licensed. A .NET 8 or .NET 9 app resolves the `net8.0` build; a .NET 10 app resolves `net10.0`.
:::

`STX.Sdk` is the official .NET SDK for the STX trading exchange. It wraps the exchange HTTP API and Phoenix WebSocket channels as a set of services you register into the .NET dependency-injection container and resolve anywhere in your app.

One package, one `ConfigureSTXServices` call, dozens of typed service + channel clients.

- **Services** for everything the exchange exposes: login, markets, events, orders, trades, settlements, profile, terms-and-conditions, geolocation.
- **Channel wrappers** for real-time: portfolio balance, active orders/trades, positions, market updates, user info.
- **Automatic session management**: optional background services keep the JWT refreshed and the geolocation token current.

```bash
dotnet add package STX.Sdk
```

```csharp
// Register once in Program.cs / Startup.cs
services.ConfigureSTXServices(
    STXEnvironment.OntarioDemo,
    STXApiKeyCredentials.FromPemFile(keyId, "~/.stx/ontario.pem"));

// Resolve and use anywhere
var markets = await marketService.GetMarketInfosWithCountAsync();
```

Primarily targeted at **market makers** writing low-latency .NET trading bots, but the surface is generic, so any integrator building a .NET app against STX can use it.

## Units

The SDK speaks **integer cents**: `price: 10` is 10¢, and `Price`, `Fee` and every
other amount come back as integers in cents.

If you also read the REST and WebSocket documentation you will see prices written as
dollar strings (`"0.10"`). Same prices, different surface. Pick one surface per
component and the conversion never comes up; mix them and convert at the boundary.

## Where to go next

  - [Quickstart](/sdks/csharp/quickstart/): Install, authenticate, and make your first call in under five minutes.
  - [Installation](/sdks/csharp/installation/): NuGet, supported runtimes, dependencies.
  - [Authentication](/sdks/csharp/authentication/): API keys, Ed25519 signing, scopes.
  - [Configuration](/sdks/csharp/configuration/): DI registration, endpoint URIs per environment.
  - [Market data](/sdks/csharp/markets/): Query markets, events, sports, and competitions.
  - [Trading](/sdks/csharp/trading/): Place and cancel orders; fetch order/trade history.
  - [WebSockets](/sdks/csharp/websockets/): Phoenix channels for real-time orders, trades, balance, markets.
  - [Errors & retries](/sdks/csharp/errors-and-retries/): Exceptions you'll encounter and the built-in Polly retry.

## Example apps

Two reference apps live in one MIT-licensed repository:

- **`console/`**: CLI trading bot showing authentication, market subscriptions, and order placement from a `BackgroundService`.
- **`webapi/`**: ASP.NET Core 8 service exposing the SDK over HTTP, with Swagger UI.

Both run against the public demo environment out of the box:

```bash
git clone https://github.com/stxapp/stx-csharp-demo.git
```
