---
title: "Trade over REST"
url: https://docs.truemarkets.co/institutional/trade-over-rest
description: "Authenticate CeFi REST requests with a JWT minted from your API key, then place orders and read balances on the exchange."
---

Docs index: https://docs.truemarkets.co/llms.txt

# Trade over REST

Exchange REST covers the same trading actions as FIX, over HTTPS. It's reachable over the internet, so you don't need the private network connection that FIX uses.

## Authenticate a request

Mint a JWT from your API key, then send it with every request. To mint one, sign the string `{key_id}.{timestamp}` with your private key and post it to [`POST https://api.truemarkets.co/v1/auth/api-key/token`](https://docs.truemarkets.co/api/auth/exchange-api-key-token). The timestamp is Unix seconds within 30 seconds of our clock. The signature is ES256, the raw 64-byte `r || s`, base64url-encoded without padding.

The response has an access token, which lasts an hour, and a refresh token. Before the access token expires, post the refresh token to [`POST /v1/auth/token/refresh`](https://docs.truemarkets.co/api/auth/refresh-token) for a new pair. [Create your API key](https://docs.truemarkets.co/trading-api/api-key#3-refresh-the-token) shows the refresh call.

Send these headers on every CeFi request:

| Header                   | Value                            |
| ------------------------ | -------------------------------- |
| `Authorization`          | `Bearer` and your access token   |
| `x-truex-auth-timestamp` | the current Unix time in seconds |
| `X-Truex-Version`        | `v2026_01_23`                    |

The JWT carries your client id, so you never send one. The timestamp guards against replayed requests: the exchange rejects one that is more than 15 seconds old or more than 1 second in the future, so keep your clock in sync.

`X-Truex-Version` picks the response format. `v2026_01_23` is the default and the only supported version, so the header is optional, but pinning it keeps a future default change from reshaping your responses. Any other value, including the withdrawn `v2024_01_01`, is rejected with `400 Bad Request`. List responses come wrapped in `data` and `pagination`.

Send every CeFi request to `https://api.truex.co`.

```typescript
import { createPrivateKey, sign } from "node:crypto";
import { readFileSync } from "node:fs";

const { key_id, private_key } = JSON.parse(
  readFileSync(process.env.TM_KEY_FILE!, "utf8"),
);
const timestamp = Math.floor(Date.now() / 1000);
const signature = sign(
  "sha256",
  Buffer.from(`${key_id}.${timestamp}`),
  {
    key: createPrivateKey({ key: private_key, format: "jwk" }),
    dsaEncoding: "ieee-p1363",
  },
).toString("base64url");

const res = await fetch(
  "https://api.truemarkets.co/v1/auth/api-key/token",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ key_id, timestamp, signature }),
  },
);
console.log((await res.json()).access_token);
```

```bash
TOKEN="$(npx tsx token.ts)"

curl -s "https://api.truex.co/v1/cefi/balances" \
  -H "Authorization: Bearer $TOKEN" \
  -H "x-truex-auth-timestamp: $(date +%s)" \
  -H "X-Truex-Version: v2026_01_23"
```

## Change an order instead of replacing it

To move a resting order's price or size, modify it with [`PATCH /v1/cefi/orders`](https://docs.truemarkets.co/api/institutional/modify-orders-cefi) rather than canceling it and placing a new one. A modify is one request instead of two, so it uses less of your [rate limit](https://docs.truemarkets.co/developer-resources/rate-limits). It also avoids a race: a new order sent right after a cancel can reach the exchange before the cancel has released your balance, and get rejected. That happens most when you're trading close to 100% of your balance. Over FIX, the same change is an [`OrderCancelReplaceRequest` (35=G)](https://docs.truemarkets.co/api/fix/order-entry#ordercancelreplacerequest-35g).

## Endpoints

**Orders**

- [Create order](https://docs.truemarkets.co/api/institutional/add-orders-cefi)
- [Modify order](https://docs.truemarkets.co/api/institutional/modify-orders-cefi)
- [Cancel order](https://docs.truemarkets.co/api/institutional/cancel-orders-cefi)
- [Cancel all orders](https://docs.truemarkets.co/api/institutional/cancel-all-orders-cefi)
- [Active orders](https://docs.truemarkets.co/api/institutional/get-orders-active-cefi)
- [Order status](https://docs.truemarkets.co/api/institutional/get-orders-status-cefi)

**Balances**

- [Get balances](https://docs.truemarkets.co/api/institutional/get-balances-cefi)
- [Balance activity](https://docs.truemarkets.co/api/institutional/get-balance-activity-cefi)

Next: [Exchange REST reference](https://docs.truemarkets.co/api/institutional/exchange-rest)