token-price-sdk-test
v1.4.0
Published
A lightweight, configurable, cache-enabled React Native library to fetch current and historical cryptocurrency prices. Supports multi-token queries, multiple currencies, caching, mock mode, retry logic, and easy integration using React Hooks.
Readme
React Native Token Price Client
A lightweight, configurable, cache-enabled React Native library to fetch current and historical cryptocurrency prices. Supports multi-token queries, multiple currencies, caching, mock mode, retry logic, and easy integration using React Hooks.
✨ Features
- 🔄 Fetch current and historical prices
- 📦 MMKV or AsyncStorage caching with TTL & manual invalidation
- ⚙️ Multiple instance support via factory clients
- 💡 Mock mode with simulated delays
- 🔁 Retry logic with exponential backoff
- ✅ React Hooks for integration
🔧 Installation
npm install token-price-sdk🎯 Simplified API: createTokenPriceToolkit()
You can initialize everything in one go using the toolkit factory method:
import { createTokenPriceToolkit } from 'your-token-price-lib-name';
const { client, useTokenPrice, useHistoricalPrice, invalidateCacheByTokens } =
createTokenPriceToolkit({
apiBaseUrl: 'https://api.example.com',
currency: 'USD',
cacheTTL: 300,
mockMode: false,
});Advanced API Usage
import { createTokenPriceClient } from 'your-token-price-lib-name';
const client = createTokenPriceClient({
apiBaseUrl: 'https://api.example.com',
cacheTTL: 300, // seconds
currency: 'USD',
mockMode: false,
});
# Fetch current prices
const prices = await client.fetchCurrentPrice(['BTC', 'ETH']);
console.log(prices.BTC.price);
# Fetch historical prices
const history = await client.fetchHistoricalPrice('BTC', 7, 'USD'); // 7-day
# Invalidate cache
client.invalidateCacheByTokens(['BTC', 'ETH']);
# Hooks Usage
import { createUseTokenPrice } from 'your-token-price-lib-name';
const useTokenPrice = createUseTokenPrice(client);
const { prices, loading, error } = useTokenPrice(['BTC', 'ETH']);
import { createUseHistoricalPrice } from 'your-token-price-lib-name';
const useHistoricalPrice = createUseHistoricalPrice(client);
const { data, loading, error } = useHistoricalPrice('BTC', 7);