Welcome to the STX SDK Wiki. The STX SDK serves as a wrapper for GraphQL endpoints and Phoenix sockets, designed specifically for .NET 8 applications.
Before diving in, ensure you have:
STX.Sdk.dll
or the STX.Sdk
NuGet package.STX.Sdk.dll
STX.Sdk.dll
file.STX.Sdk.dll
file is stored.STX.Sdk.dll
.STX.Sdk
NuGet packageSTX.Sdk
.Once the DLL or package is added, you can start working with the STX Sdk.
To begin, add STX services to your service collection:
// Add STX Services to service collection (to DI container)
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");
Upon successfully adding the necessary components, you can begin using the STX services available to you via dependency injection. Below is an example of how you can obtain an instance of STXLoginService
:
public class LoginController : ControllerBase
{
private readonly STXLoginService _loginService;
private readonly ILogger _logger;
public LoginController(
STXLoginService loginService,
ILogger<LoginController> logger)
{
_loginService = loginService;
_logger = logger;
}
// Additional code to utilize the LoginService
}
STX Services encompass a variety of functionalities. Broadly, they can be classified into two main types:
GraphQL endpoints services
Phoenix channels services
GraphQL endpoints services act as wrappers around the STX GraphQL endpoints. The core services within this category include:
STXLoginService
STXProfileService
STXTokenService
STXOrderService
STXMarketService
These services primarily interact with their respective STX GraphQL endpoints, having jurisdiction over similar-named functionalities.
The STXLoginService
handles login and terms and conditions acceptance through GraphQL endpoints.
It depends on:
STXTokenService
STXSessionBackgroundService
HttpClient
for specific API requests.To utilize the STXLoginService, first acquire its instance via dependency injection:
public class LoginController : ControllerBase
{
private readonly STXLoginService _loginService;
private readonly ILogger _logger;
public LoginController(
STXLoginService loginService,
ILogger<LoginController> logger)
{
_loginService = loginService;
_logger = logger;
}
}
public async Task<IActionResult> Login([FromBody] LoginModel model)
{
if (ModelState.IsValid)
{
var result = await _loginService.LoginAsync(model.Email, model.Password);
return Ok(result);
}
return BadRequest();
}
public async Task<IActionResult> CheckTnC(string email)
{
var result = await _loginService.CheckTermsAndConditionsAsync(email);
return Ok(result);
}
public async Task<IActionResult> AcceptTnC(string version)
{
var result = await _loginService.AcceptTermsAndConditionsAsync(version);
return Ok(result);
}
public async Task<IActionResult> GetTnC()
{
var result = await _loginService.GetTermsAndConditionsAsync();
return Ok(result);
}
public async Task<IActionResult> Confirm2FA([FromBody] Confirm2FAModel model)
{
if (ModelState.IsValid)
{
var result = await _loginService.Confirm2FAAsync(model.Code);
return Ok(result);
}
return BadRequest();
}
The STXProfileService
is responsible for retrieving user profile information through the GraphQL userProfile
endpoint. It uses the base service STXGraphQLBaseService
for authorization and shared logic.
Initialize the STXProfileService:
public class ProfileController : ControllerBase
{
private readonly STXProfileService _profileService;
private readonly ILogger _logger;
public ProfileController(
STXProfileService profileService,
ILogger<LoginController> logger)
{
_profileService = profileService;
_logger = logger;
}
}
public async Task<IActionResult> GetProfile()
{
var result = await _profileService.GetProfileAsync();
return Ok(result);
}
The STXTokenService
is responsible for authenticating users, managing access and refresh tokens, and handling session management through GraphQL endpoints.
Acquire the STXTokenService instance:
public class TokenController : ControllerBase
{
private readonly STXTokenService _tokenService;
private readonly ILogger _logger;
public TokenController(
STXTokenService loginService,
ILogger<TokenController> logger)
{
_tokenService = loginService;
_logger = logger;
}
}
public IActionResult GetTokens()
{
var result = _tokenService.Tokens;
return Ok(result);
}
public async Task<IActionResult>LoginAsync(
string email,
string password,
bool keepSessionAlive,
string deviceId = STXDefaultSettings.DeviceId)
{
var result = await LoginAsync(email, password, keepSessionAlive, deviceId)
return Ok(result);
}
public async Task<IActionResult> RefreshTokenAsync()
{
var result = await _tokenService.RefreshTokenAsync();
return Ok(result);
}
The STXOrderService
is responsible for managing user orders, including placing, confirming, retrieving, and canceling single or bulk orders, by communicating with GraphQL endpoints and integrating geo-compliance validation through background services.
Inject STXOrderService:
public class OrderController : ControllerBase
{
private readonly STXOrderService _orderService;
private readonly ILogger _logger;
public OrderController(
STXOrderService orderService,
ILogger<OrderController> logger)
{
_orderService = orderService;
_logger = logger;
}
}
public async Task<IActionResult> ConfirmOrder([FromBody] ConfirmOrderModel model)
{
if (ModelState.IsValid)
{
var result = await _orderService.ConfirmOrderAsync(
price: model.Price,
quantity: model.Quantity,
marketId: model.MarketId,
action: model.Action,
orderType: model.OrderType);
return Ok(result);
}
return BadRequest();
}
public async Task<IActionResult> ConfirmOrders([FromBody] List<STXConfirmOrderParams> orderParams)
{
var result = await _orderService.ConfirmOrdersAsync(orderParams);
return Ok(result);
}
public async Task<IActionResult> CancelOrder(string orderId)
{
if (ModelState.IsValid)
{
var result = await _orderService.CancelOrderAsync(orderId);
return Ok(result);
}
return BadRequest();
}
public async Task<IActionResult> CancelOrders([FromBody] List<string> orderIds)
{
if (orderIds == null || !orderIds.Any())
return BadRequest("Order IDs are required.");
var result = await _orderService.CancelOrdersAsync(orderIds);
return Ok(result);
}
public async Task<IActionResult> CancelAllOrders()
{
var result = await _orderService.CancelAllOrdersAsync();
return Ok(result);
}
public async Task<IActionResult> GetMyOrders(
IEnumerable<string> marketIds,
STXOrderStatus? status,
STXOrdersSortByField sortBy = STXOrdersSortByField.TIME,
STXSortOrder sortOrder = STXSortOrder.DESC,
int page = 1,
int pageSize = 100)
{
var orders = await _orderService.GetMyOrdersAsync(
marketIds: marketIds,
orderStatus: status,
ordersSortByField: sortBy,
sortOrder: sortOrder,
page: page,
pageSize: pageSize);
return Ok(orders);
}
The STXMarketService
provides access to market information via GraphQL endpoints. It supports querying detailed and lightweight market data, batched fetching, and extraction of sports and competitions. The service handles pagination, filtering, and batching limits for optimized performance.
Inject STXMarketService:
public class MarketController : ControllerBase
{
private readonly STXMarketService _marketService;
private readonly ILogger _logger;
public MarketController(
STXMarketService marketService,
ILogger<MarketController> logger)
{
_marketService = marketService;
_logger = logger;
}
}
T
Most data-fetching methods are generic to support flexible GraphQL querying. The type parameter T
represents the shape of the expected response and must be a class that matches the GraphQL selection set. Examples of T
include:
STXMarketInfo
: full market dataSTXShortMarketInfo
: lightweight data (e.g., only result, status, and marketId)STXMarketInfoShort
: used for extracting sport and competition metadatapublic async Task<IActionResult> GetMarkets([FromBody] STXMarketInfosFilter filter)
{
var result = await _marketService.GetMarketInfosWithCountAsync<STXMarketInfo>(filter);
return Ok(result);
}
public async Task<IActionResult> GetShortMarkets([FromQuery] List<string> marketIds)
{
var result = await _marketService.GetShortMarketInfosWithCountAsync(marketIds);
return Ok(result);
}
public async Task<IActionResult> GetSportsAndCompetitions()
{
var result = await _marketService.GetSportAndCompetitionsAsync();
return Ok(result);
}
The STXSettlementService
is responsible for retrieving the user's settlement history via STX's GraphQL mySettlementsHistory
endpoint. It allows filtering settlements by type and time range, with support for pagination.
Inject STXSettlementService:
public class SettlementController : ControllerBase
{
private readonly STXSettlementService _settlementService;
private readonly ILogger _logger;
public SettlementController(
STXSettlementService settlementService,
ILogger<SettlementController> logger)
{
_settlementService = settlementService;
_logger = logger;
}
}
public async Task<IActionResult> GetMySettlements()
{
var mySettlements = await _settlementService.GetMySettlementsAsync(new List<STXSettlementType> { STXSettlementType.CLOSED_LONG, STXSettlementType.CLOSED_SHORT });
return Ok(mySettlements);
}
These channels act as interfaces over the Phoenix websockets, allowing for real-time data communication. Key channels in this category include:
Each channel is designed to handle specific types of data streaming from the server.
To use STXPortfolioChannel, you first acquire its instance via dependency injection:
public class PortfolioController : ControllerBase
{
private readonly STXPortfolioChannel _portfolioChannel;
private readonly ILogger _logger;
public PortfolioController(
STXPortfolioChannel portfolioChannel,
ILogger<PortfolioController> logger)
{
_portfolioChannel = portfolioChannel;
_logger = logger;
}
// Additional code to utilize the PortfolioChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXPortfolio item)
{
// Handle received portfolio item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _portfolioChannel.StartAsync(bufferLength: 50000);
To use STXPositionsChannel, you first acquire its instance via dependency injection:
public class PositionsController : ControllerBase
{
private readonly STXPositionsChannel _positionsChannel;
private readonly ILogger _logger;
public PositionsController(
STXPositionsChannel positionsChannel,
ILogger<PositionsController> logger)
{
_positionsChannel = positionsChannel;
_logger = logger;
}
// Additional code to utilize the PositionsChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXPositions item)
{
// Handle received positions item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _positionsChannel.StartAsync(bufferLength: 50000);
To use STXActiveOrdersChannel, you first acquire its instance via dependency injection:
public class ActiveOrdersController : ControllerBase
{
private readonly STXActiveOrdersChannel _activeOrdersChannel;
private readonly ILogger _logger;
public ActiveOrdersController(
STXActiveOrdersChannel activeOrdersChannel,
ILogger<ActiveOrdersController> logger)
{
_activeOrdersChannel = activeOrdersChannel;
_logger = logger;
}
// Additional code to utilize the ActiveOrdersChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXActiveOrders item)
{
// Handle received activeOrders item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _activeOrdersChannel.StartAsync(bufferLength: 50000);
To use STXActiveSettlementsChannel, you first acquire its instance via dependency injection:
public class ActiveSettlementsController : ControllerBase
{
private readonly STXActiveSettlementsChannel _activeSettlementsChannel;
private readonly ILogger _logger;
public ActiveSettlementsController(
STXActiveSettlementsChannel activeSettlementsChannel,
ILogger<ActiveSettlementsController> logger)
{
_activeSettlementsChannel = activeSettlementsChannel;
_logger = logger;
}
// Additional code to utilize the ActiveSettlementsChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXActiveSettlements item)
{
// Handle received activeSettlements item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _activeSettlementsChannel.StartAsync(bufferLength: 50000);
To use STXActiveTradesChannel, you first acquire its instance via dependency injection:
public class ActiveTradesController : ControllerBase
{
private readonly STXActiveTradesChannel _activeTradesChannel;
private readonly ILogger _logger;
public ActiveTradesController(
STXActiveTradesChannel activeTradesChannel,
ILogger<ActiveTradesController> logger)
{
_activeTradesChannel = activeTradesChannel;
_logger = logger;
}
// Additional code to utilize the ActiveTradesChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXActiveTrades item)
{
// Handle received activeTrades item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _activeTradesChannel.StartAsync(bufferLength: 50000);
To use STXMarketChannel, you first acquire its instance via dependency injection:
public class MarketController : ControllerBase
{
private readonly STXMarketChannel _marketChannel;
private readonly ILogger _logger;
public MarketController(
STXMarketChannel marketChannel,
ILogger<MarketController> logger)
{
_marketChannel = marketChannel;
_logger = logger;
}
// Additional code to utilize the MarketChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXMarket item)
{
// Handle received market item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _marketChannel.StartAsync(bufferLength: 50000);
To use STXUserInfoChannel, you first acquire its instance via dependency injection:
public class UserInfoController : ControllerBase
{
private readonly STXUserInfoChannel _userInfoChannel;
private readonly ILogger _logger;
public UserInfoController(
STXUserInfoChannel userInfoChannel,
ILogger<UserInfoController> logger)
{
_userInfoChannel = userInfoChannel;
_logger = logger;
}
// Additional code to utilize the UserInfoChannel
}
You can listen to the data stream by overriding the OnReceive method or by registering a method to be called when data is received through the channel.
public override void OnReceive(STXUserInfo item)
{
// Handle received userInfo item
}
The default buffer length for accepting messages is 100,000 characters. To change this, use the parameter in the StartAsync method.
await _userInfoChannel.StartAsync(bufferLength: 50000);