Skip to content

API specification

Yoxira edited this page Aug 22, 2024 · 6 revisions

/status

Returns status of the app including next update.

  • Request

    GET http://ip:port/status
    

    No parameters.

  • Response

    {
      success: boolean,
      // Unix timestamp of the server time in ms
      date: number,
      // Whether Currencyinfo has fetched its first rates
      ready: boolean,
      // Whether Currencyinfo is updating the rates right now
      updating: boolean,
      // Unix timestamp in ms of the next update or the current one when updating
      next_update: number,
      // Unix timestamp of the last update in ms or `null` before the first rates have been fetched
      last_updated: number | null,
      // Currencyinfo version in `x.y.z` format
      version: string
    }
  • Examples
    • http://localhost:36668/status
      
      • Response of the endpoint when Currencyinfo hasn't fetched its first rates:

        {
          "success": true,
          "date": 1720929107999,
          "ready": false,
          "updating": true,
          "next_update": 1720929107763,
          "last_updated": null,
          "version": "4.0.0",
        }
      • Retrieved status information after Currencyinfo has been initialized:

        {
          "success": true,
          "date": 1720928929287,
          "ready": true,
          "updating": false,
          "next_update": 1720929503829,
          "last_updated": 1720928903829,
          "version": "4.0.0",
        }
      • Status if Currencyinfo is currently updating the rates:

        {
          "success": true,
          "date": 1720929504829,
          "ready": true,
          "updating": true,
          "next_update": 1720929503829,
          "last_updated": 1720928903829,
          "version": "4.0.0",
        }

/get

Allows to fetch the latest available rates: all of them, or the specific ones.

  • Request

    GET http://ip:port/get
    

    Parameters:

    • coin — optional parameter, allowing to provide only specific tickers list, comma-separated.
    • rateLiftime — overrides rateLifetime from the config for the request. Optional.
  • Response

    {
      success: boolean,
      date: number, // Unix timestamp of the server time in ms
      last_updated: number, // Unix timestamp of the last tickers update in ms
      version: string, // InfoService version
      result: {
        PAIR1: number,
        // ...
        PAIR_N: number
      }
    }
  • Examples
    • To get all latest available tickers for ADM and CNY:

      http://localhost:36668/get?coin=ADM,CNY
      
      {
        "success": true,
        "date": 1551646782431,
        "last_updated": 1557521811231,
        "version": "4.0.0",
        "result": {
          "ADM/JPY": 0.01509405,
          "ADM/BTC": 0.00000353,
          "CNY/RUB": 9.8435,
          // ...
          "USD/CNY": 6.69154772,
          "BTC/CNY": 25792.65683239,
        },
      }
    • To get the latest available tickers for all the available coins:

      http://localhost:36668/get
      
      {
        "success": true,
        "date": 1551646782431,
        "last_updated": 1557521811231,
        "version": "4.0.0",
        "result": {
          "USD/RUB": 65.86825,
          "RUB/USD": 0.01518182,
          // ...
          "AT/ETH": 0.00002025,
          "TUSD/ETH": 0.00761325,
        },
      }

/getHistory

Retrieves historical rates from the database. The result is simply snapshots of responses from the /get endpoint.

  • Request

    http://ip:port/getHistory?params
    

    You must specify params, at least one parameter is necessary:

    • timestamp — get rates nearest to value in Unix time (sec). Depending on InfoServices parameters and stored data, the nearest rates can differ in an hour or more. Client should calculate time difference between request and result timestamps and do its own behavior.

    • from — fetch records starting from value in Unix time (sec).

    • to — fetch records up to value in Unix time (sec).

    • limit — amount of records to retrieve. Maximum is 100.

    • coin — filter response for selected coin only. Specify only one ticker.

      Supported formats:

      • COIN - selects tickers where COIN is either the base or quote coin
      • COIN/ - selects tickers where COIN is the base coin
      • /COIN - selects tickers where COIN is the quote coin
      • COIN1/COIN2 - selects a specific pair
  • Response

    {
      success: boolean,
      date: number, // Unix timestamp of the server time in ms
      last_updated: number, // Unix timestamp of the last tickers update in ms
      version: string, // InfoService version
      result: [
        {
          _id: string,
          tickers: {
            PAIR1: number,
            // ...
            PAIR_N: number
          },
          date: number
        }
      ]
    }

    Where results array includes all of requested historical data. Field _id is internal database's document identifier.

  • Examples
    • To get rates for ADM token nearest to 1557525409 timestamp:

      http://localhost:36668/getHistory?timestamp=1557525409&coin=ADM
      
      {
        "success": true,
        "date": 1557639105856,
        "last_updated": 1557521811231,
        "version": "4.0.0",
        "result": [
          {
            "_id": "5cd7299fff5980058cebdceb",
            "tickers": {
              "ADM/USD": 0.03011223,
              "ADM/RUB": 1.96115985,
              "ADM/EUR": 0.02688229,
              "ADM/CNY": 0.20478986,
              "ADM/JPY": 3.32195872,
              "ADM/BTC": 0.00000478,
              "ADM/ETH": 0.00017551,
            },
            "date": 1557521811231,
          },
        ],
      }
    • To get 2 rates records between 1557525409 and 1557535409 timestamps:

      http://localhost:36668/getHistory?from=1557525409&to=1557535409&limit=2
      
      {
        "success": true,
        "date": 1557641417204,
        "last_updated": 1557521811231,
        "version": "4.0.0",
        "result": [
          {
            "_id": "5cd7299fff5980058cebdcee",
            "tickers": {
              "USD/RUB": 65.12835,
              "RUB/USD": 0.0153543,
              "EUR/RUB": 72.9536,
              "USD/EUR": 0.89273662,
              "GBR/RUB": 84.8135,
              // ...
            },
            "date": 1557532610294,
          },
          {
            "_id": "5cd7299fff5980058cebdced",
            "tickers": {
              "USD/RUB": 65.12835,
              "RUB/USD": 0.0153543,
              "EUR/RUB": 72.9536,
              "USD/EUR": 0.89273662,
              "GBR/RUB": 84.8135,
              // ...
            },
            "date": 1557529010543,
          },
        ],
      }
    • To get rates where EUR is the base coin for the given timestamp:

      http://localhost:36661/getHistory?timestamp=1557525409&coin=/EUR
      
      {
        "success": true,
        "date": 1723284810251,
        "last_updated": 1723284403858,
        "version": "4.0.0",
        "result": [
          {
            "_id": "5cd5e5933c41885b7a4aadfe",
            "date": 1557521811231,
            "tickers": {
              "ADM/EUR": 0.02688229,
              "AT/EUR": 0.04153587,
              "ZEC/EUR": 51.13833949,
              // ...
            },
          },
        ],
      }
Clone this wiki locally