Spaces:
Running
Running
Download lib/market-data.js from powerllm/anycoder-cf48624d: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/spaces/powerllm/anycoder-cf48624d/resolve/main/lib/market-data.js
- Command line
-
hf download hf://spaces/powerllm/anycoder-cf48624d/lib/market-data.js
-
curl -L -o market-data.js https://huggingface.co/spaces/powerllm/anycoder-cf48624d/resolve/main/lib/market-data.js
946 Bytes
| const API_BASE = '/api/market-data' | |
| export async function fetchMarketData(symbol = 'bitcoin') { | |
| try { | |
| const response = await fetch(`${API_BASE}?symbol=${symbol}`) | |
| if (!response.ok) { | |
| const errorData = await response.json().catch(() => ({})) | |
| throw new Error(errorData.message || 'Failed to fetch market data') | |
| } | |
| return await response.json() | |
| } catch (error) { | |
| console.error('Market Data Error:', error) | |
| return null | |
| } | |
| } | |
| export function calculateRSI(prices, period = 14) { | |
| if (prices.length < period + 1) return 50 | |
| let gains = 0 | |
| let losses = 0 | |
| for (let i = prices.length - period; i < prices.length; i++) { | |
| const change = prices[i] - prices[i - 1] | |
| if (change > 0) gains += change | |
| else losses += Math.abs(change) | |
| } | |
| const avgGain = gains / period | |
| const avgLoss = losses / period | |
| if (avgLoss === 0) return 100 | |
| const rs = avgGain / avgLoss | |
| return 100 - (100 / (1 + rs)) | |
| } |