Skip to main content

Rate Management API

This document describes the Rate Management endpoints for creating and retrieving digital asset rates.

Endpoints


Create Rate

Creates a new rate for a digital asset by fetching current pricing from configured market data providers.

Endpoint: POST /rates

Request Headers

HeaderTypeRequiredDescription
x-request-idstringNoRequest identifier for tracing (UUID format)
Content-TypestringYesMust be application/json

Request Body

{
"assetCode": "string"
}
FieldTypeRequiredDescription
assetCodestringYesAsset code (e.g., "BTC", "ETH", "SOL")

Note: Currency is currently hardcoded to USD. Future versions may support additional currencies.

Response

Status: 201 Created

{
"rate": 67543.50,
"currency": "USD",
"isStatic": false
}
FieldTypeDescription
ratenumberCurrent rate value for the asset
currencystringCurrency in which the rate is denominated
isStaticbooleanWhether the rate is static (true for stablecoins like USDC/USDT)

Examples

Basic Rate Request

curl -X POST "https://api.ledgerlink.ai/v1/rates" \
-H "Content-Type: application/json" \
-d '{
"assetCode": "BTC"
}'

Response:

{
"rate": 67543.50,
"currency": "USD",
"isStatic": false
}

Rate with Request ID

curl -X POST "https://api.ledgerlink.ai/v1/rates" \
-H "Content-Type: application/json" \
-H "x-request-id: 123e4567-e89b-12d3-a456-426614174000" \
-d '{
"assetCode": "ETH"
}'

Response:

{
"rate": 3124.80,
"currency": "USD",
"isStatic": false
}

Stablecoin Rate

curl -X POST "https://api.ledgerlink.ai/v1/rates" \
-H "Content-Type: application/json" \
-d '{
"assetCode": "USDC"
}'

Response:

{
"rate": 1.0,
"currency": "USD",
"isStatic": true
}

Error Responses

400 Bad Request - Invalid Input

{
"statusCode": 400,
"message": ["assetCode must be a string", "assetCode should not be empty"],
"error": "Bad Request"
}

Causes:

  • Missing assetCode field
  • Invalid data type for assetCode

503 Service Unavailable - Provider Unavailable

{
"statusCode": 503,
"message": "No providers available to fetch rate for BTC",
"error": "Service Unavailable"
}

Causes:

  • All configured providers are down or unreachable
  • No providers configured for the requested asset
  • Provider API rate limits exceeded

500 Internal Server Error

{
"statusCode": 500,
"message": "Failed to create rate",
"error": "Internal Server Error"
}

Causes:

  • Database connection failure
  • ActiveMQ publishing failure
  • Unexpected service error

Rate Calculation Process

  1. Stablecoin Check: If asset is USDC or USDT, returns static rate of 1.0 USD
  2. Static Value Check: If asset has a configured staticValue, returns that value
  3. Asset Lookup: Searches for asset in database by code (case-insensitive)
  4. Provider Selection:
    • If asset found: Uses asset-specific providers or category providers
    • If asset not found: Uses default providers (where isDefault = true)
  5. Multi-Provider Fetch: Queries all selected providers in parallel
  6. Average Calculation: Computes average from all successful provider responses
  7. Data Persistence: Stores rate in database with timestamp and provider details
  8. Event Publishing: Publishes VALUATION_PROCESSED event to ActiveMQ
  9. Response: Returns aggregated rate to client

Provider Data

The rate response includes aggregated data from multiple providers. The actual provider-specific rates are stored in the database data field but not returned in the API response. Example stored data:

{
"assetCode": "BTC",
"providers": {
"coinmarketcap": 67550.00,
"pyth": 67537.00
}
}

List Rates

Retrieves historical rates from the database with filtering, sorting, and pagination capabilities.

Endpoint: GET /rates

Query Parameters

ParameterTypeRequiredDescription
namestringNoFilter by asset name (case-insensitive, partial match)
fromTimestringNoStart date/time (ISO 8601 format)
toTimestringNoEnd date/time (ISO 8601 format)
limitnumberNoMaximum number of results (default: 10)
offsetnumberNoNumber of results to skip (default: 0)
sortBystringNoField to sort by: timestamp, rate (default: timestamp)
sortOrderstringNoSort direction: asc or desc (default: desc)

Response

Status: 200 OK

{
"data": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"assetId": "123e4567-e89b-12d3-a456-426614174000",
"rate": 67543.50,
"currency": "USD",
"timestamp": "2025-11-20T17:00:00.000Z",
"data": {
"assetCode": "BTC",
"providers": {
"coinmarketcap": 67550.00,
"pyth": 67537.00
}
},
"asset": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Bitcoin",
"code": "BTC",
"categoryId": "789e4567-e89b-12d3-a456-426614174000"
}
}
],
"pageInfo": {
"limit": 10,
"offset": 0,
"total": 1547
}
}

Response Fields

Data Array

FieldTypeDescription
idstringUnique rate record ID (UUID)
assetIdstringAssociated asset ID
ratenumberRate value
currencystringCurrency denomination
timestampstringWhen the rate was created (ISO 8601)
dataobjectProvider-specific rate details
assetobjectAssociated asset details

Page Info

FieldTypeDescription
limitnumberRequested limit
offsetnumberRequested offset
totalnumberTotal number of matching records

Examples

Get Latest Rates for Bitcoin

curl -X GET "https://api.ledgerlink.ai/v1/rates?name=bitcoin&limit=10&sortBy=timestamp&sortOrder=desc"

Response:

{
"data": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"assetId": "123e4567-e89b-12d3-a456-426614174000",
"rate": 67543.50,
"currency": "USD",
"timestamp": "2025-11-20T17:00:00.000Z",
"data": {
"assetCode": "BTC",
"providers": {
"coinmarketcap": 67550.00,
"pyth": 67537.00
}
},
"asset": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Bitcoin",
"code": "BTC",
"categoryId": "789e4567-e89b-12d3-a456-426614174000"
}
}
],
"pageInfo": {
"limit": 10,
"offset": 0,
"total": 1547
}
}

Get Rates Within Date Range

curl -X GET "https://api.ledgerlink.ai/v1/rates?name=ethereum&fromTime=2025-11-01T00:00:00Z&toTime=2025-11-20T23:59:59Z&limit=100&sortBy=timestamp&sortOrder=asc"

Get All Rates with Pagination

# First page
curl -X GET "https://api.ledgerlink.ai/v1/rates?limit=20&offset=0"

# Second page
curl -X GET "https://api.ledgerlink.ai/v1/rates?limit=20&offset=20"

Error Responses

400 Bad Request - Invalid Parameters

{
"statusCode": 400,
"message": "Invalid sortBy value. Allowed values: timestamp, rate",
"error": "Bad Request"
}

Causes:

  • Invalid sortBy value
  • Invalid sortOrder value
  • Invalid date format for fromTime or toTime
  • Negative limit or offset

500 Internal Server Error

{
"statusCode": 500,
"message": "Internal server error",
"error": "Internal Server Error"
}

Causes:

  • Database connection failure
  • Query execution error

Use Cases

  1. Real-time Pricing: Use POST /rates to get current market rates on-demand
  2. Historical Analysis: Use GET /rates to retrieve stored rates for charting and analysis
  3. Price Tracking: Query rates within date ranges to track price movements
  4. Audit Trail: Review historical rates with provider details for compliance

Notes

  • POST creates new rates by fetching from providers (real-time)
  • GET retrieves historical rates stored in the database
  • Rates are automatically persisted when created via POST
  • Provider-specific rates are included in the data field
  • Asset relationships are automatically resolved and included
  • Use pagination for large result sets to avoid performance issues
  • Timestamps are in UTC (ISO 8601 format)

Need Help? Contact helpdesk@ledgerlink.ai for assistance.