> 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:**

curl -X POST <https://auth.quant.fun/oauth2/token> \\\
&#x20; -H "Content-Type: application/x-www-form-urlencoded" \\\
&#x20; -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, close anything else):**

curl -X POST <https://api.quant.fun/vaults/my-vault/trades> \\\
&#x20; -H "Authorization: Bearer \<ACCESS\_TOKEN>" \\\
&#x20; -H "Content-Type: application/json" \\\
&#x20; -d '\[\
&#x20;   { "type": "perp", "marketIndex": 0, "direction": "long",  "portfolioAllocation": 0.5, "leverage": 4 },\
&#x20;   { "type": "perp", "marketIndex": 1, "direction": "short", "portfolioAllocation": 0.5, "leverage": 4 },\
&#x20;   { "type": "closeAll" }\
&#x20; ]'

Returns immediately with a transaction ID:

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

**Step 3 — Poll for completion:**

curl <https://api.quant.fun/vaults/my-vault/transactions/550e8400-e29b-41d4-a716-446655440000> \\\
&#x20; -H "Authorization: Bearer \<ACCESS\_TOKEN>"

{\
&#x20; "result": {\
&#x20;   "requestStatus": "COMPLETED",\
&#x20;   "portfolioCompositionResponse": \[\
&#x20;     { "success": true, "orderIds": \[123456], "adjustmentTradeDirection": "long",  "allocation": { "marketIndex": 0 } },\
&#x20;     { "success": true, "orderIds": \[123457], "adjustmentTradeDirection": "short", "allocation": { "marketIndex": 1 } }\
&#x20;   ]\
&#x20; }\
}

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