# STXClient

> The REST client: options and every method.

Source: https://docs.stxapp.io/sdks/csharp/reference/stx-client/

```csharp
public sealed class STXClient : IDisposable
public STXClient(STXClientOptions? options = null)
```

The client is thread-safe; share one per exchange. Every method is async and takes an optional `CancellationToken ct` as its last parameter.

## STXClientOptions

| Property | Type | Default |
|---|---|---|
| `Region`, `Environment` | `STXRegion?`, `STXEnvironment?` | from `STX_REGION`, `STX_ENV` or the profile |
| `Host` | `string?` | from `STX_HOST` or the profile; overrides `Region` and `Environment` |
| `KeyId` | `string?` | from `STX_KEY_ID` or the profile |
| `PrivateKey` | `string?`: PEM text or a path | from `STX_PRIVATE_KEY` or the profile |
| `Signer` | `Func<byte[], byte[]>?` | instead of `PrivateKey` |
| `ClientId`, `ClientSecret` | `string?`: an OAuth app | from `STX_OAUTH_CLIENT_ID`, `STX_OAUTH_CLIENT_SECRET` or the profile |
| `Scope` | `string?`: the app token's scopes, space-separated | every app scope the app is allowed |
| `Profile` | `string?` | `STX_PROFILE`, then `default` |
| `VerifyTls` | `bool?` | `true` |
| `Retry` | `STXRetryPolicy` | `STXRetryPolicy.Default` |
| `Timeout` | `TimeSpan` | 30 seconds |
| `OnResponse` | `Action<STXResponseEvent>?` | none |
| `LoggerFactory` | `ILoggerFactory?` | none |
| `HttpHandler` | `HttpMessageHandler?` | a pooled `SocketsHttpHandler` |
| `UseEnvironment` | `bool` | `true`: read `STX_*` variables and the credentials file |

Properties: `BaseUrl`, `SocketUrl`, `Host`, `Credentials` (`STXApiKeyCredentials?`), `AppToken` (`STXAppToken?`), `Options`; static `UserAgent`.

## Identity

| Method | Returns |
|---|---|
| `GetMeAsync()` | `Me`: `UserId`, `AccountId`, `KeyId`, `Scope` |
| `GetUserIdAsync()` | `string`, cached after the first call |

## Markets and events

| Method | Returns |
|---|---|
| `GetMarketsAsync(marketIds, eventIds, status, trading, sports, competitions, sortBy, sortDirection, limit, cursor)` | `STXPage<Market>` |
| `GetAllMarketsAsync(...)` (same filters, no cursor) | `IAsyncEnumerable<Market>` |
| `GetMarketAsync(marketId)` | `Market`, or `STXNotFoundException` |
| `GetEventsAsync(eventIds, sports, competitions, eventTypes, title, status, promoted, sortBy, sortDirection, limit, cursor)` | `STXPage<Event>` |
| `GetAllEventsAsync(...)` | `IAsyncEnumerable<Event>` |
| `GetEventPlayersAsync(eventId)` | `EventPlayers`: `Teams`, `Stats` |
| `GetMarketTypesAsync()` | `IReadOnlyDictionary<string, MarketType>`, keyed by rule |
| `CreateMarketsAsync(eventId, IEnumerable<STXNewMarket> markets, dryRun, validate)` | `IReadOnlyList<STXCreateMarketResult>`: `Index`, `Status`, `MarketId`, `Reason`, `Market`; see [Create markets](/sdks/csharp/create-markets/) |
| `GetCapabilitiesAsync(refresh, probeChannels)` | `STXCapabilities`; see [What you can do](/sdks/csharp/capabilities/) |

List filters take any `IEnumerable<string>`, e.g. `status: ["open", "pre_open"]`.

## Orders

| Method | Returns |
|---|---|
| `PlaceOrderAsync(marketId, action, orderType, quantity, price, clientOrderId, expiration, expirationTime, cancelOnDisconnect)` | `Order` |
| `PlaceOrderAsync(STXOrderRequest order)` | `Order` |
| `PlaceOrdersAsync(IEnumerable<STXOrderRequest> orders)` | `IReadOnlyList<STXBatchOrderResult>`: `Order` or `Errors`, `Ok` |
| `CancelOrderAsync(orderId)` | `Cancellation`: `OrderId`, `Status` |
| `CancelOrdersAsync(IEnumerable<string> orderIds)` | `IReadOnlyList<Cancellation>` |
| `CancelAllOrdersAsync()` | `IReadOnlyList<Cancellation>` |
| `GetOrdersAsync(orderIds, clientOrderIds, marketIds, status, limit, cursor)` | `STXPage<Order>` |
| `GetAllOrdersAsync(...)` | `IAsyncEnumerable<Order>` |
| `GetOrderAsync(orderId)` | `Order` |

`STXOrderAction.Buy`, `STXOrderAction.Sell`, `STXOrderType.Limit` and `STXOrderType.Market` name the wire values.

## Account

| Method | Returns |
|---|---|
| `GetBalanceAsync()` | `Balance` |
| `GetPositionsAsync(marketIds)` | `IReadOnlyList<Position>` |
| `GetFillsAsync(marketIds, orderIds, status, limit, cursor)` / `GetAllFillsAsync` | `STXPage<Fill>` / `IAsyncEnumerable<Fill>` |
| `GetAccountMarketStatsAsync(marketIds, eventIds, excludeZeroSettlements, fromTime, toTime, sports, competitions, limit, cursor, unsettledOnly)` / `GetAllAccountMarketStatsAsync` | `STXPage<MarketStat>` / `IAsyncEnumerable<MarketStat>` |
| `GetSettlementsAsync(marketIds, type, limit, cursor)` / `GetAllSettlementsAsync` | `STXPage<Settlement>` / `IAsyncEnumerable<Settlement>` |
| `GetDepositsAsync`, `GetWithdrawalsAsync`, `GetAdjustmentsAsync` (`limit`, `cursor`) and their `GetAll` twins | `PaymentTransaction` pages |
| `GetFeesAsync` / `GetAllFeesAsync` | `FeeTransaction` pages |
| `GetLoyaltyAsync` / `GetAllLoyaltyAsync` | `Transaction` pages |
| `AcceptTermsAsync(acceptTerms, acceptPrivacy, acceptHouseRules)` | `string`: the exchange's message |
| `GetLeaderboardAsync(period, category, metric, limit)` | `Leaderboard` |
| `GetLeaderboardStandingAsync(period, category)` | `LeaderboardStanding` |
| `UpdateProfileAsync(handle, avatar, leaderboardOptIn)` | `Me` |

## WebSocket

| Method | Returns |
|---|---|
| `CreateWebSocket(STXWebSocketOptions? options)` | `STXWebSocket`; see [STXWebSocket](/sdks/csharp/reference/stx-websocket/) |

## STXPage&lt;T&gt;

`IReadOnlyList<T>` plus `Cursor` (`string?`, null on the last page) and `HasMore`.

## STXRetryPolicy

A record: `MaxAttempts` (3), `InitialBackoff` (0.5 s), `MaxBackoff` (30 s), `Jitter` (true). `STXRetryPolicy.Default`, `STXRetryPolicy.None`; change one with `with { MaxAttempts = 5 }`.

## STXResponseEvent

`Method`, `Path`, `Status` (null when no answer arrived), `Attempt`, `Duration`, `RequestBody`, `ResponseBody`.

## STXApiKeyCredentials

`new STXApiKeyCredentials(keyId, privateKey)` (PEM text or path) or `new STXApiKeyCredentials(keyId, signer)`. `Headers(method, path)` returns the three signed headers for one request; `BuildMessage(timestampMs, method, path)` the string that is signed.
