Execute trade
const url = 'https://api.openfx.com/v2/brokerage/{orgId}/trade';
const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({quoteId: 'd8bc9618-2830-1822-9ae2-414aaf2b2de3'})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://api.openfx.com/v2/brokerage/{orgId}/trade"
payload = { "quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3" }
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://api.openfx.com/v2/brokerage/{orgId}/trade")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}")
.asString();CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.openfx.com/v2/brokerage/{orgId}/trade");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Idempotency-Key: <idempotency-key>");
headers = curl_slist_append(headers, "Authorization: Bearer <token>");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}");
CURLcode ret = curl_easy_perform(hnd);package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.openfx.com/v2/brokerage/{orgId}/trade"
payload := strings.NewReader("{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}curl --request POST \
--url https://api.openfx.com/v2/brokerage/{orgId}/trade \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3"
}
'{
"status": "success",
"data": {
"balances": {
"USD": -596064.969940321,
"USDC": -9893214.59296976,
"USDT": 8654884.42360652
},
"trade": {
"id": "2c011d8b-1822-4d1c-9b16-414aaf2b2de4",
"buy": "USD",
"sell": "USDC",
"referencedUnit": "USD",
"referencedAmount": 100,
"amount": 101,
"status": "EXECUTED",
"transactedAt": "2025-02-10T07:40:21.300Z",
"quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3"
},
"userCreditLimit": 10000000,
"userCreditUsed": 8844000.51844473
}
}{
"status": "error",
"message": "Query validation failed"
}{
"status": "error",
"message": "The authorization key provided is either invalid or expired, please try again"
}{
"status": "error",
"message": "Request with this idempotency key is currently processing",
"error": {
"code": "IDEMPOTENCY_IN_FLIGHT",
"details": "Please wait for the original request to complete"
}
}{
"status": "error",
"message": "Idempotency key reused with different parameters",
"error": {
"code": "IDEMPOTENCY_MISMATCH",
"details": "This idempotency key was already used with different request parameters"
}
}{
"status": "error",
"message": "An internal error has occurred"
}Execute trade
Executes a currency exchange against a valid quote ID. Must be called within the quote validity window.
POST
/
v2
/
brokerage
/
{orgId}
/
trade
Execute trade
const url = 'https://api.openfx.com/v2/brokerage/{orgId}/trade';
const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({quoteId: 'd8bc9618-2830-1822-9ae2-414aaf2b2de3'})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://api.openfx.com/v2/brokerage/{orgId}/trade"
payload = { "quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3" }
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://api.openfx.com/v2/brokerage/{orgId}/trade")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}")
.asString();CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.openfx.com/v2/brokerage/{orgId}/trade");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Idempotency-Key: <idempotency-key>");
headers = curl_slist_append(headers, "Authorization: Bearer <token>");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}");
CURLcode ret = curl_easy_perform(hnd);package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.openfx.com/v2/brokerage/{orgId}/trade"
payload := strings.NewReader("{\n \"quoteId\": \"d8bc9618-2830-1822-9ae2-414aaf2b2de3\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}curl --request POST \
--url https://api.openfx.com/v2/brokerage/{orgId}/trade \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3"
}
'{
"status": "success",
"data": {
"balances": {
"USD": -596064.969940321,
"USDC": -9893214.59296976,
"USDT": 8654884.42360652
},
"trade": {
"id": "2c011d8b-1822-4d1c-9b16-414aaf2b2de4",
"buy": "USD",
"sell": "USDC",
"referencedUnit": "USD",
"referencedAmount": 100,
"amount": 101,
"status": "EXECUTED",
"transactedAt": "2025-02-10T07:40:21.300Z",
"quoteId": "d8bc9618-2830-1822-9ae2-414aaf2b2de3"
},
"userCreditLimit": 10000000,
"userCreditUsed": 8844000.51844473
}
}{
"status": "error",
"message": "Query validation failed"
}{
"status": "error",
"message": "The authorization key provided is either invalid or expired, please try again"
}{
"status": "error",
"message": "Request with this idempotency key is currently processing",
"error": {
"code": "IDEMPOTENCY_IN_FLIGHT",
"details": "Please wait for the original request to complete"
}
}{
"status": "error",
"message": "Idempotency key reused with different parameters",
"error": {
"code": "IDEMPOTENCY_MISMATCH",
"details": "This idempotency key was already used with different request parameters"
}
}{
"status": "error",
"message": "An internal error has occurred"
}Executes a currency exchange trade using a valid quote ID. The trade must be submitted within the quote’s validity window (3 seconds by default, up to 60 seconds when
See the full v2 error reference for retry semantics and idempotency-specific codes.
quoteForSeconds was specified at quote generation).
Use this endpoint to:
- Execute currency exchanges
- Lock in quoted rates
- Convert between currencies
- Initiate settlement process
Idempotency required. This POST requires an
Idempotency-Key header. Keys are cached for 24 hours. Reusing the same key with the same body returns the cached response; reusing it with different parameters returns a 422 error.Errors
| Status | Message | Notes |
|---|---|---|
| 400 | Query validation failed | Request didn’t match schema (often a missing or expired quoteId) |
| 401 | The authorization key provided is either invalid or expired, please try again | Mint a fresh JWT — see Authentication |
| 409 | Request with this idempotency key is currently processing | See Errors → Idempotency |
| 422 | Idempotency key reused with different parameters | New body → new key |
| 500 | An internal error has occurred | Trade may or may not have executed — GET the trade by ID before retrying |
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Unique key to ensure idempotent requests. UUID v4 recommended. Valid for 24 hours.
Example:
"123e4567-e89b-12d3-a456-426614174000"
Path Parameters
Body
application/json
Example:
"d8bc9618-2830-1822-9ae2-414aaf2b2de3"
⌘I