Trade Methods

LP-9002 JSON-RPC trade query methods

Trade Methods

Methods for querying executed trades. Public trades are accessible without authentication; user-specific trades require authentication.

lx_getTrades

Get recent public trades for a market.

Parameters

NameTypeRequiredDescription
marketstringYesTrading pair (e.g., "BTC-USDT")
limitintegerNoNumber of trades (default: 100, max: 1000)
fromIdstringNoGet trades after this trade ID
startTimeintegerNoStart timestamp (ms)
endTimeintegerNoEnd timestamp (ms)

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTrades",
  "params": {
    "market": "BTC-USDT",
    "limit": 50
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "market": "BTC-USDT",
    "trades": [
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440100",
        "price": "42000.50",
        "quantity": "0.2500",
        "value": "10500.125",
        "side": "buy",
        "timestamp": 1702300500000
      },
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440099",
        "price": "42000.00",
        "quantity": "0.1500",
        "value": "6300.00",
        "side": "sell",
        "timestamp": 1702300450000
      },
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440098",
        "price": "41999.50",
        "quantity": "1.0000",
        "value": "41999.50",
        "side": "buy",
        "timestamp": 1702300400000
      }
    ],
    "hasMore": true
  }
}

Trade Object

FieldTypeDescription
tradeIdstringUnique trade identifier
pricestringExecution price
quantitystringTrade quantity
valuestringTrade value (price * quantity)
sidestringAggressor side: "buy" or "sell"
timestampintegerTrade timestamp (ms)

curl Example

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getTrades",
    "params": {
      "market": "BTC-USDT",
      "limit": 100
    }
  }'

Pagination with fromId

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTrades",
  "params": {
    "market": "BTC-USDT",
    "limit": 100,
    "fromId": "660e8400-e29b-41d4-a716-446655440098"
  }
}

Time-Based Query

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTrades",
  "params": {
    "market": "BTC-USDT",
    "startTime": 1702200000000,
    "endTime": 1702300000000,
    "limit": 500
  }
}

Errors

CodeMessageCause
-32001Market not foundInvalid market symbol
-32602Invalid paramsInvalid time range or limit

Rate Limit

  • Limit: 100 requests per second
  • Note: Public endpoint

lx_getUserTrades

Get authenticated user's trade history.

Parameters

NameTypeRequiredDescription
marketstringNoFilter by market
orderIdstringNoFilter by order ID
sidestringNoFilter by "buy" or "sell"
startTimeintegerNoStart timestamp (ms)
endTimeintegerNoEnd timestamp (ms)
limitintegerNoMax results (default: 100, max: 500)
offsetintegerNoPagination offset

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getUserTrades",
  "params": {
    "market": "BTC-USDT",
    "startTime": 1702200000000,
    "limit": 100
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "trades": [
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440100",
        "orderId": "550e8400-e29b-41d4-a716-446655440000",
        "clientOrderId": "my-order-001",
        "market": "BTC-USDT",
        "side": "buy",
        "price": "42000.50",
        "quantity": "0.2500",
        "value": "10500.125",
        "fee": "5.25",
        "feeAsset": "USDT",
        "feeRate": "0.0005",
        "role": "taker",
        "realizedPnl": null,
        "timestamp": 1702300500000
      },
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440095",
        "orderId": "550e8400-e29b-41d4-a716-446655440001",
        "market": "BTC-USDT",
        "side": "sell",
        "price": "42100.00",
        "quantity": "0.1000",
        "value": "4210.00",
        "fee": "2.10",
        "feeAsset": "USDT",
        "feeRate": "0.0005",
        "role": "maker",
        "realizedPnl": "10.00",
        "timestamp": 1702300000000
      }
    ],
    "total": 156,
    "limit": 100,
    "offset": 0,
    "hasMore": true
  }
}

User Trade Object

FieldTypeDescription
tradeIdstringUnique trade identifier
orderIdstringAssociated order ID
clientOrderIdstring | nullClient order ID if set
marketstringTrading pair
sidestringYour side: "buy" or "sell"
pricestringExecution price
quantitystringTrade quantity
valuestringTrade value
feestringFee amount
feeAssetstringFee currency
feeRatestringFee rate applied
rolestring"maker" or "taker"
realizedPnlstring | nullRealized profit/loss (futures)
timestampintegerTrade timestamp (ms)

curl Example

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_api_secret" \
  -H "X-API-Timestamp: 1702300000000" \
  -H "X-API-Signature: signature_here" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getUserTrades",
    "params": {
      "market": "BTC-USDT",
      "limit": 100
    }
  }'

Filter by Order

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getUserTrades",
  "params": {
    "orderId": "550e8400-e29b-41d4-a716-446655440000"
  }
}

Rate Limit

  • Limit: 20 requests per second
  • Authentication: Required

lx_getTradeHistory

Get historical trade data with OHLCV aggregation.

Parameters

NameTypeRequiredDescription
marketstringYesTrading pair
intervalstringNoAggregation interval (see below)
startTimeintegerNoStart timestamp (ms)
endTimeintegerNoEnd timestamp (ms)
limitintegerNoNumber of candles (default: 100, max: 1000)

Intervals

ValueDescription
1m1 minute
5m5 minutes
15m15 minutes
30m30 minutes
1h1 hour
4h4 hours
1d1 day
1w1 week

Request (Raw Trades)

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTradeHistory",
  "params": {
    "market": "BTC-USDT",
    "startTime": 1702200000000,
    "endTime": 1702300000000,
    "limit": 1000
  }
}

Response (Raw Trades)

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "market": "BTC-USDT",
    "trades": [
      {
        "tradeId": "660e8400-e29b-41d4-a716-446655440100",
        "price": "42000.50",
        "quantity": "0.2500",
        "side": "buy",
        "timestamp": 1702300500000
      }
    ],
    "count": 1000,
    "hasMore": true
  }
}

Request (OHLCV)

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTradeHistory",
  "params": {
    "market": "BTC-USDT",
    "interval": "1h",
    "startTime": 1702200000000,
    "endTime": 1702300000000,
    "limit": 100
  }
}

Response (OHLCV)

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "market": "BTC-USDT",
    "interval": "1h",
    "candles": [
      {
        "timestamp": 1702296000000,
        "open": "41950.00",
        "high": "42100.00",
        "low": "41900.00",
        "close": "42000.50",
        "volume": "125.5000",
        "quoteVolume": "5268750.00",
        "trades": 1234
      },
      {
        "timestamp": 1702292400000,
        "open": "41800.00",
        "high": "41980.00",
        "low": "41750.00",
        "close": "41950.00",
        "volume": "98.2500",
        "quoteVolume": "4108087.50",
        "trades": 987
      }
    ],
    "hasMore": true
  }
}

OHLCV Candle Object

FieldTypeDescription
timestampintegerCandle open time (ms)
openstringOpening price
highstringHighest price
lowstringLowest price
closestringClosing price
volumestringBase asset volume
quoteVolumestringQuote asset volume
tradesintegerNumber of trades

curl Example

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getTradeHistory",
    "params": {
      "market": "BTC-USDT",
      "interval": "1h",
      "limit": 24
    }
  }'

Rate Limit

  • Limit: 50 requests per second
  • Note: Public endpoint

lx_getAggregatedTrades

Get trades aggregated by price level over a time period.

Parameters

NameTypeRequiredDescription
marketstringYesTrading pair
startTimeintegerYesStart timestamp (ms)
endTimeintegerYesEnd timestamp (ms)
sidestringNoFilter by "buy" or "sell"

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getAggregatedTrades",
  "params": {
    "market": "BTC-USDT",
    "startTime": 1702296000000,
    "endTime": 1702300000000
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "market": "BTC-USDT",
    "startTime": 1702296000000,
    "endTime": 1702300000000,
    "aggregates": [
      {
        "price": "42000.00",
        "buyVolume": "15.2500",
        "sellVolume": "12.7500",
        "totalVolume": "28.0000",
        "buyTrades": 145,
        "sellTrades": 120,
        "totalTrades": 265
      },
      {
        "price": "41999.50",
        "buyVolume": "8.5000",
        "sellVolume": "9.2500",
        "totalVolume": "17.7500",
        "buyTrades": 78,
        "sellTrades": 85,
        "totalTrades": 163
      }
    ],
    "summary": {
      "totalBuyVolume": "125.5000",
      "totalSellVolume": "118.7500",
      "totalVolume": "244.2500",
      "vwap": "42005.25",
      "totalTrades": 2345
    }
  }
}

Summary Object

FieldTypeDescription
totalBuyVolumestringTotal buy volume
totalSellVolumestringTotal sell volume
totalVolumestringCombined volume
vwapstringVolume-weighted average price
totalTradesintegerTotal number of trades

curl Example

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getAggregatedTrades",
    "params": {
      "market": "BTC-USDT",
      "startTime": 1702296000000,
      "endTime": 1702300000000
    }
  }'

Rate Limit

  • Limit: 20 requests per second

lx_getTradeStatistics

Get trade statistics for a market.

Parameters

NameTypeRequiredDescription
marketstringYesTrading pair
periodstringNoTime period: "1h", "24h", "7d", "30d" (default: "24h")

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_getTradeStatistics",
  "params": {
    "market": "BTC-USDT",
    "period": "24h"
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "market": "BTC-USDT",
    "period": "24h",
    "startTime": 1702213600000,
    "endTime": 1702300000000,
    "stats": {
      "totalTrades": 125678,
      "totalVolume": "3456.7500",
      "totalValue": "145234567.50",
      "avgTradeSize": "0.0275",
      "avgPrice": "42012.35",
      "vwap": "42008.12",
      "medianPrice": "42000.00",
      "priceStdDev": "125.50",
      "buyVolume": "1789.2500",
      "sellVolume": "1667.5000",
      "buyRatio": "0.5176",
      "largestTrade": {
        "tradeId": "660e8400-e29b-41d4-a716-446655440999",
        "price": "42050.00",
        "quantity": "25.0000",
        "value": "1051250.00",
        "timestamp": 1702298765000
      }
    }
  }
}

Statistics Fields

FieldTypeDescription
totalTradesintegerNumber of trades in period
totalVolumestringTotal base asset volume
totalValuestringTotal quote asset volume
avgTradeSizestringAverage trade size
avgPricestringSimple average price
vwapstringVolume-weighted average price
medianPricestringMedian trade price
priceStdDevstringPrice standard deviation
buyVolumestringTotal buy volume
sellVolumestringTotal sell volume
buyRatiostringBuy volume / total volume
largestTradeobjectLargest single trade

curl Example

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getTradeStatistics",
    "params": {
      "market": "BTC-USDT",
      "period": "24h"
    }
  }'

Rate Limit

  • Limit: 20 requests per second

OpenRPC Schema Reference

{
  "name": "lx_getTrades",
  "summary": "Get recent trades for a market",
  "params": [
    {
      "name": "market",
      "required": true,
      "schema": {"type": "string", "pattern": "^[A-Z]+-[A-Z]+$"}
    },
    {
      "name": "limit",
      "required": false,
      "schema": {"type": "integer", "minimum": 1, "maximum": 1000, "default": 100}
    },
    {
      "name": "fromId",
      "required": false,
      "schema": {"type": "string", "format": "uuid"}
    }
  ],
  "result": {
    "name": "TradesResult",
    "schema": {
      "type": "object",
      "properties": {
        "market": {"type": "string"},
        "trades": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "tradeId": {"type": "string"},
              "price": {"type": "string"},
              "quantity": {"type": "string"},
              "side": {"type": "string", "enum": ["buy", "sell"]},
              "timestamp": {"type": "integer"}
            }
          }
        },
        "hasMore": {"type": "boolean"}
      }
    }
  }
}