Find Trade By ID
This endpoint allows users to retrieve a trade order by ID using an API KEY.
Authentication
ATTENTION: You Need an API Key Token to Access This Endpoint!
Click here to learn how to create an API Key Token → (API Key Token Guide
This endpoint requires an API KEY token. The token must be sent in the api-token
header.
Example:
--header 'api-token: xxxxxxxxxx'
If the token is missing, the API will return:
{
"statusCode": 401,
"status": "error",
"timestamp": "2025-03-04T14:11:39.814Z",
"path": "/token/trades",
"data": {
"message": "ApiKey not provided",
"error": "Unauthorized",
"statusCode": 401
}
}
If the token is invalid, the API will return:
{
"statusCode": 401,
"status": "error",
"timestamp": "2025-03-04T14:12:17.651Z",
"path": "/token/trades/",
"data": {
"message": "Invalid token",
"error": "Unauthorized",
"statusCode": 401
}
}
Endpoints
Retrieve a trade by ID
Method: GET
URL: /token/trades/:id
Authentication: Required (API KEY Token
)
Description: Retrieves a specific trade by its ID.
Request Example
curl --location 'https://api.zaffex.com/token/trades/01JCRQVVZ793NPMASQHZR4361T' \
--header 'api-token: <your_token_here>'
Success Response (200)
{
"id": "01JCRQVVZ793NPMASQHZR4361T",
"userId": "01J16JVXPMZN04TTW9ZVPGSTWQ",
"tenantId": "01HZDQXAXT4XHT9PCXSF0DY333",
"status": "CANCELLED",
"symbol": "BTCUSDT",
"amount": 20,
"createdAt": "2024-11-15T20:22:37.287Z"
}
Open a new trade
Method: POST
URL: /token/trades/open
Authentication: Required (API KEY Token
)
Description: Opens a new trade with the provided parameters.
Request Example
curl -X POST "https://api.zaffex.com/token/trades/open" \
-H "api-token: <your_token_here>" \
-H "Content-Type: application/json" \
-d '{
"symbol": "BTCUSDT",
"volume": 1.5,
"direction": "BUY"
}'
Success Response (200)
{
"tradeId": "01JCRQVVZ793NPMASQHZR4361T",
"status": "OPEN"
}
Retrieve all trades
Method: GET
URL: /token/trades?page=1&pageSize=10
Authentication: Required (API KEY Token
)
Description: Retrieves all trades associated with the authenticated user.
Request Example
curl --location 'https://api.zaffex.com/token/trades?page=1&pageSize=10' \
--header 'api-token: <your_token_here>'
Success Response (200)
{
"currentPage": 1,
"perPage": 10,
"lastPage": 33,
"nextPage": 2,
"prevPage": 1,
"pages": 33,
"total": 10,
"count": 329,
"data": [
{
"id": "01JCRQVVZ793NPMASQHZR4361T",
"symbol": "BTCUSDT",
"userId": "01J16JVXPMZN04TTW9ZVPGSTWQ",
"amount": 20,
"status": "CANCELLED",
"createdAt": "2024-11-15T20:22:37.287Z"
}
]
}
Possible Errors
Status Code | Message | Description |
---|---|---|
401 | Unauthorized | Token is missing or invalid |
500 | Internal Server Error | Unexpected server error |
Usage Example
To retrieve a trade by ID using curl
:
curl -X GET "https://api.zaffex.com/token/trades/01JCRQVVZ793NPMASQHZR4361T" \
-H "api-token: <your_token_here>"
To open a trade using TypeScript with fetch
:
async function openTrade(apiKey: string, tradeData: any): Promise<void> {
try {
const response = await fetch("https://api.zaffex.com/token/trades/open", {
method: "POST",
headers: {
"api-token": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify(tradeData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
console.log("Trade opened:", data);
} catch (error) {
console.error("Error opening trade:", error);
}
}
// Usage example:
openTrade("<your_api_key_here>", { symbol: "BTCUSDT", volume: 1.5, direction: "BUY" });