The UTXO Pricing API provides functionality to interact with price data for Unspent Transaction Output (UTXO) based blockchains.
import { Pricing, PriceType } from "@noves/noves-sdk";
// Initialize the UTXO pricing client
const utxoPricing = Pricing.utxo("YOUR_API_KEY");Returns a list of supported UTXO chains.
const chains = await utxoPricing.getChains();
// Returns: UTXOPricingChainsResponseResponse Type: UTXOPricingChainsResponse
interface UTXOPricingChain {
name: string;
ecosystem: 'utxo';
nativeCoin: {
name: string;
symbol: string;
address: string;
decimals: number;
};
}
type UTXOPricingChainsResponse = UTXOPricingChain[];Example response:
[
{
"name": "btc",
"ecosystem": "utxo",
"nativeCoin": {
"name": "BTC",
"symbol": "BTC",
"address": "BTC",
"decimals": 8
}
},
{
"name": "cardano",
"ecosystem": "utxo",
"nativeCoin": {
"name": "ADA",
"symbol": "ADA",
"address": "ADA",
"decimals": 6
}
}
]Returns the price for any token at the given timestamp. If no timestamp is passed, the price for the latest block will be returned.
const price = await utxoPricing.getPrice(
"btc", // chain
"bitcoin", // token identifier
{ // optional parameters
priceType: PriceType.WEIGHTED_VOLUME_AVERAGE,
timestamp: 1640995200
}
);
// Returns: UTXOPricingPriceParameters:
chain(string): The name of the chain to retrieve pricing fortoken(string): The token identifier to retrieve pricing foroptions(optional object):priceType(PriceType | string): The type of price to retrieve (defaults toPriceType.WEIGHTED_VOLUME_AVERAGE)timestamp(number): The timestamp for which to retrieve the price
Pricing Strategies: See Pricing Strategies Documentation for all available strategies.
PriceType.DEX_HIGHEST_LIQUIDITY- Uses the liquidity pool with the highest liquidityPriceType.COINGECKO- Uses Coingecko as a price sourcePriceType.CUSTOM- Uses a custom strategyPriceType.WEIGHTED_VOLUME_AVERAGE- Uses a weighted volume average across exchanges
Response Type: UTXOPricingPrice
interface UTXOPricingToken {
symbol: string;
name: string;
address: string;
decimals: number;
}
interface UTXOPricingPriceInfo {
amount: string;
currency: string;
status: string;
}
interface UTXOPricingPrice {
chain: string;
token: UTXOPricingToken;
price: UTXOPricingPriceInfo;
priceType: string;
priceStatus: string;
}Example response:
{
"chain": "btc",
"token": {
"symbol": "BTC",
"name": "Bitcoin",
"address": "btc",
"decimals": 8
},
"price": {
"amount": "103780.71410240",
"currency": "USD",
"status": "resolved"
},
"priceType": "weightedVolumeAverage",
"priceStatus": "resolved"
}For complete examples, see the UTXO Pricing Examples.
The UTXO Pricing API can throw various errors:
- Network-related errors when API requests fail
- Invalid parameters or authentication errors
try {
const price = await utxoPricing.getPrice("btc", "bitcoin");
} catch (error) {
console.error("API error:", error.message);
}