Skip to content

Latest commit

 

History

History
150 lines (84 loc) · 3.18 KB

File metadata and controls

150 lines (84 loc) · 3.18 KB

rates-api v3.0.0


rates-api / src/services/providers/cryptoCompare / CryptoCompare

Class: CryptoCompare

Defined in: src/services/providers/cryptoCompare.ts:28

Singleton class to interact with the CryptoCompare API.

This class provides methods to retrieve cryptocurrency exchange rates and market data from CryptoCompare. It handles API requests, caching, and rate limiting.

Example

import { CryptoCompare } from './cryptocompare';

async function fetchExchangeRates() {
  const cryptoCompare = CryptoCompare.getInstance();
  const rates = await cryptoCompare.getExchangeRates(['BTC', 'ETH']);
  console.log('Exchange Rates:', rates);
}

fetchExchangeRates();

Constructors

Constructor

new CryptoCompare(): CryptoCompare

Defined in: src/services/providers/cryptoCompare.ts:69

Private constructor to enforce the singleton pattern.

Initializes the AxiosWrapper and the LRU cache.

Returns

CryptoCompare

Throws

If an instance already exists.

Methods

getExchangeRates()

getExchangeRates(ids, vsCurrency?): Promise<CryptoComparePrice>

Defined in: src/services/providers/cryptoCompare.ts:163

Retrieves exchange rates for an array of cryptocurrency symbols.

Handles splitting the symbols into batches to comply with API limitations.

Parameters

ids

string[]

An array of cryptocurrency symbols (e.g., ['BTC', 'ETH']).

vsCurrency?

string = 'BTC'

The target currency symbol (default is 'BTC').

Returns

Promise<CryptoComparePrice>

An object mapping cryptocurrency symbols to their exchange rates.

Example

const cryptoCompare = CryptoCompare.getInstance();
const rates = await cryptoCompare.getExchangeRates(['BTC', 'ETH'], 'USD');
console.log('Exchange Rates:', rates);

getMarketData()

getMarketData(ids, vsCurrency?): Promise<CryptoCompareMarkets>

Defined in: src/services/providers/cryptoCompare.ts:226

Retrieves market data for an array of cryptocurrency symbols.

Handles splitting the symbols into batches to comply with API limitations.

Parameters

ids

string[]

An array of cryptocurrency symbols (e.g., ['BTC', 'ETH']).

vsCurrency?

string = 'BTC'

The target currency symbol (default is 'BTC').

Returns

Promise<CryptoCompareMarkets>

An object containing detailed market data.

Example

const cryptoCompare = CryptoCompare.getInstance();
const marketData = await cryptoCompare.getMarketData(['BTC', 'ETH'], 'USD');
console.log('Market Data:', marketData);

getInstance()

static getInstance(): CryptoCompare

Defined in: src/services/providers/cryptoCompare.ts:92

Returns the singleton instance of the CryptoCompare class.

Returns

CryptoCompare

The singleton instance of CryptoCompare.

Example

const cryptoCompare = CryptoCompare.getInstance();