Skip to main content
One call wires up every service, channel, and background worker the SDK provides.

Register services

using STX.Sdk;
using Microsoft.Extensions.DependencyInjection;

services.ConfigureSTXServices(
    graphQLUri:  "https://in-api-staging.stxapp.io/graphiql",
    channelsUri: "wss://in-api-staging.stxapp.io/socket/websocket?token={0}&vsn=2.0.0");
ConfigureSTXServices adds:
  • GraphQL HTTP client + typed services (STXLoginService, STXMarketService, STXOrderService, …)
  • Phoenix channel classes + wrappers (STXPortfolioChannel, STXActiveOrdersChannel, …)
  • User storage (STXUserStorage) as a singleton
  • Two hosted background services (STXSessionBackgroundService, STXGeoLocationBackgroundService) that the hosting framework starts automatically

Endpoints per environment

{0} in channelsUri is a format placeholder — the SDK substitutes the JWT before connecting.
EnvironmentgraphQLUrichannelsUri
Staginghttps://in-api-staging.stxapp.io/graphiqlwss://in-api-staging.stxapp.io/socket/websocket?token={0}&vsn=2.0.0
Productionhttps://in-api.stxapp.io/graphiqlwss://in-api.stxapp.io/socket/websocket?token={0}&vsn=2.0.0
Pull these from configuration, not code, so deploys can swap environments without recompiling:
services.ConfigureSTXServices(
    graphQLUri:  builder.Configuration["STX:GraphQLUri"]!,
    channelsUri: builder.Configuration["STX:ChannelsUri"]!);
appsettings.json:
{
  "STX": {
    "GraphQLUri":  "https://in-api-staging.stxapp.io/graphiql",
    "ChannelsUri": "wss://in-api-staging.stxapp.io/socket/websocket?token={0}&vsn=2.0.0"
  }
}
Override per environment with appsettings.Production.json or env vars (STX__GraphQLUri=…).

Dynamic endpoint resolution

If the endpoints depend on something inside DI (a tenant selector, feature flag, etc.), the overload that takes Func<IServiceProvider, string> gives you a callback:
services.ConfigureSTXServices(
    getGraphQLUri:  sp => sp.GetRequiredService<IMyEnvResolver>().GraphQLUri,
    getChannelsUri: sp => sp.GetRequiredService<IMyEnvResolver>().ChannelsUri);

Resolving services

Register once, resolve anywhere:
public class OrderPlacer
{
    private readonly STXOrderService _orders;
    private readonly STXMarketService _markets;

    public OrderPlacer(STXOrderService orders, STXMarketService markets)
    {
        _orders = orders;
        _markets = markets;
    }

    public async Task PlaceAsync() { /* ... */ }
}
Services are registered as Transient — safe to resolve per operation. Channel classes are Singleton so state (the active websocket, subscribed topics) is shared across the app.

Logging

The SDK uses Microsoft.Extensions.Logging. Hook up the provider you prefer:
services.AddLogging(builder =>
    builder
        .SetMinimumLevel(LogLevel.Information)
        .AddConsole());
The SDK logs at Debug for every GraphQL request/response body, Information for connection lifecycle, and Warning/Error for transient + fatal issues.

GeoComply / GeoLocation

ConfigureSTXServices registers STX.GeoComply and STX.GeoLocation internally. For trading bots running server-side, the default behavior is usually what you want — the geolocation token is fetched lazily and cached. If you’re embedding the SDK in a client app (desktop, mobile), integrate with GeoComply’s SDK per their docs.