# Using the API

Markets, practice orders, errors, limits and live updates.

All addresses below start with `https://api.omnimarketx.com/api/public/v1`. Every request is signed as described in the [Quick start](/docs/quick-start).

## Markets and prices

| Request | Returns |
|---|---|
| `GET /markets` | Markets, with filters `status`, `category`, `q` (text), `sort`, `limit`, `offset` |
| `GET /markets/{id}` | One market: options, resolution rules, close time |
| `GET /markets/{id}/prices` | Real-money prices |
| `GET /practice/markets/{id}/prices` | Practice prices |
| `GET /markets/{id}/history` | Price history of one option (`optionKey`, `period`) |

Each market has two prices per option:

- **Real price** (`options[].currentPrice`): the real-money market, for reference.
- **Practice price** (`practicePrices`): what practice orders fill at.

They move separately, so always use the practice price when you trade.

## Your practice account

| Request | Returns |
|---|---|
| `GET /me` | Your username, Pro status and this key's permissions |
| `GET /practice/account` | Practice balance |
| `GET /practice/positions` | Open practice positions |
| `GET /practice/orders` | Your practice orders, newest first |

## Practice orders

Placing orders needs a key with **Practice trading** and an active OmniMarket Pro subscription.

### Preview first

`GET /practice/markets/{id}/quote?optionKey=YES&side=BUY&amountUsd=25` returns:

- `shares`: how many shares you get
- `avgPrice`: the average price you pay. Your price limit is checked against this number.
- `priceNow`: the practice price before your order
- `cost`, `fee`, `total`

Bigger orders move the price, so `avgPrice` rises with the amount.

### Place the order

```json
POST /practice/orders
{
  "clientOrderId": "my-bot-0001",
  "marketId": "<market id>",
  "optionKey": "YES",
  "side": "BUY",
  "amountUsd": 25,
  "maxPrice": 0.62
}
```

- **Price limit (required)**: `maxPrice` for a BUY, `minPrice` for a SELL (with `shares`). The order fills completely at or better than your limit, or is refused. It is never half-filled.
- **`clientOrderId` (required)**: your own id for this order. Sending the same request again returns the first result with `"replayed": true` and never creates a second order. Reusing the id for a different order is refused.

## Errors explained

Every error has a `success: false`, an `error` code and a plain `message`.

| Code | What it means | What to do |
|---|---|---|
| `credential_required` | No key or token was sent | Add the three signing headers |
| `invalid_credential` | The key is unknown, revoked or expired | Create a new key |
| `invalid_signature` | The signature doesn't match | Check the four signed lines and the path with query |
| `stale_request` | The timestamp is too old or was already used | Use the current time; send each request once |
| `wrong_environment` | A test key on production, or the reverse | Use a key from this site |
| `ip_not_allowed` | The request came from an IP the key doesn't allow | Update the key's IP allow list |
| `scope_required` | The key or connection can only read | Use a key with Practice trading (Pro) |
| `pro_subscription_required` | Trading needs OmniMarket Pro | Get Pro, or trade on the website |
| `price_limit_required` | No `maxPrice` / `minPrice` | Add a price limit |
| `price_limit_exceeded` | The price moved past your limit | Get a new quote and try again |
| `client_order_id_conflict` | This `clientOrderId` was used for another order | Use a new id |
| `insufficient_balance` | Not enough practice balance | Use a smaller amount |
| `insufficient_shares` | You don't hold that many shares | Sell fewer shares |
| `market_not_tradable` / `market_closing` | The market is closed or closes very soon | Choose another market |
| `market_api_paused` | Trading through the API is paused on this market | Try later, or use the website |
| `api_trading_disabled` | Trading through the API is switched off for now | Try later; reading still works |
| `key_exposure_cap` / `market_exposure_cap` | The order would pass a safety cap | Use a smaller amount |
| `rate_limited` | Too many requests | Wait for the seconds in `Retry-After` |
| `temporarily_unavailable` | We couldn't safely check the request | Retry shortly; nothing was placed |

## Rate limits

- Per key or connected assistant: **120 reads** and **30 orders** per minute. Each response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`.
- Up to **5 keys** per account. Keys can have an IP allow list and an expiry date.
- Trading through the API stops a few minutes before a market closes.

## Live updates

Open a WebSocket to `https://api.omnimarketx.com/api/public/v1/stream` with your signing headers, then subscribe to topics:

| Topic | Sends |
|---|---|
| `market:<id>:prices` | Real-price changes |
| `market:<id>:practice-prices` | Practice-price changes |
| `me:orders` | Your practice orders as they fill |

Up to 3 streams per key. Revoking the key closes its streams.