@cygnus-wealth/asset-valuator
Version:
Asset valuation library for retrieving and converting cryptocurrency prices
35 lines (34 loc) • 985 B
JavaScript
const DETERMINISTIC_PRICES = {
BTC: 40000,
ETH: 2000,
SOL: 100,
USDC: 1,
USDT: 1,
};
export class TestPriceProvider {
async fetchPrice(symbol, currency = 'usd') {
const normalizedSymbol = symbol.toUpperCase();
const price = DETERMINISTIC_PRICES[normalizedSymbol];
if (price === undefined) {
throw new Error(`TestPriceProvider: no deterministic price for ${normalizedSymbol}`);
}
return {
symbol: normalizedSymbol,
price,
timestamp: new Date(),
};
}
async fetchMultiplePrices(symbols, currency = 'usd') {
const results = [];
for (const symbol of symbols) {
try {
const priceData = await this.fetchPrice(symbol, currency);
results.push(priceData);
}
catch {
// Skip symbols without deterministic prices
}
}
return results;
}
}