> For the complete documentation index, see [llms.txt](https://quant-fun.gitbook.io/quant.fun-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quant-fun.gitbook.io/quant.fun-docs/for-funds-quant.fun-trades-api/api-example-flow.md).

# API Example Flow

**Step 1 — Get an access token:**

```bash
curl -X POST https://auth.quant.fun/oauth2/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>"
```

**Step 2 — Submit a trade (go 50% long ETH and 50% short BTC):**

```bash
curl -X POST https://api.quant.fun/trades/my-vault \
  -H "Authorization: Bearer <ACCESS_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '[
    { "type": "perp", "coin": "ETH", "direction": "long",  "portfolioAllocation": 0.5, "leverage": 4 },
    { "type": "perp", "coin": "BTC", "direction": "short", "portfolioAllocation": 0.5, "leverage": 4 }
  ]'
```

To go flat on a market, submit it with `"portfolioAllocation": 0`.

Returns immediately with a transaction ID:

```json
{ "result": { "transactionId": "550e8400-e29b-41d4-a716-446655440000" } }
```

**Step 3 — Poll for completion:**

```bash
curl https://api.quant.fun/trades/my-vault/transactions/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer <ACCESS_TOKEN>"
```

```json
{
  "result": {
    "requestStatus": "COMPLETED",
    "portfolioCompositionResponse": [
      { "success": true,  "allocation": { "type": "perp", "coin": "ETH", "direction": "long",  "portfolioAllocation": 0.5, "leverage": 4 } },
      { "success": true, "allocation": { "type": "perp", "coin": "BTC", "direction": "short", "portfolioAllocation": 0.5, "leverage": 4 } }
    ]
  }
}
```

Poll every 2–3 seconds until `requestStatus` is `COMPLETED` or `FAILED`. Typical execution completes within 30–60 seconds depending on maker fill rates.
