1.1.0 • Published 6 months ago

@orao-network/price-service v1.1.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
6 months ago

ORAO Price Service

This JavaScript/TypeScript SDK provides a client for interacting with the ORAO Price Service API. It allows users to fetch price feeds for various assets across different networks.

Features

  • Fetch available networks
  • Retrieve whitelists for specific networks
  • Get the latest price feeds for specified assets on a given network

Installation

To use this SDK in your project, install it via npm:

npm install @orao-network/price-service

Usage

Here's a basic example of how to use the SDK:

import {
  Secp256k1PriceService,
  PriceServiceConfig,
} from "@orao-network/price-service";

// Initialize the PriceService
const config: PriceServiceConfig = {
  authToken: "your_auth_token",
  timeout: 5000,
  httpRetries: 3,
  logger: console,
};

const priceService = new Secp256k1PriceService(
  "https://api.example.com",
  config
);

// Get whitelist for a specific network
priceService
  .getWhitelist()
  .then((whitelist) => console.log("whitelist:", whitelist))
  .catch((error) => console.error("Error fetching whitelist:", error));

// Get latest price feeds
const assetNames = ["bitcoin", "ethereum"];
priceService
  .getLatestPriceFeeds(assetNames)
  .then((priceFeed) => {
    console.log("Latest price feed:", priceFeed);
    const priceFeedsUpdateData =
      priceService.getPriceFeedsUpdateData(priceFeed);
    console.log("PriceFeedsUpdateData:", priceFeedsUpdateData);
  })
  .catch((error) => console.error("Error fetching price feeds:", error));

Supported Networks

NetworkService name
evmSecp256k1PriceService
fuelEd25519PriceService
solanaEd25519PriceService

API Reference

Secp256k1PriceService

The main class for interacting with the ORAO Price Service API.

Constructor

constructor(endpoint: string, config?: PriceServiceConfig)
  • endpoint: The base URL of the ORAO Price Service API.
  • config: Optional configuration object.

Methods

getWhitelist(): Promise<string[]>

Retrieves the whitelist.

getLatestPriceFeeds(assetNames: string[]): Promise<PriceFeed>

Retrieves the latest price feeds for specified assets.

Types

PriceServiceConfig

{
  authToken?: string;
  timeout?: number;
  httpRetries?: number;
  logger?: Logger;
}

PriceFeed

{
  prices: Record<string, string>;
  metadata: {
    epoch: number;
    requestHash: string;
    configHash: string;
    signatures: Record<string, string>;
    message: string;
  }
}

Error Handling

All-methods return Promises that may reject with errors. It's recommended to use try-catch blocks or .catch() methods to handle potential errors.

Logging

The SDK uses a configurable logger. You can provide your own logger implementation or use the default console logger for warnings and errors.

1.1.0

6 months ago

1.0.2

7 months ago

1.0.1

9 months ago

1.0.0

9 months ago