Authentication
The client needs your API key ID and its Ed25519 private key, as a path to the PEM file or as the PEM text. Creating a key, how requests are signed, and why a signature fails are covered on Authentication.
There are three ways to hand the key to the client. When more than one is set, options win over environment variables, and environment variables win over the profile.
A credentials profile
Section titled “A credentials profile”Add a profile to ~/.stx/credentials:
[default]region = usenv = demokey_id = your-key-idkey_file = ~/.stx/stx-key.pemregion and env pick the exchange; the values are listed under Environments. new STXClient() reads STX_PROFILE, then the [default] section, so the examples in this guide work as written:
using var client = new STXClient();An API key works on one exchange only. To keep keys for more than one, add a section per key under any name you like, and pick one with Profile:
using var client = new STXClient(new STXClientOptions { Profile = "my-demo" });Environment variables
Section titled “Environment variables”export STX_REGION=us STX_ENV=demoexport STX_KEY_ID=your-key-idexport STX_PRIVATE_KEY=~/.stx/stx-key.pem # a path, or the PEM textSTX_HOST, STX_PROFILE and STX_CREDENTIALS (the path of the credentials file) are also read.
Options
Section titled “Options”using var client = new STXClient(new STXClientOptions{ Region = STXRegion.US, Environment = STXEnvironment.Demo, KeyId = configuration["Stx:KeyId"], PrivateKey = configuration["Stx:PrivateKeyPem"], // a path or the PEM text});If the key lives in an HSM or KMS, set Signer instead of PrivateKey: a Func<byte[], byte[]> that returns the raw 64-byte Ed25519 signature of the bytes it is given. UseEnvironment = false ignores the environment variables and the credentials file.
Check it works
Section titled “Check it works”var me = await client.GetMeAsync();Console.WriteLine($"{me.UserId} {me.Scope}"); // scope: read_only or read_write// bc2d4b34-5d21-4a2a-8af6-d1ad3846ac3f read_writeA bad key, or a machine clock that has drifted, throws STXAuthenticationException.
App tokens
Section titled “App tokens”An approved app creates markets with an OAuth app token instead of an API key (see Create markets). Give the client the app’s client id and secret, and it mints the token from the exchange’s /oauth/token with the client_credentials grant, keeps it, and mints a new one shortly before it expires or when the exchange refuses it.
using var writer = new STXClient(new STXClientOptions{ Region = STXRegion.US, Environment = STXEnvironment.Demo, ClientId = configuration["Stx:ClientId"], ClientSecret = configuration["Stx:ClientSecret"], Scope = "events markets.write", // leave out for every scope the app is allowed});STX_OAUTH_CLIENT_ID and STX_OAUTH_CLIENT_SECRET, or client_id, client_secret and scope in a credentials profile, work the same way. Keep the secret on your server.
The token is used where the API takes it: CreateMarketsAsync, and the reads an app can make (GetEventsAsync, GetMarketsAsync, GetEventPlayersAsync, GetMarketTypesAsync). A client with both an API key and an app signs those reads with the key and sends the token only to create markets. client.AppToken is the token itself: GetAsync() returns a valid one and GrantedScope is what the exchange granted. An exchange without OAuth answers 404 at /oauth/token, which throws STXNotAvailableException.

