---
name: trading
description: Execute trading operations on Tetrac across every supported exchange. Place orders, manage positions, set leverage, and control risk. Use when you need to execute trades, modify positions, or manage exchange accounts.
license: Proprietary
compatibility: Designed for Claude Code (or similar products)
metadata:
  author: tetrac
  version: "2.2"
  category: "trading"
  emoji: "📈"
---

## Skill Files

| File                     | URL                                              |
| ------------------------ | ------------------------------------------------ |
| **SKILL.md** (this file) | `https://www.tetrac.xyz/skills/trading/SKILL.md` |

## Overview

This skill provides trading operations:

1. **Orders** - Place, cancel, and manage orders
2. **Positions** - View and close positions
3. **Account** - Set leverage, hedge mode, get balance
4. **Risk** - Stop losses, take profits

---

## Prerequisites

### 1. Authentication — Session or Pay Per Call

Every call needs one of:

- **A registered session** — log in with the challenge + signature flow in the [onboarding skill](https://www.tetrac.xyz/skills/onboarding/SKILL.md) (the passkey never leaves your machine), then send both headers below on every request.
- **A per-call payment** — no account; see [x402 agent payments](https://www.tetrac.xyz/skills/x402-agent-payments/SKILL.md) or [MPP payments](https://www.tetrac.xyz/skills/mpp-payments/skill.md).

| Header           | Description                                                                |
| ---------------- | -------------------------------------------------------------------------- |
| `ttc-auth-token` | The `authToken` returned by `/api/auth/login` (valid for 24 hours)         |
| `ttc-public-key` | The `publicKey` returned by `/api/auth/login` — the session is bound to it |

### 2. Exchange Credentials

Each request also includes your exchange-specific credentials in the body:

```json
{
  "credentials": {
    "apiKey": "YOUR_EXCHANGE_API_KEY",
    "apiSecret": "YOUR_EXCHANGE_API_SECRET",
    "passphrase": "YOUR_API_PASSPHRASE"
  }
}
```

| Field           | Required                   | Description                                                                                    |
| --------------- | -------------------------- | ---------------------------------------------------------------------------------------------- |
| `apiKey`        | Yes                        | Your exchange API key                                                                          |
| `apiSecret`     | Yes                        | Your exchange API secret                                                                       |
| `passphrase`    | For some exchanges         | API passphrase. Required by some venues; omitting it returns a field-specific error naming it. |
| `walletAddress` | Orderly (email users only) | Your main Solana wallet address for Orderly account ID derivation (see below)                  |

> **Note:** `getTickers`, `getBestBidAsk`, `getKlines` and `getContractSpecs` are public market-data methods and need no exchange credentials. `getAccounts` needs `apiKey` only. Credentials are never stored — send them with every request.

### Orderly Network — Agentic / CLI Users

Orderly derives your account ID from your **main wallet address** + broker ID. The server uses `credentials.walletAddress` when you send it and falls back to your `ttc-public-key` otherwise. If your Orderly account was created with a different wallet than your `ttc-public-key`, pass that wallet as `walletAddress` so the server derives the correct account ID:

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "orderly",
    "method": "getPositions",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_ORDERLY_ED25519_PUBLIC_KEY",
      "apiSecret": "YOUR_ORDERLY_ED25519_PRIVATE_KEY",
      "passphrase": "ttc",
      "walletAddress": "YOUR_SOLANA_MAIN_WALLET_ADDRESS"
    }
  }'
```

Omit `walletAddress` when your Orderly main wallet is the same key as your `ttc-public-key`.

---

## Place Orders

### Limit Order

Place a buy limit order at a specific price:

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "phemex",
    "method": "placeLimitOrder",
    "params": {
      "symbol": "BTCUSDT",
      "side": "buy",
      "quantity": 0.001,
      "price": 95000,
      "positionSide": "long",
      "timeInForce": "GoodTillCancel"
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET",
      "passphrase": "YOUR_API_PASSPHRASE"
    }
  }'
```

> Omit `passphrase` if the exchange does not require one.

### Market Order

Execute immediately at current price:

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "bybit",
    "method": "placeMarketOrder",
    "params": {
      "symbol": "ETHUSDT",
      "side": "sell",
      "quantity": 0.1,
      "positionSide": "short"
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Stop Loss Order

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "placeStopOrder",
    "params": {
      "symbol": "BTCUSDT",
      "side": "sell",
      "quantity": 0.001,
      "stopPrice": 90000,
      "positionSide": "long",
      "triggerType": "ByMarkPrice"
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Order Response

```json
{
  "success": true,
  "data": {
    "id": "1234567890",
    "symbol": "BTCUSDT",
    "side": "buy",
    "type": "limit",
    "price": 95000,
    "quantity": 0.001,
    "status": "new",
    "filled": 0,
    "remaining": 0.001,
    "timestamp": 1738435234567
  },
  "exchange": "phemex"
}
```

`status` is one of `new`, `partially_filled`, `filled`, `canceled`, `rejected`, `expired`. Use `data.id` with `cancelOrder`. Responses also carry the venue's own `code` and `msg` fields, whose values differ by exchange — branch on the HTTP status and `success`, not on `code`. Errors return a non-200 status with `{ "error", "code", "details" }`.

---

## Manage Positions

### Get Positions

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "phemex",
    "method": "getPositions",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Positions Response

```json
{
  "success": true,
  "data": [
    {
      "exchange": "phemex",
      "symbol": "BTCUSDT",
      "side": "buy",
      "positionSide": "long",
      "direction": "long",
      "status": "open",
      "size": 0.001,
      "volume": 97.5,
      "entryPrice": 95000,
      "markPrice": 97500,
      "pnl": 2.5,
      "leverage": 10,
      "liquidationPrice": 86500,
      "marginType": "cross",
      "openTime": 1738400000000,
      "updateTime": 1738435234567,
      "timestamp": 1738435234567
    }
  ],
  "exchange": "phemex"
}
```

`volume` is the position's USD value. Each position also carries identification fields (`systemID`, `userIdentifier`, `exchangeUser`, `portfolioExposure`) and, where the venue reports them, `takeProfitPrice`, `stopLossPrice`, `roe` and `marginRatio`.

> **Privacy:** pay-per-call (x402 / MPP) `getPositions` requests are never recorded. For a signed-in account, positions returned by `getPositions` are shared with the DAO positions feed under a pseudonymous trader id, on by default. Turn it off in the Tetrac web app → Settings → DAO Participation: that stops new rows, while rows already shared stay until you delete your account.

### Close All Positions

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "phemex",
    "method": "closeAllPositions",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

---

## Account Management

### Set Leverage

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "setLeverage",
    "params": {
      "symbol": "BTCUSDT",
      "leverage": 10
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Set Hedge Mode

Enable long and short positions simultaneously:

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "bybit",
    "method": "setHedgeMode",
    "params": {
      "symbol": "BTCUSDT",
      "isHedged": true
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Get Balance

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "getBalance",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Balance Response

```json
{
  "success": true,
  "data": [
    {
      "asset": "USDT",
      "balance": "1000.00",
      "available": "950.00",
      "locked": "50.00"
    },
    {
      "asset": "BTC",
      "balance": "0.05",
      "available": "0.05",
      "locked": "0"
    }
  ],
  "code": 200,
  "exchange": "binance"
}
```

---

## Order Management

### Get Open Orders

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "getOrders",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Cancel All Orders

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "cancelAllOrders",
    "params": {
      "symbol": "BTCUSDT"
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Cancel Specific Order

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "bybit",
    "method": "cancelOrder",
    "params": {
      "symbol": "BTCUSDT",
      "orderID": "1234567890"
    },
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

---

## Order Parameters Reference

| Parameter         | Type    | Required  | Description                                                     |
| ----------------- | ------- | --------- | --------------------------------------------------------------- |
| `symbol`          | string  | Yes       | Trading pair (e.g., `BTCUSDT`)                                  |
| `side`            | string  | Yes       | `buy` or `sell`                                                 |
| `quantity`        | number  | Yes       | Order quantity                                                  |
| `price`           | number  | For limit | Limit price                                                     |
| `stopPrice`       | number  | For stop  | Stop trigger price                                              |
| `positionSide`    | string  | No        | `long`, `short`, or `merged` (hedge mode)                       |
| `orderType`       | string  | No        | `market`, `limit`, `stop`, `stoplimit`                          |
| `timeInForce`     | string  | No        | `GoodTillCancel`, `ImmediateOrCancel`, `FillOrKill`, `PostOnly` |
| `reduceOnly`      | boolean | No        | Only reduce existing position                                   |
| `closePosition`   | boolean | No        | Close entire position                                           |
| `triggerType`     | string  | No        | `ByLastPrice`, `ByMarkPrice`, `ByIndexPrice`                    |
| `takeProfitPrice` | number  | No        | Take profit price                                               |
| `stopLossPrice`   | number  | No        | Stop loss price                                                 |

---

## Available Methods

| Method                | Credentials  | Description                                                                        |
| --------------------- | ------------ | ---------------------------------------------------------------------------------- |
| `setHedgeMode`        | Key + secret | Set hedge mode for the exchange account                                            |
| `setLeverage`         | Key + secret | Set leverage for a specific trading pair                                           |
| `getInfoLeverage`     | Key + secret | Leverage tier brackets for a trading pair (notional ranges and their max leverage) |
| `getPositions`        | Key + secret | Retrieve current open positions                                                    |
| `getBalance`          | Key + secret | Get account balance information                                                    |
| `placeLimitOrder`     | Key + secret | Execute a limit order                                                              |
| `placeMarketOrder`    | Key + secret | Execute a market order                                                             |
| `placeStopOrder`      | Key + secret | Place a stop order                                                                 |
| `closeAllPositions`   | Key + secret | Close all open positions                                                           |
| `createWithdrawal`    | Key + secret | Initiate a withdrawal from the exchange                                            |
| `getDepositAddress`   | Key + secret | Get deposit address for a specific asset                                           |
| `getOrders`           | Key + secret | Retrieve open or historical orders                                                 |
| `cancelAllOrders`     | Key + secret | Cancel all open orders                                                             |
| `cancelOrder`         | Key + secret | Cancel a specific order by ID                                                      |
| `getUserTradeHistory` | Key + secret | Retrieve user's historical trade records                                           |
| `getAccounts`         | Key only     | List your Propr challenge-attempt accounts (Propr only)                            |
| `getTickers`          | None         | Get current ticker information                                                     |
| `getBestBidAsk`       | None         | Get best bid and ask prices                                                        |
| `getKlines`           | None         | Get historical candlestick/kline data for a trading pair                           |
| `getContractSpecs`    | None         | Per-market contract size, size increment, and order minimums (canonical symbols)   |

Not every venue implements every method — an unsupported method returns a `400`. The live catalog (with descriptions and prices) is the `methods` object returned by `GET /api/v1/exchanges`.

---

## Supported Exchanges

The supported-venue roster changes as venues are added, suspended, or delisted, so it is not reproduced here. See the live list on the home page (https://www.tetrac.xyz), or read the `supportedExchanges` array returned by `GET /api/v1/exchanges`. The roster is also included in the unpaid `402` response body, so you can read it before paying.

---

## Rate Limits

Limits are per identity (your `ttc-public-key`, or the paying wallet for x402) and scale with your subscription tier. x402 pay-per-call requests use the Free limit.

| Endpoint                                | Free   | Pro    | Elite   |
| --------------------------------------- | ------ | ------ | ------- |
| `/api/v1/exchanges` (all trading calls) | 20/min | 60/min | 200/min |

A `429` response includes a `Retry-After` header — wait that many seconds before retrying.

---

## Best Practices

1. **Test with small amounts first** - Verify your integration works
2. **Use reduceOnly for exits** - Prevents accidental position opens
3. **Set stop losses** - Always manage risk
4. **Monitor rate limits** - Avoid being blocked
5. **Secure credentials** - Never share API keys

---

## Next Steps

- Explore [market data](https://www.tetrac.xyz/skills/market-data/SKILL.md)
- Explore [x402 agent payments](https://www.tetrac.xyz/skills/x402-agent-payments/SKILL.md)

---

**API contract (machine-readable):** https://www.tetrac.xyz/openapi.json · **For humans:** https://www.tetrac.xyz/docs
