-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarketData.js
31 lines (26 loc) · 997 Bytes
/
marketData.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
const fs = require('fs');
const csv = require('csv-parser');
const path = require('path');
async function fetchHistoricalData() {
const directoryPath = path.join(__dirname, 'sol_historical_data');
const files = fs.readdirSync(directoryPath);
const latestFile = files.filter(file => file.startsWith('SOL-USD')).sort().reverse()[0];
return new Promise((resolve, reject) => {
const results = [];
fs.createReadStream(path.join(directoryPath, latestFile))
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
resolve(results);
})
.on('error', (error) => {
console.error('Error reading historical data:', error);
reject([]);
});
});
}
async function fetchLiveData() {
// Placeholder for live data fetching logic
return { price: "Current market price" };
}
module.exports = { fetchHistoricalData, fetchLiveData };