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
new BitfinexPricingClient(options?)options(optional): reserved for future use
Methods
| Method | Description | Returns |
|---|---|---|
getCurrentPrice(base, quote) | Fetch latest price for base/quote pair | Promise\<number\> |
getHistoricalPrice(from, to, opts?) | Fetch historical series (downscaled to ≤ 100 points if needed) | Promise\<HistoricalPriceResult[]\> |
getCurrentPrice(base, quote)
const price = await client.getCurrentPrice('BTC', 'USD')getHistoricalPrice(from, to, opts?)
If the returned series exceeds 100 points, it is downscaled by powers of two until ≤ 100.
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
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. Whenretriesexceeds the number of provided clients, the failover loops back 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
| Method | Description | Returns |
|---|---|---|
getLastPrice(base, quote) | Returns cached last price; refreshes when TTL expires | Promise\<number\> |
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')getHistoricalPrice(from, to, opts?)
const hist = await provider.getHistoricalPrice('BTC', 'USD', {
start: 1709906400000,
end: 1709913600000
})Interface: PricingClient (abstract)
Implement this interface to plug your data source into PricingProvider.
| Method | Signature | Notes |
|---|---|---|
getCurrentPrice | (from: string, to: string) =\> Promise\<number\> | Should return spot price |
getHistoricalPrice | (from: string, to: string, opts?: HistoricalPriceOptions) =\> Promise\<HistoricalPriceResult[]\> | Return series for charting |
Notes
- Uses Bitfinex Public HTTP API (
/v2/tickerand/v2/candles) under the hood for the Bitfinex client - Provider caches last price per pair using in-memory store and TTL