# Market data

> STXMarketService + STXEventService method signatures.

Source: https://docs.stxapp.io/sdks/csharp/reference/market-data/

## `STXMarketService`

```csharp
public class STXMarketService
{
    // Full market info
    Task<STXMarketInfosWithCountResponse<STXMarketInfo>> GetMarketInfosWithCountAsync(STXMarketInfosFilter filter = null);

    // Generic variant: specify your own response type
    Task<STXMarketInfosWithCountResponse<T>> GetMarketInfosWithCountAsync<T>(STXMarketInfosFilter filter = null);

    // Short market info (lightweight: id, status, title only)
    Task<STXMarketInfosWithCountResponse<STXShortMarketInfo>> GetShortMarketInfosWithCountAsync(IEnumerable<string> marketIds);
    Task<STXMarketInfosWithCountResponse<STXShortMarketInfo>> GetShortMarketInfosWithCountWithLimitAsync(IEnumerable<string> marketIds);

    // Deprecated. Same data without the total count; kept for existing callers.
    [Obsolete] Task<STXMarketInfosResponse<STXMarketInfo>> GetMarketInfosAsync(STXMarketInfosFilter filter = null);
    [Obsolete] Task<STXMarketInfosResponse<T>> GetMarketInfosAsync<T>(STXMarketInfosFilter filter = null);
    [Obsolete] Task<STXMarketInfosResponse<STXShortMarketInfo>> GetShortMarketInfosAsync(IEnumerable<string> marketIds);
    [Obsolete] Task<STXMarketInfosResponse<STXShortMarketInfo>> GetShortMarketInfosWithLimitAsync(IEnumerable<string> marketIds);

    // Walk every page (see "Market data" guide)
    Task<List<STXMarketInfo>> GetAllMarketInfosAsync(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);
    Task<List<T>> GetAllMarketInfosAsync<T>(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);
    Task<List<STXMarketInfo>> GetAllOpenMarketInfosAsync(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);
    Task<List<T>> GetAllOpenMarketInfosAsync<T>(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);

    // Stream page by page instead of buffering the whole result set
    IAsyncEnumerable<List<T>> GetMarketInfoPagesAsync<T>(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);
    IAsyncEnumerable<List<T>> GetOpenMarketInfoPagesAsync<T>(STXMarketInfosFilter filter = null, int pageSize = 500, CancellationToken cancellationToken = default);

    // Sports / competitions catalog
    Task<List<STXSportAndCompetitions>> GetSportAndCompetitionsAsync();
}
```

The paging helpers ignore `Limit` and `Pagination` on the filter and never modify it. `pageSize` must stay within the server's maximum page size (exceeding it fails the request rather than returning a smaller page), and `MarketIds`, when set, makes the server ignore status, sports, trading and paging. They stop when the server stops returning a cursor (null or empty), throw `STXBadArgumentException` on a non-positive `pageSize`, and `STXPaginationStalledException` if the server ever repeats a cursor. `cancellationToken` is observed between pages.

### `STXMarketInfosFilter`

```csharp
public class STXMarketInfosFilter
{
    public IEnumerable<STXMarketInfosStatus> Status { get; set; }
    public STXMarketInfosTrading? Trading { get; set; }
    public IEnumerable<string> Sports { get; set; }
    public IEnumerable<string> Competitions { get; set; }
    public IEnumerable<string> EventIds { get; set; }
    public IEnumerable<string> MarketIds { get; set; }
    public STXKeysetPagination Pagination { get; set; }   // Cursor + Limit
    public int? Limit { get; set; }                       // caps one response
    public string KeywordRegex { get; set; }
    public STXFeatured? Featured { get; set; }
    public STXMarketFilter? FilterBy { get; set; }
    public STXMarketInfoFilters Filters { get; set; }
    public STXMarketFilterInput MarketFilter { get; set; }
    public STXPoweredByInput PoweredBy { get; set; }
    public STXMarketInfosSortBy SortBy { get; set; }
    public STXPslStats? Stat { get; set; }
}
```

Enums for `Status` and `Trading` live in `STX.Sdk.Enums`.

### `STXMarketInfo`

Key fields:

| | |
|---|---|
| `MarketId` | Unique ID |
| `EventId` | Parent event |
| `Status` | `open` / `closed` / `settled` / … |
| `Sport`, `Competition`, `Title` | Descriptive |
| `Rules` | Market type: `PLAYER_STAT_LINE`, `SPREAD`, `OVER_UNDER`, … |
| `Specifier` | Line value (e.g. `7.5`, or `"Player Name\|id\|STAT\|value"`) |
| `MaxPrice` | Settlement max (cents) |
| `Participants` | Teams/players involved |
| `GroupingId` | Identity of the set of mutually exclusive outcomes this market prices against. Opaque: compare for equality, never parse. Stable for the life of the market and present in every status, so it is the field to map market data on; unlike `Symbol` it does not move when a fixture is rescheduled. |
| `GroupingName` | The grouping in words (`"AL East Division"`, `"Spread - 1st Quarter"`). Descriptive, not stable: display it, join on `GroupingId` |

## `STXEventService`

```csharp
public class STXEventService
{
    Task<STXEventInfosResponse> GetEventInfosAsync(STXEventInfosFilter filter = null);
}
```

### `STXEventInfosFilter`

```csharp
public class STXEventInfosFilter
{
    public string Sport { get; set; }
    public string Competition { get; set; }
    public STXEventStatus[] EventStatusFilter { get; set; }
    public DateTime? EventStartFrom { get; set; }
    public DateTime? EventStartTo { get; set; }
    public int? Limit { get; set; }
}
```

### `STXEventInfo`

Bundles the event plus its markets:

```csharp
public class STXEventInfo
{
    public string EventId { get; set; }
    public string Title { get; set; }
    public string Sport { get; set; }
    public string Competition { get; set; }
    public STXEventStatus Status { get; set; }
    public DateTime EventStart { get; set; }
    public List<STXMarketInfo> MarketInfos { get; set; }
}
```

See [Markets](/sdks/csharp/markets/) for task-oriented examples.
