-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataFetcher.js
60 lines (51 loc) · 1.7 KB
/
dataFetcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const config = require('./config.json');
const axios = require('axios');
async function fetchRSIData(token) {
const apiKey = process.env.TAAPI_SECRET;
if (!apiKey) {
console.error('API key is undefined. Check the TAAPI_SECRET environment variable.');
return null;
}
const apiUrl = `https://api.taapi.io/rsi`;
try {
const params = {
secret: apiKey,
exchange: 'binance',
symbol: `${token}/USDT`,
addResultTimestamp: true,
interval: '1h'
};
const response = await axios.get(apiUrl, { params });
// Explicitly check for a successful response
if (response.status === 200) {
// Log response for debugging purposes
console.log(`Response for ${token}:`, response.data);
return response.data; // Assuming the API returns the RSI data directly
} else {
console.error(`Non-successful response for ${token}:`, response.status);
return null;
}
} catch (error) {
// Log more details of the axios error
console.error(`Error fetching RSI for ${token}:`, error.message);
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.error(error.response.data);
console.error(error.response.status);
console.error(error.response.headers);
}
return null;
}
}
async function updateHeatmapData() {
const heatmapData = [];
for (const token of config.tokens) {
const rsiData = await fetchRSIData(token);
if (rsiData) {
heatmapData.push({ token, rsi: rsiData.value });
}
}
return heatmapData; // Return the data instead of logging it.
}
module.exports = { fetchRSIData, updateHeatmapData };