> ## 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.

# Market data

> Market data operations on the STX Python SDK.

**4 operations.** See the [market data guide](/sdks/python/markets) for worked examples.

## `account_market_stats`

*Query — returns `list[AccountMarketStat]`.*

<sub>GraphQL field: `accountMarketStats`</sub>

List of all account market stats for a given account

**Parameters**

| Name         | Type                             | Required | Description                                        |
| ------------ | -------------------------------- | -------- | -------------------------------------------------- |
| `pagination` | `Pagination` (dict — see below)  | No       | The pagination to use for the results.             |
| `filter`     | `StatsFilter` (dict — see below) | No       | Optional filter for returned Account Market Stats. |

`pagination` accepts a dict with these keys (pass as `params={"pagination": {...}}`):

| Field   | Type  | Required | Description                                                          |
| ------- | ----- | -------- | -------------------------------------------------------------------- |
| `page`  | `int` | Yes      | The page of result where each page has `limit` values.  Integer >= 0 |
| `limit` | `int` | Yes      | The limit of values per page.  Integer value greater than 0.         |

`filter` accepts a dict with these keys (pass as `params={"filter": {...}}`):

| Field                      | Type        | Required | Description                                                                                                                                                                                                       |
| -------------------------- | ----------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `market_ids`               | `list[str]` | No       | A list of market ids to return stats for.                                                                                                                                                                         |
| `exclude_zero_settlements` | `bool`      | No       | A flag to determine if stats with 0 settlements should be allowed.     if flag is true stats with 0 settlements is not allowed in response.     if flag is false stats with 0 settlements is allowed in response. |
| `from_time`                | `int`       | No       | The list of markets that have last\_settled\_at on or after this time. This time should be specified in microseconds.                                                                                             |
| `to_time`                  | `int`       | No       | The list of markets that have last\_settled\_at on or before this time. This time should be specified in microseconds.                                                                                            |
| `sports`                   | `list[str]` | No       | Filter the markets by this sport                                                                                                                                                                                  |
| `competitions`             | `list[str]` | No       | Filter the markets by this competition                                                                                                                                                                            |

**Example**

```python theme={null}
result = client.account_market_stats(params={"pagination": ..., "filter": ...}, selections=Selection(...))
```

***

## `markets`

*Query — returns `Page[MarketInfo]`.*

<sub>Also available as `market_infos_with_count`. GraphQL field: `marketInfosWithCount`</sub>

Returns a list of the markets and filtered details with the count of entries

**Parameters**

| Name    | Type                                  | Required | Description                                       |
| ------- | ------------------------------------- | -------- | ------------------------------------------------- |
| `input` | `MarketInfosInput` (dict — see below) | No       | Optional list of IDs of the marketInfos to return |

`input` accepts a dict with these keys (pass as `params={"input": {...}}`):

| Field           | Type                                                                                     | Required | Description                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- |
| `market_ids`    | `list[str]`                                                                              | No       | A list of market ids to return settlements for. If specified, 'limit' is ignored.                  |
| `event_ids`     | `list[str]`                                                                              | No       | A list of event ids to return markets for.                                                         |
| `filter_by`     | `"ACTIVE"` \| `"LIVE_AND_UPCOMING"`                                                      | No       | The type of filter that should be applied                                                          |
| `filters`       | `MarketInfoFilters`                                                                      | No       | The filter that specifies the category, subcategory, section, grouping or subgrouping              |
| `market_filter` | `MarketFilterType`                                                                       | No       | The specification of markets to fetch by filter name                                               |
| `keyword_regex` | `str`                                                                                    | No       | The keyword regular expression to match.                                                           |
| `limit`         | `int`                                                                                    | No       | Number of records to constrain the return.  'nil' and '0' will not limit results                   |
| `sports`        | `list[str]`                                                                              | No       | Sport or competition to filter the markets by - i.e (Soccer, Cricket).                             |
| `competitions`  | `list[str]`                                                                              | No       | Competition to filter the markets by - i.e (NBA, UEFA).                                            |
| `status`        | `"SCHEDULED"` \| `"OPEN"` \| `"PRE_OPEN"` \| `"CANCELLED"` \| `"CLOSED"` \| … (7 values) | No       | Status of the market - (open, pre\_open).                                                          |
| `trading`       | `"TRUE"` \| `"FALSE"`                                                                    | No       | Trading filter - true means it's open for trading, false means can't trade yet.                    |
| `powered_by`    | `PoweredByInputObject`                                                                   | No       | Powered by - provider used to result this market.                                                  |
| `stat`          | `"BASES"` \| `"BK"` \| `"DOUBLES"` \| `"HIT_RUN_RBI"` \| `"HITS"` \| … (58 values)       | No       | Stat filter - can filter by PK or RBI.                                                             |
| `featured`      | `"TRUE"` \| `"FALSE"`                                                                    | No       | Featured flag.                                                                                     |
| `sort_by`       | `MarketInfosSortBy`                                                                      | No       | How to sort the results of the query.                                                              |
| `pagination`    | `KeysetPagination`                                                                       | No       | Cursor-based pagination options (cursor and limit). Only available for marketInfosWithCount query. |

**Example**

```python theme={null}
result = client.markets(params={"input": ...}, selections=Selection(...))
```

***

## `market_settlements`

*Query — returns `list[TransactionHistory]`.*

<sub>GraphQL field: `marketSettlements`</sub>

List of all settlement for a given market

**Parameters**

| Name         | Type                            | Required | Description                                   |
| ------------ | ------------------------------- | -------- | --------------------------------------------- |
| `market_id`  | `str`                           | Yes      | The market id to restrict the settlements to. |
| `pagination` | `Pagination` (dict — see below) | No       | The pagination to use for the results.        |

`pagination` accepts a dict with these keys (pass as `params={"pagination": {...}}`):

| Field   | Type  | Required | Description                                                          |
| ------- | ----- | -------- | -------------------------------------------------------------------- |
| `page`  | `int` | Yes      | The page of result where each page has `limit` values.  Integer >= 0 |
| `limit` | `int` | Yes      | The limit of values per page.  Integer value greater than 0.         |

**Example**

```python theme={null}
result = client.market_settlements(params={"market_id": ..., "pagination": ...}, selections=Selection(...))
```

***

## `trades_for_settlement`

*Query — returns `SettlementTrades`.*

<sub>GraphQL field: `tradesForSettlement`</sub>

Opening and closing Trades for given settlement\_id

**Parameters**

| Name            | Type  | Required | Description                                      |
| --------------- | ----- | -------- | ------------------------------------------------ |
| `settlement_id` | `str` | Yes      | The id of the settlement to find the trades for. |

**Example**

```python theme={null}
result = client.trades_for_settlement(params={"settlement_id": ...}, selections=Selection(...))
```

***

## Types

Reusable dict shapes referenced by the operations above. Pass as plain Python dicts; the SDK translates snake\_case keys to the wire format.

### `KeysetPagination`

Cursor-based keyset pagination.

| Field    | Type  | Required | Description                                                 |
| -------- | ----- | -------- | ----------------------------------------------------------- |
| `cursor` | `str` | No       | Opaque cursor for fetching the next page of results.        |
| `limit`  | `int` | No       | The limit of values per page. Integer value greater than 0. |

### `MarketFilterType`

Parameters for selecting markets based on filter tree

| Field   | Type                   | Required | Description                                                                       |
| ------- | ---------------------- | -------- | --------------------------------------------------------------------------------- |
| `group` | `"TRADE"` \| `"BASIC"` | Yes      | Which type of filter to query on                                                  |
| `path`  | `list[str]`            | Yes      | A path (list of node names) to a leaf in the market filter tree to set of markets |

### `MarketInfoFilters`

Parameters for selecting markets based on filter tree

| Field         | Type        | Required | Description                                                 |
| ------------- | ----------- | -------- | ----------------------------------------------------------- |
| `category`    | `list[str]` | No       | The category filter - can be a string or list of strings    |
| `subcategory` | `list[str]` | No       | The subcategory filter - can be a string or list of strings |
| `section`     | `list[str]` | No       | The section filter - can be a string or list of strings     |
| `grouping`    | `list[str]` | No       | The grouping filter - can be a string or list of strings    |
| `subgrouping` | `list[str]` | No       | The subgrouping filter - can be a string or list of strings |

### `MarketInfosSortBy`

A sort order that can be passed to a query requesting a list of market infos.

| Field       | Type                 | Required | Description                                  |
| ----------- | -------------------- | -------- | -------------------------------------------- |
| `name`      | `"EVENT_START_TIME"` | No       | The name of the field to sort by.            |
| `direction` | `"ASC"` \| `"DESC"`  | No       | The direction, `asc` or `desc` for the sort. |

### `PoweredByInputObject`

| Field      | Type  | Required | Description                         |
| ---------- | ----- | -------- | ----------------------------------- |
| `provider` | `str` | Yes      | Provider used to result this market |
| `link`     | `str` | No       | reference link of the provider.     |
