Trades - Private
GET /v3/trades
/v3/tradesReturns your most recent trades.
Curl
Request
GET /v3/trades?marketCode={marketCode}&limit={limit}&startTime={startTime}&endTime={endTime}Successful response format
{
"success": true,
"data": [
{
"orderId": "160067484555913076",
"clientOrderId": "123",
"matchId": "160067484555913077",
"marketCode": "OX-USDT",
"side": "SELL",
"matchedQuantity": "0.1",
"matchPrice": "0.065",
"total": "0.0065",
"orderMatchType": "TAKER",
"feeAsset": "OX",
"fee":"0.0196",
"source": "10",
"matchedAt": "1595514663626"
}
]
}Python
import os
import requests
import hmac
import hashlib
import base64
import time
from dotenv import load_dotenv
load_dotenv()
def fetch_trades(market_code, limit, start_time, end_time):
api_key = os.getenv('API_KEY')
secret_key = os.getenv('API_SECRET').encode('utf-8')
ts = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime())
nonce = str(int(time.time() * 1000))
method = "/v3/trades"
api_url = "api.ox.fun"
query_string = f"marketCode={market_code}&limit={limit}&startTime={start_time}&endTime={end_time}"
msg_string = f"{ts}\n{nonce}\nGET\n{api_url}\n{method}\n{query_string}"
sign = base64.b64encode(hmac.new(secret_key, msg_string.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')
headers = {
'Content-Type': 'application/json',
'AccessKey': api_key,
'Timestamp': ts,
'Signature': sign,
'Nonce': nonce
}
url = f"https://{api_url}{method}?{query_string}"
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
if data.get('success'):
print('Trades Data:', data['data'])
else:
print('Failed to fetch trades')
except requests.exceptions.RequestException as error:
print('Error fetching trades:', error)
# Example usage
market_code = 'BTC-USD-SWAP-LIN'
limit = 100
start_time = int(time.time() * 1000) - 24 * 60 * 60 * 1000 # 24 hours ago
end_time = int(time.time() * 1000)
fetch_trades(market_code, limit, start_time, end_time)Javascript
const axios = require('axios');
const crypto = require('crypto');
require('dotenv').config();
async function fetchTrades(marketCode, limit, startTime, endTime) {
const apiKey = process.env.API_KEY;
const secretKey = process.env.API_SECRET;
const ts = new Date().toISOString().split('.')[0] + 'Z';
const nonce = Date.now().toString();
const method = "/v3/trades";
const apiUrl = "api.ox.fun";
const queryString = `marketCode=${marketCode}&limit=${limit}&startTime=${startTime}&endTime=${endTime}`;
const msgString = `${ts}\n${nonce}\nGET\n${apiUrl}\n${method}\n${queryString}`;
const sign = crypto.createHmac('sha256', secretKey)
.update(msgString)
.digest('base64');
const headers = {
'Content-Type': 'application/json',
'AccessKey': apiKey,
'Timestamp': ts,
'Signature': sign,
'Nonce': nonce
};
const url = `https://${apiUrl}${method}?${queryString}`;
try {
const response = await axios.get(url, { headers });
if (response.data.success) {
console.log('Trades Data:', response.data.data);
} else {
console.error('Failed to fetch trades');
}
} catch (error) {
console.error('Error fetching trades:', error.response ? error.response.data : error.message);
}
}
// Example usage
const market_code = 'BTC-USD-SWAP-LIN';
const limit = 100;
const start_time = Date.now() - 24 * 60 * 60 * 1000; // 24 hours ago
const end_time = Date.now();
fetchTrades(market_code, limit, start_time, end_time);marketCode
String
default most recent trades first
limit
LONG
NO
max 500, default 200
startTime
LONG
NO
Millisecond timestamp. Default 24 hours ago. startTime and endTime must be within 7 days of each other. startTime is INCLUSIVE
endTime
LONG
NO
Millisecond timestamp. Default time now. startTime and endTime must be within 7 days of each other. endTime is INCLUSIVE
orderId
STRING
Order ID
clientOrderId
STRING
Client assigned ID to help manage and identify orders with max value 9223372036854775807
matchId
STRING
Match ID
marketCode
STRING
Market code
side
STRING
Side of the order, BUY or SELL
matchedQuantity
STRING
Match quantity
matchPrice
STRING
Match price
total
STRING
Total price
orderMatchType
STRING
TAKER,MAKER
feeAsset
STRING
Instrument ID of the fees
fee
STRING
Fees
source
STRING
Source of the request, available values: 0, 2, 10, 11, 13, 22, 101, 102, 103, 104, 111.
Enumeration: 0: GUI, 2: Borrow, 11: REST, 13: Websocket, 22: Delivery, 101: Automatic borrow, 102: Borrow position liquidation, 103: Contract liquidation, 104: Liquidation revert, 111: Automatic repayment
matchedAt
STRING
Millisecond timestamp of the order matched time
Last updated