> For the complete documentation index, see [llms.txt](https://sodex.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sodex.com/documentation/for-developers/api-reference/trading-api.md).

# Trading API

Use REST for request/response operations and WebSocket Streams for realtime market and account events.

## Choose an interface

{% content-ref url="/pages/JhkOXmaIr0osLMjp2DfF" %}
[REST API](/documentation/for-developers/api-reference/trading-api/rest-v1.md)
{% endcontent-ref %}

{% content-ref url="/pages/U25Aeh8OoqsoN02ofoj4" %}
[WebSocket Streams](/documentation/for-developers/api-reference/trading-api/websocket-v1.md)
{% endcontent-ref %}

{% content-ref url="/pages/8O69liORmMccphq48PVL" %}
[Schema](/documentation/for-developers/api-reference/trading-api/rest-v1/schema.md)
{% endcontent-ref %}

## Documentation

{% content-ref url="/pages/AWT2USWBEq58NRgR0pxR" %}
[Quickstart](/documentation/for-developers/developers/trading/quickstart.md)
{% endcontent-ref %}

{% content-ref url="/pages/EHI3mUMvf6Ci6NYJZwU1" %}
[API Keys and Nonces](/documentation/for-developers/developers/trading/api-keys-and-nonces.md)
{% endcontent-ref %}

{% content-ref url="/pages/o3Yj9kHutFbmg6uDLnhS" %}
[Authentication & Signing](/documentation/for-developers/developers/trading/authentication-and-signing.md)
{% endcontent-ref %}

{% content-ref url="/pages/HWeWqIzQUTNao2smQ2pp" %}
[Rate Limits](/documentation/for-developers/developers/trading/api-rate-limits.md)
{% endcontent-ref %}

## Endpoint

* Mainnet REST Endpoint
  * Spot: `https://mainnet-gw.sodex.dev/api/v1/spot`
  * Perps: `https://mainnet-gw.sodex.dev/api/v1/perps`
* Mainnet WebSocket Endpoint
  * Spot: `wss://mainnet-gw.sodex.dev/ws/spot`
  * Perps: `wss://mainnet-gw.sodex.dev/ws/perps`
* Testnet REST Endpoint
  * Spot: `https://testnet-gw.sodex.dev/api/v1/spot`
  * Perps: `https://testnet-gw.sodex.dev/api/v1/perps`
* Testnet WebSocket Endpoint
  * Spot: `wss://testnet-gw.sodex.dev/ws/spot`
  * Perps: `wss://testnet-gw.sodex.dev/ws/perps`

## Get account ID

Account IDs are required to query account data and to sign trading actions. Retrieve them via either of:

### Via REST API

```bash
curl -X GET "${PERPS_ENDPOINT}/accounts/{userAddress}/state" \
  -H 'Accept: application/json'
```

The `aid` field in the response is the account ID. By default this is the primary account; pass `?accountID=<id>` to query a specific sub-account. The same endpoint is available under `${SPOT_ENDPOINT}` for spot.

See [WsPerpsState](/documentation/for-developers/api-reference/trading-api/rest-v1/schema.md#wsperpsstate) for the full response shape.

## Implementation example

{% content-ref url="/pages/jkJqX14fY6MLgpgQvq3B" %}
[Go SDK Signing Guide](/documentation/for-developers/sdks/go-sdk-signing-guide.md)
{% endcontent-ref %}
