Configuration
Configure HTTP pricing clients and providers
Bitfinex HTTP Client
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
// Create the client (no options needed)
const client = new BitfinexPricingClient()Current Price
Current-price lookups use Bitfinex's FX conversion endpoint. If Bitfinex cannot quote the pair directly, the client tries a two-leg from -> USD -> to conversion. If the pair still cannot be resolved, the result is null.
const price = await client.getCurrentPrice('BTC', 'USD')
const brlPrice = await client.getCurrentPrice('BTC', 'BRL') // resolved through USD when available
if (price === null) {
// Show an unavailable-price state in your UI
}Batch Current Prices
Batch lookups return results in the same order as the input list. Entries that cannot be resolved are null.
const prices = await client.getMultiCurrentPrices([
{ from: 'BTC', to: 'USD' },
{ from: 'ETH', to: 'BRL' }
])Batch Price Data
Use getMultiPriceData() when you need the last price plus 24-hour absolute and relative change. This method uses Bitfinex ticker data and only supports pairs Bitfinex quotes directly.
const priceData = await client.getMultiPriceData([
{ from: 'BTC', to: 'USD' }
])Historical Series
Downscales long histories to ≤ 100 points.
const series = await client.getHistoricalPrice('BTC', 'USD', {
start: 1709906400000, // optional (ms)
end: 1709913600000 // optional (ms)
})Provider Integration
Works with @tetherto/wdk-pricing-provider as a PricingClient implementation.
You can pass a single client or an array of clients. When an array is provided, connection errors trigger automatic failover to the next client in the list.
import { PricingProvider } from '@tetherto/wdk-pricing-provider'
const provider = new PricingProvider({
client,
priceCacheDurationMs: 60 * 60 * 1000 // optional, defaults to 1h
})
const last = await provider.getLastPrice('BTC', 'USD')
const prices = await provider.getMultiLastPrices([
{ from: 'BTC', to: 'USD' },
{ from: 'ETH', to: 'BRL' }
])
const hist = await provider.getHistoricalPrice('BTC', 'USD', {
start: 1709906400000,
end: 1709913600000
})To enable failover, pass an ordered array of PricingClient instances. The provider tries each client in order when a connection error occurs.
import { PricingProvider } from '@tetherto/wdk-pricing-provider'
const provider = new PricingProvider({
client: [primaryClient, secondaryClient, tertiaryClient],
retries: 3 // optional, defaults to 3
})
const last = await provider.getLastPrice('BTC', 'USD')