WDK logoWDK documentation

API Reference

API for @tetherto/wdk-pricing-bitfinex-http

Package: @tetherto/wdk-pricing-bitfinex-http

Class: BitfinexPricingClient

Simple HTTP pricing client for Bitfinex Public REST API.

Constructor

Create Client
new BitfinexPricingClient(options?)
  • options (optional): reserved for future use

Methods

MethodDescriptionReturns
getCurrentPrice(base, quote)Fetch latest price for base/quote pairPromise\<number | null\>
getMultiCurrentPrices(pairs)Fetch latest prices for multiple pairs in one batchPromise\<Array\<number | null\>\>
getMultiPriceData(pairs)Fetch last price and 24h change data for multiple directly quoted pairsPromise\<Array\<PriceData | null\>\>
getHistoricalPrice(from, to, opts?)Fetch historical series (downscaled to ≤ 100 points if needed)Promise\<HistoricalPriceResult[]\>
getCurrentPrice(base, quote)

Uses Bitfinex's /calc/fx/batch endpoint. If Bitfinex cannot quote the pair directly, the client tries a two-leg USD pivot. Returns null when the pair cannot be resolved.

Current Price
const price = await client.getCurrentPrice('BTC', 'USD')
const brl = await client.getCurrentPrice('BTC', 'BRL')
getMultiCurrentPrices(pairs)

Returns current prices in the same order as the input pairs. Each unresolved pair returns null.

Batch Current Prices
const prices = await client.getMultiCurrentPrices([
  { from: 'BTC', to: 'USD' },
  { from: 'ETH', to: 'BRL' }
])
getMultiPriceData(pairs)

Returns last price plus 24-hour absolute and relative change. This method reads Bitfinex ticker data and does not use the USD-pivot fallback, so unsupported entries return null.

Batch Price Data
const data = await client.getMultiPriceData([
  { from: 'BTC', to: 'USD' }
])
getHistoricalPrice(from, to, opts?)

If the returned series exceeds 100 points, it is downscaled by powers of two until ≤ 100.

Historical Prices
const series = await client.getHistoricalPrice('BTC', 'USD', {
  start: 1709906400000, // optional
  end:   1709913600000  // optional
})

Package: @tetherto/wdk-pricing-provider

Class: PricingProvider

Cache-aware wrapper providing a unified API over a PricingClient implementation.

Constructor

Create Provider
new PricingProvider({
  client,                 // required: PricingClient or PricingClient[]
  retries,                // optional: number of retry attempts (default 3, only applies when client is an array)
  priceCacheDurationMs    // optional: defaults to 1h
})
  • client (PricingClient | PricingClient[]): a single client instance or an ordered array of client instances. When an array is provided, connection errors trigger automatic failover to the next client in the list.
  • retries (number, optional): number of additional retry attempts after the initial call fails. Total attempts = 1 + retries. When retries exceeds the number of provided clients, the failover loops back in round-robin order. Default: 3. Only applies when client is an array.
  • priceCacheDurationMs (number, optional): cache TTL for last price in ms (default 3,600,000)

Methods

MethodDescriptionReturns
getLastPrice(base, quote)Returns cached last price; refreshes when TTL expiresPromise\<number\>
getMultiLastPrices(pairs)Returns cached last prices for multiple pairsPromise\<number[]\>
getLastPriceData(base, quote)Returns cached last price plus daily change dataPromise\<PriceData\>
getMultiLastPriceData(pairs)Returns cached price data for multiple pairsPromise\<PriceData[]\>
getHistoricalPrice(from, to, opts?)Delegates to client for historical dataPromise\<HistoricalPriceResult[]\>
getLastPrice(base, quote)
Last Price with Caching
const provider = new PricingProvider({ client })
const last = await provider.getLastPrice('BTC', 'USD')
getMultiLastPrices(pairs)
Cached Batch Last Prices
const prices = await provider.getMultiLastPrices([
  { from: 'BTC', to: 'USD' },
  { from: 'ETH', to: 'BRL' }
])
getLastPriceData(base, quote)
Cached Price Data
const data = await provider.getLastPriceData('BTC', 'USD')
console.log(data.lastPrice, data.dailyChange, data.dailyChangeRelative)
getMultiLastPriceData(pairs)
Cached Batch Price Data
const data = await provider.getMultiLastPriceData([
  { from: 'BTC', to: 'USD' }
])
getHistoricalPrice(from, to, opts?)
Historical via Provider
const hist = await provider.getHistoricalPrice('BTC', 'USD', {
  start: 1709906400000,
  end: 1709913600000
})

Interface: PricingClient (abstract)

Implement this interface to plug your data source into PricingProvider.

MethodSignatureNotes
getCurrentPrice(from: string, to: string) =\> Promise\<number | null\>Return spot price or null when the pair cannot be resolved
getMultiCurrentPrices(list: PricePair[]) =\> Promise\<Array\<number | null\>\>Return one result per pair; unresolved entries are null
getMultiPriceData(list: PricePair[]) =\> Promise\<Array\<PriceData | null\>\>Return last price and daily change data; unresolved entries are null
getHistoricalPrice(from: string, to: string, opts?: HistoricalPriceOptions) =\> Promise\<HistoricalPriceResult[]\>Return series for charting

Notes

  • Uses Bitfinex Public HTTP API (/v2/calc/fx/batch, /v2/tickers, and /v2/candles) under the hood for the Bitfinex client
  • Current-price lookups can pivot through USD for fiat pairs Bitfinex does not quote directly; historical prices and getMultiPriceData() do not use that pivot
  • Provider caches last price per pair using in-memory store and TTL

Need Help?

On this page