Skip to main content
POST
/
v1
/
exchange
/
stablefx
/
trades
Create a trade
curl --request POST \
  --url https://api.circle.com/v1/exchange/stablefx/trades \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "idempotencyKey": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
  "quoteId": "c4d1da72-111e-4d52-bdbf-2e74a2d803d5",
  "address": "0x1234567890abcdef1234567890abcdef12345678",
  "message": {
    "permitted": {
      "token": "0xTOKEN",
      "amount": "1000"
    },
    "spender": "0xa8f94168b4981840ba27d423f4ad6332bedee006",
    "nonce": "309585810",
    "deadline": "1770302983",
    "witness": {
      "consideration": {
        "quoteId": "<string>",
        "base": "<string>",
        "quote": "<string>",
        "baseAmount": "<string>",
        "quoteAmount": "<string>",
        "maturity": "1716153600"
      },
      "recipient": "0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6",
      "fee": "80000"
    }
  },
  "signature": "<string>"
}
'
import requests

url = "https://api.circle.com/v1/exchange/stablefx/trades"

payload = {
"idempotencyKey": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
"quoteId": "c4d1da72-111e-4d52-bdbf-2e74a2d803d5",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"message": {
"permitted": {
"token": "0xTOKEN",
"amount": "1000"
},
"spender": "0xa8f94168b4981840ba27d423f4ad6332bedee006",
"nonce": "309585810",
"deadline": "1770302983",
"witness": {
"consideration": {
"quoteId": "<string>",
"base": "<string>",
"quote": "<string>",
"baseAmount": "<string>",
"quoteAmount": "<string>",
"maturity": "1716153600"
},
"recipient": "0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6",
"fee": "80000"
}
},
"signature": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
idempotencyKey: 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
quoteId: 'c4d1da72-111e-4d52-bdbf-2e74a2d803d5',
address: '0x1234567890abcdef1234567890abcdef12345678',
message: {
permitted: {token: '0xTOKEN', amount: '1000'},
spender: '0xa8f94168b4981840ba27d423f4ad6332bedee006',
nonce: '309585810',
deadline: '1770302983',
witness: {
consideration: {
quoteId: '<string>',
base: '<string>',
quote: '<string>',
baseAmount: '<string>',
quoteAmount: '<string>',
maturity: '1716153600'
},
recipient: '0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6',
fee: '80000'
}
},
signature: '<string>'
})
};

fetch('https://api.circle.com/v1/exchange/stablefx/trades', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.circle.com/v1/exchange/stablefx/trades",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'idempotencyKey' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'quoteId' => 'c4d1da72-111e-4d52-bdbf-2e74a2d803d5',
'address' => '0x1234567890abcdef1234567890abcdef12345678',
'message' => [
'permitted' => [
'token' => '0xTOKEN',
'amount' => '1000'
],
'spender' => '0xa8f94168b4981840ba27d423f4ad6332bedee006',
'nonce' => '309585810',
'deadline' => '1770302983',
'witness' => [
'consideration' => [
'quoteId' => '<string>',
'base' => '<string>',
'quote' => '<string>',
'baseAmount' => '<string>',
'quoteAmount' => '<string>',
'maturity' => '1716153600'
],
'recipient' => '0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6',
'fee' => '80000'
]
],
'signature' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.circle.com/v1/exchange/stablefx/trades"

payload := strings.NewReader("{\n \"idempotencyKey\": \"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11\",\n \"quoteId\": \"c4d1da72-111e-4d52-bdbf-2e74a2d803d5\",\n \"address\": \"0x1234567890abcdef1234567890abcdef12345678\",\n \"message\": {\n \"permitted\": {\n \"token\": \"0xTOKEN\",\n \"amount\": \"1000\"\n },\n \"spender\": \"0xa8f94168b4981840ba27d423f4ad6332bedee006\",\n \"nonce\": \"309585810\",\n \"deadline\": \"1770302983\",\n \"witness\": {\n \"consideration\": {\n \"quoteId\": \"<string>\",\n \"base\": \"<string>\",\n \"quote\": \"<string>\",\n \"baseAmount\": \"<string>\",\n \"quoteAmount\": \"<string>\",\n \"maturity\": \"1716153600\"\n },\n \"recipient\": \"0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6\",\n \"fee\": \"80000\"\n }\n },\n \"signature\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

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))

}
HttpResponse<String> response = Unirest.post("https://api.circle.com/v1/exchange/stablefx/trades")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"idempotencyKey\": \"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11\",\n \"quoteId\": \"c4d1da72-111e-4d52-bdbf-2e74a2d803d5\",\n \"address\": \"0x1234567890abcdef1234567890abcdef12345678\",\n \"message\": {\n \"permitted\": {\n \"token\": \"0xTOKEN\",\n \"amount\": \"1000\"\n },\n \"spender\": \"0xa8f94168b4981840ba27d423f4ad6332bedee006\",\n \"nonce\": \"309585810\",\n \"deadline\": \"1770302983\",\n \"witness\": {\n \"consideration\": {\n \"quoteId\": \"<string>\",\n \"base\": \"<string>\",\n \"quote\": \"<string>\",\n \"baseAmount\": \"<string>\",\n \"quoteAmount\": \"<string>\",\n \"maturity\": \"1716153600\"\n },\n \"recipient\": \"0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6\",\n \"fee\": \"80000\"\n }\n },\n \"signature\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.circle.com/v1/exchange/stablefx/trades")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"idempotencyKey\": \"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11\",\n \"quoteId\": \"c4d1da72-111e-4d52-bdbf-2e74a2d803d5\",\n \"address\": \"0x1234567890abcdef1234567890abcdef12345678\",\n \"message\": {\n \"permitted\": {\n \"token\": \"0xTOKEN\",\n \"amount\": \"1000\"\n },\n \"spender\": \"0xa8f94168b4981840ba27d423f4ad6332bedee006\",\n \"nonce\": \"309585810\",\n \"deadline\": \"1770302983\",\n \"witness\": {\n \"consideration\": {\n \"quoteId\": \"<string>\",\n \"base\": \"<string>\",\n \"quote\": \"<string>\",\n \"baseAmount\": \"<string>\",\n \"quoteAmount\": \"<string>\",\n \"maturity\": \"1716153600\"\n },\n \"recipient\": \"0x1f531ce3c418bbd830d06138a9e5b5eacfdfb3d6\",\n \"fee\": \"80000\"\n }\n },\n \"signature\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "c4d1da72-111e-4d52-bdbf-2e74a2d803d5",
  "contractTradeId": "24",
  "rate": 0.915,
  "from": {
    "amount": "100.00"
  },
  "to": {
    "amount": "100.00"
  },
  "fee": "100.00",
  "createDate": "2023-01-01T12:04:05Z",
  "updateDate": "2023-01-01T12:04:05Z",
  "quoteId": "c4d1da72-111e-4d52-bdbf-2e74a2d803d5",
  "settlementTransactionHash": "0xf97c6a87511583d5c7e8e72f8e1fe38bfd24350edda78fddbe67125f3cf0a122",
  "maturity": "2023-01-01T12:04:05Z",
  "completeDate": "2023-01-01T12:04:05Z"
}

Authorizations

Authorization
string
header
required

Circle's API Keys are formatted in the following structure "PREFIX:ID:SECRET". All three parts are requred to make a successful request.

Body

application/json

Request body for creating a trade. Accepts a quote and submits a signed taker Permit2 message to create the trade. The taker signs the typedData payload returned by the presign endpoint and includes the signed message, signature, and signer address.

idempotencyKey
string<uuid>
required

Universally unique identifier (UUID v4) idempotency key. This key is utilized to ensure exactly-once execution of mutating requests. To create a UUIDv4 go to uuidgenerator.net. If the same key is reused, it will be treated as the same request and the original response will be returned.

Example:

"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"

quoteId
string<uuid>
required

System-generated unique identifier of the resource.

Example:

"c4d1da72-111e-4d52-bdbf-2e74a2d803d5"

address
string
required

The wallet address signing the trade presign data.

Example:

"0x1234567890abcdef1234567890abcdef12345678"

message
object
required

The taker Permit2 message derived from the quote response typedData.message.

signature
string
required

The signature generated from signing the trade presign data.

Response

200 - application/json

Trade created successfully

A StableFX trade created from a quote.

id
string<uuid>

System-generated unique identifier of the resource.

Example:

"c4d1da72-111e-4d52-bdbf-2e74a2d803d5"

contractTradeId
string

The ID of the trade on the contract.

Pattern: ^[0-9]+$
Example:

"24"

status
enum<string>
Available options:
pending,
complete,
confirmed,
pending_settlement,
taker_funded,
maker_funded,
refunded,
breaching,
breached
rate
number<double>

Exchange rate for the quote

Example:

0.915

from
object

Currency and amount details for a foreign exchange transaction

to
object

Currency and amount details for a foreign exchange transaction

fee
string

Trade fee charged to the requesting party (matching the type parameter — taker or maker), denominated in the to currency.

Pattern: ^\d+(?:\.\d{1,6})?$
Example:

"100.00"

createDate
string<date-time>

Date and time when the resource was created

Example:

"2023-01-01T12:04:05Z"

updateDate
string<date-time>

Date and time when the resource was last updated

Example:

"2023-01-01T12:04:05Z"

quoteId
string<uuid>

System-generated unique identifier of the resource.

Example:

"c4d1da72-111e-4d52-bdbf-2e74a2d803d5"

settlementTransactionHash
string | null

The hash of the settlement transaction on-chain.

Pattern: ^0x[a-fA-F0-9]{64}$
Example:

"0xf97c6a87511583d5c7e8e72f8e1fe38bfd24350edda78fddbe67125f3cf0a122"

maturity
string<date-time> | null

The date when the trade has matured.

Example:

"2023-01-01T12:04:05Z"

tenor
enum<string>

The settlement schedule for the trade

Available options:
instant,
hourly,
daily
completeDate
string<date-time> | null

The time/date the trade was completed.

Example:

"2023-01-01T12:04:05Z"