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
const price = await client.getCurrentPrice('BTC', '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 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')