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

# Trading

> Trading operations on the STX Python SDK.

**9 operations.** See the [trading guide](/sdks/python/trading) for worked examples.

## `cancel_all_orders`

*Mutation — returns `list[BatchCancelOrdersResult]`.*

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

Cancel of all open orders of an account.

**Parameters**

| Name           | Type                            | Required | Description |
| -------------- | ------------------------------- | -------- | ----------- |
| `geo_location` | `str`                           | No       | —           |
| `device_info`  | `DeviceInfo` (dict — see below) | No       | —           |

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

| Field       | Type  | Required | Description                                         |
| ----------- | ----- | -------- | --------------------------------------------------- |
| `device_id` | `str` | No       | The unique id of the device from the device itself. |

**Example**

```python theme={null}
result = client.cancel_all_orders(params={"geo_location": ..., "device_info": ...}, selections=Selection(...))
```

***

## `cancel_order`

*Mutation — returns `CancelOrderResult`.*

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

Cancels an order.

**Parameters**

| Name           | Type                            | Required | Description                                         |
| -------------- | ------------------------------- | -------- | --------------------------------------------------- |
| `order_id`     | `str`                           | Yes      | The id of the order that the user wishes to cancel. |
| `geo_location` | `str`                           | No       | —                                                   |
| `device_info`  | `DeviceInfo` (dict — see below) | No       | —                                                   |

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

| Field       | Type  | Required | Description                                         |
| ----------- | ----- | -------- | --------------------------------------------------- |
| `device_id` | `str` | No       | The unique id of the device from the device itself. |

**Example**

```python theme={null}
result = client.cancel_order(params={"order_id": ..., "geo_location": ..., "device_info": ...}, selections=Selection(...))
```

***

## `cancel_orders`

*Mutation — returns `list[BatchCancelOrdersResult]`.*

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

Batch cancel of orders.

**Parameters**

| Name           | Type                            | Required | Description                                                       |
| -------------- | ------------------------------- | -------- | ----------------------------------------------------------------- |
| `order_ids`    | `list[str]`                     | No       | The list of the ids of the orders that the user wishes to cancel. |
| `geo_location` | `str`                           | No       | —                                                                 |
| `device_info`  | `DeviceInfo` (dict — see below) | No       | —                                                                 |

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

| Field       | Type  | Required | Description                                         |
| ----------- | ----- | -------- | --------------------------------------------------- |
| `device_id` | `str` | No       | The unique id of the device from the device itself. |

**Example**

```python theme={null}
result = client.cancel_orders(params={"order_ids": ..., "geo_location": ..., "device_info": ...}, selections=Selection(...))
```

***

## `place_order`

*Mutation — returns `OrderResult`.*

<sub>Also available as `confirm_order`. GraphQL field: `confirmOrder`</sub>

Creates a new order.

**Parameters**

| Name           | Type                            | Required | Description                                                        |
| -------------- | ------------------------------- | -------- | ------------------------------------------------------------------ |
| `user_order`   | `UserOrder` (dict — see below)  | Yes      | The data structure holding the details for the order to be placed. |
| `geo_location` | `str`                           | No       | —                                                                  |
| `device_info`  | `DeviceInfo` (dict — see below) | No       | —                                                                  |

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

| Field                  | Type                                                     | Required | Description                                                                   |
| ---------------------- | -------------------------------------------------------- | -------- | ----------------------------------------------------------------------------- |
| `market_id`            | `str`                                                    | Yes      | The ID of the market to place the order on.                                   |
| `order_type`           | `"MARKET"` \| `"LIMIT"`                                  | Yes      | The type of order to place.                                                   |
| `action`               | `"BUY"` \| `"SELL"`                                      | Yes      | The action of the order.                                                      |
| `price`                | `float`                                                  | No       | The limit price for an order, which will be ignored for order\_type `market`. |
| `quantity`             | `float`                                                  | Yes      | The quantity of the order in number of contracts.                             |
| `client_order_id`      | `str`                                                    | No       | The optional order\_id sent by the client's for their reference.              |
| `cancel_on_disconnect` | `bool`                                                   | No       | The optional flag to cancel orders on disconnection.                          |
| `expiration`           | `"GOOD_TILL_START"` \| `"GOOD_TILL_TIME"`                | No       | The optional expiration condition for the order.                              |
| `expiration_time`      | `int`                                                    | No       | The optional expiration time for time-based expiration (UNIX microseconds).   |
| `ux_action`            | `"BUY_YES"` \| `"BUY_NO"` \| `"SELL_NO"` \| `"SELL_YES"` | No       | The optional UX action representing the user's intended action.               |

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

| Field       | Type  | Required | Description                                         |
| ----------- | ----- | -------- | --------------------------------------------------- |
| `device_id` | `str` | No       | The unique id of the device from the device itself. |

**Example**

```python theme={null}
result = client.place_order(params={"user_order": ..., "geo_location": ..., "device_info": ...}, selections=Selection(...))
```

***

## `place_orders`

*Mutation — returns `OrderResults`.*

<sub>Also available as `confirm_orders`. GraphQL field: `confirmOrders`</sub>

Creates a set of new orders.

**Parameters**

| Name           | Type                            | Required | Description                                                         |
| -------------- | ------------------------------- | -------- | ------------------------------------------------------------------- |
| `user_orders`  | `UserOrder` (dict — see below)  | Yes      | The data structure holding the details for the orders to be placed. |
| `geo_location` | `str`                           | No       | —                                                                   |
| `device_info`  | `DeviceInfo` (dict — see below) | No       | —                                                                   |

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

| Field                  | Type                                                     | Required | Description                                                                   |
| ---------------------- | -------------------------------------------------------- | -------- | ----------------------------------------------------------------------------- |
| `market_id`            | `str`                                                    | Yes      | The ID of the market to place the order on.                                   |
| `order_type`           | `"MARKET"` \| `"LIMIT"`                                  | Yes      | The type of order to place.                                                   |
| `action`               | `"BUY"` \| `"SELL"`                                      | Yes      | The action of the order.                                                      |
| `price`                | `float`                                                  | No       | The limit price for an order, which will be ignored for order\_type `market`. |
| `quantity`             | `float`                                                  | Yes      | The quantity of the order in number of contracts.                             |
| `client_order_id`      | `str`                                                    | No       | The optional order\_id sent by the client's for their reference.              |
| `cancel_on_disconnect` | `bool`                                                   | No       | The optional flag to cancel orders on disconnection.                          |
| `expiration`           | `"GOOD_TILL_START"` \| `"GOOD_TILL_TIME"`                | No       | The optional expiration condition for the order.                              |
| `expiration_time`      | `int`                                                    | No       | The optional expiration time for time-based expiration (UNIX microseconds).   |
| `ux_action`            | `"BUY_YES"` \| `"BUY_NO"` \| `"SELL_NO"` \| `"SELL_YES"` | No       | The optional UX action representing the user's intended action.               |

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

| Field       | Type  | Required | Description                                         |
| ----------- | ----- | -------- | --------------------------------------------------- |
| `device_id` | `str` | No       | The unique id of the device from the device itself. |

**Example**

```python theme={null}
result = client.place_orders(params={"user_orders": ..., "geo_location": ..., "device_info": ...}, selections=Selection(...))
```

***

## `orders`

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

<sub>Also available as `my_order_history`. GraphQL field: `myOrderHistory`</sub>

List of all orders for a user, all criteria is combined in an AND.

**Parameters**

| Name               | Type                                                                                   | Required | Description                                              |
| ------------------ | -------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------- |
| `order_ids`        | `list[str]`                                                                            | No       | The ids of the orders to return                          |
| `client_order_ids` | `list[str]`                                                                            | No       | The client order ids of the orders to return.            |
| `market_ids`       | `list[str]`                                                                            | No       | The id of the market to restrict the orders returned to. |
| `status`           | `"CREATED"` \| `"REQUESTED"` \| `"ACCEPTED"` \| `"OPEN"` \| `"FILLED"` \| … (9 values) | No       | Order status filter                                      |
| `pagination`       | `Pagination` (dict — see below)                                                        | No       | The pagination to use for the results.                   |
| `sort_by`          | `OrdersSortBy` (dict — see below)                                                      | No       | The sorting 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.         |

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

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

**Example**

```python theme={null}
result = client.orders(params={"order_ids": ..., "client_order_ids": ..., "market_ids": ..., "status": ..., "pagination": ..., "sort_by": ...}, selections=Selection(...))
```

***

## `settlements`

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

<sub>Also available as `my_settlements_history`. GraphQL field: `mySettlementsHistory`</sub>

History of all settlements

**Parameters**

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

`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 settlements for. |
| `settlement_type` | `"CLOSED_LONG"` \| `"CLOSED_SHORT"` \| `"EXPIRED_LONG"` \| `"EXPIRED_SHORT"` | No       | Restrict settlements to given type(s)           |
| `settled_on`      | `DateRangeFilter`                                                            | No       | —                                               |

**Example**

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

***

## `my_trades_for_order`

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

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

List of trades associated with provided order id

**Parameters**

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

**Example**

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

***

## `trades`

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

<sub>Also available as `my_trades_history`. GraphQL field: `myTradesHistory`</sub>

List of the user's trades

**Parameters**

| Name              | Type                                 | Required | Description                               |
| ----------------- | ------------------------------------ | -------- | ----------------------------------------- |
| `sort_by`         | `TradesSortBy` (dict — see below)    | No       | How to sort the results of the query.     |
| `filter`          | `MarketIdsFilter` (dict — see below) | No       | A filter for market ids to include.       |
| `settlement_type` | `"SETTLED"` \| `"UNSETTLED"`         | No       | A filter for trades.                      |
| `settled_on`      | `DateRangeFilter` (dict — see below) | No       | Date Range filter to find settled trades. |
| `pagination`      | `Pagination` (dict — see below)      | No       | The pagination to use for the results.    |

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

| Field       | Type                   | Required | Description                                              |
| ----------- | ---------------------- | -------- | -------------------------------------------------------- |
| `name`      | `"FILLED"` \| `"TIME"` | No       | The name of the attribute to sort on, default is `time`. |
| `direction` | `"ASC"` \| `"DESC"`    | No       | The direction to sort, either `asc` or `desc`            |

`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 trades for. |

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

| Field            | Type               | Required | Description |
| ---------------- | ------------------ | -------- | ----------- |
| `type`           | `"ROLLING_WINDOW"` | Yes      | —           |
| `rolling_window` | `RollingWindow`    | No       | —           |

`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.trades(params={"sort_by": ..., "filter": ..., "settlement_type": ..., "settled_on": ..., "pagination": ...}, 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.

### `DateRangeFilter`

Specifies a date range to constrain the result set to.  At least one must be provided

| Field            | Type               | Required | Description |
| ---------------- | ------------------ | -------- | ----------- |
| `type`           | `"ROLLING_WINDOW"` | Yes      | —           |
| `rolling_window` | `RollingWindow`    | No       | —           |

### `RollingWindow`

A rolling window date range filter.  A rolling window from now into the past.  For instance the last 24 hours

| Field       | Type                                                              | Required | Description |
| ----------- | ----------------------------------------------------------------- | -------- | ----------- |
| `increment` | `"SECONDS"` \| `"MINUTES"` \| `"HOURS"` \| `"DAYS"` \| `"MONTHS"` | Yes      | —           |
| `value`     | `int`                                                             | Yes      | —           |
