WDK logoWDK documentation

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:

Create Client
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:

Set Currency-Code Overrides
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.

Get Current Price
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.

Get Batch Current Prices
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.

Get Batch Price Data
const priceData = await client.getMultiPriceData([
  { from: 'BTC', to: 'USD' }
])

Historical Series

Supply start and end as Unix timestamps in milliseconds; both fields are required by HistoricalPriceOptions. Keep start within the trailing 365 days to avoid the client's range error. Long histories are downscaled to ≤ 100 points. This example requests the last 24 hours:

Get Historical Prices
const end = Date.now()
const start = end - 24 * 60 * 60 * 1000
const series = await client.getHistoricalPrice('BTC', 'USD', {
  start,
  end
})

The concrete Bitfinex result uses { price, ts }, with ts in Unix milliseconds. The inherited HistoricalPriceResult declaration instead names the time field timestamp; this is a declaration/runtime mismatch. See the historical API notes before consuming the series in TypeScript.

Provider Integration

Works with @tetherto/wdk-pricing-provider as a PricingClient implementation.

You can pass a single client or an array of clients. With an array, failures matching error instanceof Error trigger failover within the configured retries limit, including application and HTTP errors. A resolved null does not trigger failover.

Single client
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 end = Date.now()
const start = end - 24 * 60 * 60 * 1000
const hist = await provider.getHistoricalPrice('BTC', 'USD', {
  start,
  end
})

To enable failover, pass an ordered array of PricingClient instances. The provider advances through that array when a failure matches error instanceof Error, up to the retries limit.

Failover across multiple clients
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:

CoinGecko fallback client
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
})

Need Help?

On this page