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. In beta.6, all four pricing methods accept common ticker symbols case-insensitively and translate them into Bitfinex codes before making price requests. For example, use USDT for USD₮; the client translates it to UST.
Constructor
Create a client with optional currency-code overrides:
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
const client = new BitfinexPricingClient({
currencyCodes: { btc: 'btc', usd: 'usd' }
})options(BitfinexPricingClientOptions, optional): omit it to use the built-in mappings and remote aliases.options.currencyCodes(Record<string, string>, optional): common-symbol-to-Bitfinex-code mappings, merged over the built-in defaults. Keys and values are uppercased. Explicit mappings take precedence over remote aliases.
See currency-code resolution and fallback behavior for details. The exported BitfinexPricingClientOptions type describes this option.
Methods
| Method | Description | Returns (declared) |
|---|---|---|
getCurrentPrice(base, quote) | Fetch latest price for base/quote pair | Promise\<number | null\> |
getMultiCurrentPrices(pairs) | Fetch latest prices for multiple pairs in one batch | Promise\<Array\<number | null\>\> |
getMultiPriceData(pairs) | Fetch last price and 24h change data for multiple directly quoted pairs | Promise\<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. Returns null when Bitfinex cannot quote the pair directly. The client does not try a two-leg USD pivot.
const price = await client.getCurrentPrice('BTC', 'USD')
const unsupported = await client.getCurrentPrice('BTC', 'BRL') // null when unsupportedgetMultiCurrentPrices(pairs)
Returns current prices in the same order as the input pairs. Each unresolved pair returns null.
const prices = await client.getMultiCurrentPrices([
{ from: 'BTC', to: 'USD' },
{ from: 'ETH', to: 'USD' },
{ from: 'BTC', 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.
const data = await client.getMultiPriceData([
{ from: 'BTC', to: 'USD' }
])getHistoricalPrice(from, to, opts?)
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. If the returned series exceeds 100 points, it is downscaled by powers of two until ≤ 100.
Request the last 24 hours:
const end = Date.now()
const start = end - 24 * 60 * 60 * 1000
const series = await client.getHistoricalPrice('BTC', 'USD', {
start,
end
})The concrete Bitfinex beta.6 implementation returns { price, ts }, with ts in Unix milliseconds. Its inherited HistoricalPriceResult declaration still defines { price, timestamp }. This is a declaration/runtime mismatch: timestamp is not the runtime field returned by this client. Validate or adapt the concrete result before using it through that declared type; PricingProvider forwards the client's historical result without renaming fields.
Package: @tetherto/wdk-pricing-provider
Class: PricingProvider
Cache-aware wrapper providing a unified API over a PricingClient implementation.
Constructor
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. With an array, failures matchingerror instanceof Errorcan trigger failover within theretrieslimit, including application and HTTP errors. A resolvednulldoes not trigger failover.retries(number, optional): number of additional retry attempts after the initial call fails. Total attempts =1 + retries. When the total attempt budget exceeds the number of clients, attempts can wrap in round-robin order. Default:3. Only applies whenclientis an array.priceCacheDurationMs(number, optional): cache TTL for last price in ms (default 3,600,000)
Methods
The table shows the published Provider beta.7 declarations. At runtime, current-price and price-data methods can forward and cache null from a client, including individual null entries in batch results. Handle unavailable values even though the wrapper's declared return types do not include null.
| Method | Description | Returns (declared) |
|---|---|---|
getLastPrice(base, quote) | Returns cached last price; refreshes when TTL expires | Promise\<number\> |
getMultiLastPrices(pairs) | Returns cached last prices for multiple pairs | Promise\<number[]\> |
getLastPriceData(base, quote) | Returns cached last price plus daily change data | Promise\<PriceData\> |
getMultiLastPriceData(pairs) | Returns cached price data for multiple pairs | Promise\<PriceData[]\> |
getHistoricalPrice(from, to, opts?) | Delegates to client for historical data | Promise\<HistoricalPriceResult[]\> |
getLastPrice(base, quote)
const provider = new PricingProvider({ client })
const last = await provider.getLastPrice('BTC', 'USD')getMultiLastPrices(pairs)
const prices = await provider.getMultiLastPrices([
{ from: 'BTC', to: 'USD' },
{ from: 'ETH', to: 'BRL' }
])getLastPriceData(base, quote)
Check for an unavailable result before reading its fields:
const data = await provider.getLastPriceData('BTC', 'USD')
if (data === null) {
console.log('Price data unavailable')
} else {
console.log(data.lastPrice, data.dailyChange, data.dailyChangeRelative)
}getMultiLastPriceData(pairs)
const data = await provider.getMultiLastPriceData([
{ from: 'BTC', to: 'USD' }
])getHistoricalPrice(from, to, opts?)
Request the last 24 hours through the provider. When its client is Bitfinex, the result retains the concrete ts field described above; the wrapper does not convert it to the declared timestamp field.
const end = Date.now()
const start = end - 24 * 60 * 60 * 1000
const hist = await provider.getHistoricalPrice('BTC', 'USD', {
start,
end
})Interface: PricingClient (abstract)
Implement this interface to plug your data source into PricingProvider.
| Method | Signature | Notes |
|---|---|---|
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/tickers/hist) under the hood for the Bitfinex client - Bitfinex lookups support only pairs Bitfinex quotes directly. Unsupported current-price and price-data pairs return
null; unsupported historical pairs return an empty series. - Use
@tetherto/wdk-pricing-coingecko-httpwhen you need a CoinGecko-backedPricingClient - Provider caches last price per pair using in-memory store and TTL