1.1.0 • Published 6 months ago
@orao-network/price-service v1.1.0
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-serviceUsage
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
| Network | Service name |
|---|---|
| evm | Secp256k1PriceService |
| fuel | Ed25519PriceService |
| solana | Ed25519PriceService |
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.