Logo
API Documentation

Historical Trades API

API endpoint for retrieving historical trade data for specific trading pairs

Retrieves historical trade data for a specific trading pair.

Endpoint

GET /v1/spot/historical_trades

Base URL

https://dev-backend.pixpel.io

Query Parameters

ParameterTypeRequiredDefaultDescription
chainnumberYes1482601649Blockchain chain ID
ticker_idstringYes-Trading pair identifier (format: BASE_TARGET)
typestringNo"all"Trade type filter: "buy", "sell", or "all"
limitnumberNo100Maximum number of trades to return (0 = all)
start_timestringNo-Unix timestamp - filter trades after this time
end_timestringNo-Unix timestamp - filter trades before this time

Request Examples

Get all trades for a pair:

curl -X GET "https://dev-backend.pixpel.io/v1/spot/historical_trades?chain=1482601649&ticker_id=0x123abc_0x456def"

Get last 50 buy trades:

curl -X GET "https://dev-backend.pixpel.io/v1/spot/historical_trades?chain=1482601649&ticker_id=0x123abc_0x456def&type=buy&limit=50"

Get trades within time range:

curl -X GET "https://dev-backend.pixpel.io/v1/spot/historical_trades?chain=1482601649&ticker_id=0x123abc_0x456def&start_time=1699200000&end_time=1699286400"

JavaScript/TypeScript:

const params = new URLSearchParams({
  chain: '1482601649',
  ticker_id: '0x123abc_0x456def',
  type: 'all',
  limit: '100'
});

const response = await fetch(`https://dev-backend.pixpel.io/v1/spot/historical_trades?${params}`);
const trades = await response.json();

Python:

import requests

params = {
    'chain': 1482601649,
    'ticker_id': '0x123abc_0x456def',
    'type': 'all',
    'limit': 100
}

response = requests.get('https://dev-backend.pixpel.io/v1/spot/historical_trades', params=params)
trades = response.json()

Response Schema

{
  "success": true,
  "statusCode": 200,
  "message": "Success",
  "data": {
    "buy": [
      {
        "trade_id": 0,
        "price": 0,
        "base_volume": "string",
        "target_volume": "string",
        "trade_timestamp": 0,
        "type": "buy"
      }
    ],
    "sell": [
      {
        "trade_id": 0,
        "price": 0,
        "base_volume": "string",
        "target_volume": "string",
        "trade_timestamp": 0,
        "type": "sell"
      }
    ]
  }
}

Response Fields

FieldTypeDescription
trade_idnumberUnique trade identifier (block_number * 1000 + index)
pricenumberTrade execution price as decimal number (6 decimal precision)
base_volumestringAmount of base currency traded (6 decimal places)
target_volumestringAmount of target currency traded (6 decimal places)
trade_timestampnumberUnix timestamp in milliseconds
typestringTrade type: "buy" or "sell"

Trade Type Logic

  • Buy Trade: amount0In > 0 and amount1Out > 0 (swapping base for target)
    Price = amount1Out / amount0In
  • Sell Trade: amount1In > 0 and amount0Out > 0 (swapping target for base)
    Price = amount1In / amount0Out

Example Response

{
  "success": true,
  "statusCode": 200,
  "message": "Success",
  "data": {
    "buy": [
      {
        "trade_id": 123456001,
        "price": 1.234567,
        "base_volume": "100.000000",
        "target_volume": "123.456700",
        "trade_timestamp": 1699200000000,
        "type": "buy"
      },
      {
        "trade_id": 123457001,
        "price": 1.235000,
        "base_volume": "50.000000",
        "target_volume": "61.750000",
        "trade_timestamp": 1699201000000,
        "type": "buy"
      }
    ],
    "sell": [
      {
        "trade_id": 123458001,
        "price": 1.230000,
        "base_volume": "75.000000",
        "target_volume": "92.250000",
        "trade_timestamp": 1699202000000,
        "type": "sell"
      }
    ]
  }
}

Error Responses

400 Bad Request - Missing ticker_id:

{
  "success": false,
  "statusCode": 400,
  "message": "ticker_id is required"
}

400 Bad Request - Invalid ticker_id format:

{
  "success": false,
  "statusCode": 400,
  "message": "Invalid ticker_id format. Expected: BASE_TARGET"
}

404 Not Found - Pair doesn't exist:

{
  "success": false,
  "statusCode": 404,
  "message": "Pair not found"
}

500 Internal Server Error:

{
  "success": false,
  "statusCode": 500,
  "message": "Error retrieving historical trades"
}