> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sportsxapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch settlement history with the SportsX C# SDK

> Query your account's settlement history by type, market, or date range using STXSettlementService, and subscribe to live settlements via WebSocket.

A settlement is the final payout when a prediction market resolves. Every position you hold in a market that closes generates a settlement record on your account — won, lost, or pushed. You can query settlement history via `STXSettlementService` or receive live settlement events over a WebSocket channel.

## Fetch settlement history

```csharp theme={null}
using STX.Sdk.Enums;
using STX.Sdk.Services;

var settlements = serviceProvider.GetRequiredService<STXSettlementService>();

var history = await settlements.GetMySettlementsAsync(
    limit:          50,
    sortBy:         STXSortOrder.desc,
    settlementType: STXTradeSettlementType.won);

foreach (var s in history.Settlements)
{
    Console.WriteLine($"{s.SettlementId}  {s.MarketId}  {s.Type}  P&L: {s.Amount}c");
}
```

### Filter options

| Parameter          | Notes                                                           |
| ------------------ | --------------------------------------------------------------- |
| `limit` / `offset` | Pagination controls                                             |
| `settlementType`   | `STXTradeSettlementType.won`, `lost`, `pushed`, or others       |
| `marketIds`        | Array of market IDs — only return settlements for those markets |
| `from` / `to`      | Timestamp window for date-range queries                         |

<Tip>
  Combine `marketIds` with a date range to reconcile P\&L for a specific event after it settles.
</Tip>

## Real-time settlements

For bots that need to act immediately when a market settles — for example to redeploy freed-up capital — subscribe to `STXActiveSettlementsChannelWrapper` instead of polling:

```csharp theme={null}
var channel = serviceProvider
    .GetRequiredService<STXActiveSettlementsChannelWrapper>();

channel.OnSettlement += s =>
    _logger.LogInformation(
        "Settled {MarketId}: {Type} {Amount}c",
        s.MarketId, s.Type, s.Amount);

await channel.ConnectAsync();
```

The channel pushes a settlement event as soon as the exchange resolves a market you hold a position in. It requires an authenticated session — call `LoginAsync` before `ConnectAsync`.

## See also

* [Trading](/sdks/csharp/trading) — order fills that accumulate into positions before settlement
* [WebSockets](/sdks/csharp/websockets) — full channel API and reconnection behavior
