Skip to content

cybor97/priceapi-coingecko-hypercore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Price API

A distributed price API service that provides real-time and historical cryptocurrency price data through RPC endpoints.

RPC API Endpoints

The API exposes the following RPC endpoints:

ping

Simple health check endpoint that increments the provided nonce.

Request:

{
  "nonce": number
}

Response:

{
  "nonce": number
}

getLatestPrices

Retrieves the latest prices for specified trading pairs.

Request:

{
  "pairs": string[]
}

Response:

{
  "prices": {
    "BTCUSDT": {
      "tickers": [
        {
          "exchange": string,
          "price": number
        }
      ],
      "avg": number
    }
  }
}

getHistoricalPrices

Retrieves historical price data for specified trading pairs within a time range.

Request:

{
  "pairs": string[],
  "from": number,  // Seq
  "to": number     // Seq
}

Response:

{
  "prices": {
    "BTCUSDT": [
      {
        "timestamp": number,
        "value": {
          "tickers": [
            {
              "exchange": string,
              "price": number
            }
          ],
          "avg": number
        }
      }
    ]
  }
}

runPricePipeline

Triggers the price pipeline job to update price data. No payload required

Response:

{
  "success": boolean,
  "error": string  // Only present if success is false
}

Error Handling

All endpoints return a standard error response format when an error occurs:

{
  "success": false,
  "error": "Error message"
}

Environment Variables

  • BOOTSTRAP_HOST: Bootstrap node host (default: "127.0.0.1")
  • BOOTSTRAP_PORT: Bootstrap node port (default: 30001)
  • DHT_PORT: DHT network port (default: 40001)

Notes

  • Trading pairs should be provided in the format "BTC/USD" and will be internally converted to "BTCUSD"
  • All price values are returned as numbers with appropriate decimal places
  • The API uses a distributed hash table (DHT) for peer discovery and communication

Sample client

Added sample client providing light demo of functionality. Relies on the same .env + SERVER_PUB_KEY env variable

Implementation notes

  • Current implementation misses:
    • Data issues handling from Coingecko
    • Stores market fields with tickers wheres id would be enough and markets themselves could be stored separately
    • RPC query validation
    • Better storage management
    • RPC client implementation with proper CLI
    • Smarter way for scheduling, current implementation ignores ttl which is taken from coingecko API docs and should be used for caching or iteration planning
  • Nice to have:
    • Progress tracking
    • Authorization and throttler which would allow to run service not only locally
    • Scalability improvements
    • Tests

About

Not a final version, there are several points to fix/improve

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published