Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.sportsxapp.com/llms.txt

Use this file to discover all available pages before exploring further.

The trading services are the core of any active integration with SportsX. STXOrderService lets you place single or batch orders, cancel them individually or all at once, and page through order history. STXTradeService gives you access to fill history, either across markets or scoped to a specific order. Both services are registered as transient. For task-oriented examples, see the Trading guide.
If you create orders with cancelOnDisconnect: true (the default), you must connect STXActiveOrdersChannel before placing any orders. The SDK throws STXCancelOnDisconnectNotEnabledException if the channel is not joined when the order is submitted.

ConfirmOrderAsync

Places a single order on the specified market. Return type: Task<STXConfirmedOrder>

Parameters

NameTypeRequiredDescription
priceintYesLimit price in cents (1–99 for binary markets).
quantityintYesNumber of contracts to trade.
marketIdstringYesID of the target market.
actionSTXOrderActionYesbuy or sell.
orderTypeSTXOrderTypeYeslimit or market.
clientOrderIdstringNoYour own reference ID, echoed back in responses and channel updates.
cancelOnDisconnectboolNoWhen true (default), the order is cancelled automatically if the active orders channel disconnects.

Example

// Connect the channel first when using cancelOnDisconnect
await _activeOrdersChannel.ConnectAsync();

STXConfirmedOrder order = await _orderService.ConfirmOrderAsync(
    price: 55,
    quantity: 10,
    marketId: "market-abc123",
    action: STXOrderAction.buy,
    orderType: STXOrderType.limit,
    clientOrderId: "my-ref-001");

Console.WriteLine($"Order placed: {order.OrderId}");

ConfirmOrdersAsync

Places multiple orders in a single request. Each order in the batch is described by an STXConfirmOrderParams object, which supports the same fields as ConfirmOrderAsync plus expiration options. Return type: Task<List<STXConfirmedOrder>>

Parameters

NameTypeRequiredDescription
confirmOrderParamsIEnumerable<STXConfirmOrderParams>YesCollection of order parameter objects.

Example

var orders = new List<STXConfirmOrderParams>
{
    new STXConfirmOrderParams
    {
        Price = 45,
        Quantity = 5,
        MarketId = "market-abc123",
        Action = STXOrderAction.buy,
        OrderType = STXOrderType.limit
    },
    new STXConfirmOrderParams
    {
        Price = 60,
        Quantity = 3,
        MarketId = "market-def456",
        Action = STXOrderAction.sell,
        OrderType = STXOrderType.limit,
        Expiration = STXOrderExpiration.GOOD_TILL_TIME,
        ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(30).ToUnixTimeMilliseconds() * 1000 // microseconds
    }
};

List<STXConfirmedOrder> confirmed = await _orderService.ConfirmOrdersAsync(orders);

CancelOrderAsync

Cancels a single open order by its order ID. Return type: Task<string> — the cancelled order ID.

Parameters

NameTypeRequiredDescription
orderIdstringYesID of the order to cancel.

Example

string cancelledId = await _orderService.CancelOrderAsync("order-xyz789");
Console.WriteLine($"Cancelled: {cancelledId}");

CancelOrdersAsync

Cancels a batch of orders by their IDs in one request. Return type: Task<List<STXCancelOrder>>

Parameters

NameTypeRequiredDescription
orderIdsIEnumerable<string>YesIDs of the orders to cancel.

Example

var idsToCancel = new[] { "order-001", "order-002", "order-003" };
List<STXCancelOrder> results = await _orderService.CancelOrdersAsync(idsToCancel);

CancelAllOrdersAsync

Cancels every open order for the currently authenticated user. Use with care in production. Return type: Task<List<STXCancelOrder>>

Parameters

This method takes no parameters.

Example

List<STXCancelOrder> cancelled = await _orderService.CancelAllOrdersAsync();
Console.WriteLine($"{cancelled.Count} orders cancelled");

GetMyOrdersAsync

Retrieves paginated order history for the authenticated user, with optional filtering by status and market. Return type: Task<STXMyOrderHistory>

Parameters

NameTypeRequiredDescription
statusFilterIEnumerable<STXOrderStatus>NoLimit results to orders with these statuses.
marketIdsIEnumerable<string>NoLimit results to orders on these markets.
limitint?NoMaximum number of orders to return.
offsetint?NoNumber of orders to skip, for pagination.
sortBySTXOrdersSortByField?NoField to sort by — insertedAt, price, quantity, marketId, and others.
sortOrderSTXSortOrder?Noasc or desc.

Example

STXMyOrderHistory history = await _orderService.GetMyOrdersAsync(
    statusFilter: new[] { STXOrderStatus.filled, STXOrderStatus.partially_cancelled },
    limit: 50,
    offset: 0,
    sortBy: STXOrdersSortByField.insertedAt,
    sortOrder: STXSortOrder.desc);

foreach (var order in history.Orders)
{
    Console.WriteLine($"{order.OrderId}{order.Status} — filled: {order.FilledQuantity}");
}

GetMyTradesAsync

Returns fill (trade) history for the authenticated user. All parameters are optional. Return type: Task<STXMyTradeHistory>

Parameters

NameTypeRequiredDescription
marketIdsIEnumerable<string>NoLimit results to fills on these markets.
limitint?NoMaximum number of trades to return.
offsetint?NoNumber of trades to skip, for pagination.
sortBySTXTradesSortByField?NoField to sort by.
sortOrderSTXSortOrder?Noasc or desc.

Example

STXMyTradeHistory trades = await _tradeService.GetMyTradesAsync(
    limit: 25,
    sortBy: STXTradesSortByField.insertedAt,
    sortOrder: STXSortOrder.desc);

GetMyTradesForOrderAsync

Returns all fills associated with a specific order ID. Useful when you need to reconcile an order’s fills after it has been partially or fully executed. Return type: Task<List<STXTrade>>

Parameters

NameTypeRequiredDescription
orderIdstringYesThe order whose fills you want to retrieve.

Example

List<STXTrade> fills = await _tradeService.GetMyTradesForOrderAsync("order-xyz789");

foreach (var fill in fills)
{
    Console.WriteLine($"Fill at {fill.Price} — qty {fill.Quantity}");
}

Enum reference

EnumValues
STXOrderActionbuy, sell
STXOrderTypelimit, market
STXOrderStatuscreated, requested, accepted, open, filled, cancelled, rejected, partially_cancelled, delayed
STXOrderExpirationGOOD_TILL_START, GOOD_TILL_TIME
STXOrdersSortByFieldinsertedAt, price, quantity, marketId, and others
STXSortOrderasc, desc
ExpirationTime for GOOD_TILL_TIME is a UNIX timestamp in microseconds (multiply milliseconds by 1000).

STXConfirmOrderParams

Use this class when building a batch for ConfirmOrdersAsync. It mirrors the parameters of ConfirmOrderAsync and adds expiration support.
public class STXConfirmOrderParams
{
    public int Price { get; set; }
    public int Quantity { get; set; }
    public string MarketId { get; set; }
    public STXOrderAction Action { get; set; }
    public STXOrderType OrderType { get; set; }
    public string ClientOrderId { get; set; }
    public bool CancelOnDisconnect { get; set; } = true;
    public STXOrderExpiration? Expiration { get; set; }
    public long? ExpirationTime { get; set; }  // UNIX microseconds — required for GOOD_TILL_TIME
}

Real-time channels

Subscribe to these channels to receive order and fill updates without polling.
ChannelEventDescription
STXActiveOrdersChannelOnOrderUpdateFires on every order state transition. Also gates cancelOnDisconnect logic — must be connected before placing orders with that flag.
STXActiveTradesChannelOnTradeFires whenever a new fill is created.
_activeOrdersChannel.OnOrderUpdate += update =>
{
    Console.WriteLine($"Order {update.Id}{update.Status}, filled: {update.FilledQuantity}");
};

await _activeOrdersChannel.ConnectAsync();

Errors

ExceptionWhen it is thrown
STXCancelOnDisconnectNotEnabledExceptionConfirmOrderAsync or ConfirmOrdersAsync was called with cancelOnDisconnect: true but STXActiveOrdersChannel is not connected.
STXTokenExpiredExceptionThe current JWT has expired. Refresh the token with STXTokenService.RefreshTokenAsync and retry.
See Errors and retries for the full exception hierarchy and retry strategies.