Skip to content

Settlements

A settlement is the final payout when a position closes. Query them with STXSettlementService.

using STX.Sdk.Enums;
using STX.Sdk.Services;
var settlements = serviceProvider.GetRequiredService<STXSettlementService>();
var history = await settlements.GetMySettlementsAsync(
settlementTypes: new[] { STXSettlementType.CLOSED_LONG, STXSettlementType.CLOSED_SHORT },
rollingWindowIncrement: STXRollingWindowIncrement.DAYS,
rollingWindowValue: 7,
page: 1,
pageSize: 50);
Console.WriteLine($"{history.Settlements.Count} of {history.TotalCount} settlements");
foreach (var s in history.Settlements)
{
Console.WriteLine($"{s.Id} {s.MarketId} {s.Type} P&L: {s.RealizedPnl}c");
}

settlementTypes is required. The rolling window bounds how far back to look, so the call above means “the last 7 days”.

CLOSED_LONG A long position closed by an opposing trade
CLOSED_SHORT A short position closed by an opposing trade
EXPIRED_LONG A long position held to market expiry
EXPIRED_SHORT A short position held to market expiry

The type describes how the position closed, not whether it made money. Use RealizedPnl for that.

Id, MarketId, AccountId Identifiers
Type One of the four above
RealizedPnl, GrossPnl, Fee Amounts in cents
Quantity Contracts settled
OpeningPrice, ClosingPrice Prices in cents
OpeningTradeId, ClosingTradeId The trades that opened and closed the position
InsertedAt, InsertedAtIso Unix time, and the same value as a DateTime

Subscribe for settlements as they land instead of polling:

var channel = serviceProvider.GetRequiredService<STXActiveSettlementsChannel>();
channel.SetOnReceiveAction(s =>
_logger.LogInformation("Settled {MarketId}: {Type} {Pnl}c", s.MarketId, s.Type, s.RealizedPnl));
await channel.StartAsync();

The channel topic is keyed on the user id, so under API-key authentication call STXIdentityService.GetMeAsync() once at startup before connecting. See WebSockets.

STXActiveSettlementsChannelWrapper wraps the same channel with a bounded queue if you would rather drain settlements yourself than handle a callback.

v1.5.9Changelogllms.txtllms-full.txt