Configuration
Configure HTTP pricing clients and providers
Bitfinex HTTP Client
In @tetherto/wdk-pricing-bitfinex-http beta.6, pass common ticker symbols to the client methods. Symbols are case-insensitive: USDT and usdt both use Bitfinex's UST currency code for USD₮. The same translation applies to current prices, batch price data, and historical lookups.
Create a client to use the built-in mappings and Bitfinex's published aliases:
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
// Create the client (no options needed)
const client = new BitfinexPricingClient()Currency-Code Overrides (optional)
Use the optional currencyCodes object to set explicit common-symbol-to-Bitfinex-code mappings. Entries take precedence over built-in mappings and remote aliases. Both keys and values are uppercased.
For example, these explicit BTC and USD mappings let the client resolve that pair without fetching the remote alias map:
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
const mappedClient = new BitfinexPricingClient({
currencyCodes: { btc: 'btc', usd: 'usd' }
})
const price = await mappedClient.getCurrentPrice('BTC', 'USD')For symbols without an explicit or built-in mapping, the client looks up Bitfinex's aliases and caches a successful lookup for that client instance. An unknown or ambiguous alias falls back to the uppercased input symbol. If the alias lookup fails, the client uses that fallback and retries the alias lookup on a later request. Translation does not add support for pairs Bitfinex cannot quote, and errors from price requests can still reject the call.
Current Price
Current-price lookups use Bitfinex's FX conversion endpoint. The client returns a price only when Bitfinex can quote the pair directly. Unsupported pairs return null; the client does not try a USD-pivot fallback.
const price = await client.getCurrentPrice('BTC', 'USD')
const unsupported = await client.getCurrentPrice('BTC', 'BRL') // null when Bitfinex has no direct quote
if (unsupported === 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: 'USD' },
{ from: 'BTC', to: 'BRL' } // null when unsupported
])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: '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')Use @tetherto/wdk-pricing-coingecko-http as another PricingClient when you want CoinGecko as a fallback or primary data source:
import { PricingProvider } from '@tetherto/wdk-pricing-provider'
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
import { CoingeckoPricingClient } from '@tetherto/wdk-pricing-coingecko-http'
const provider = new PricingProvider({
client: [
new BitfinexPricingClient(),
new CoingeckoPricingClient({ apiKey: process.env.COINGECKO_API_KEY })
],
retries: 1
})