Skip to content

Commit

Permalink
Add price-fetch module
Browse files Browse the repository at this point in the history
  • Loading branch information
nobita851 committed Dec 1, 2024
1 parent f91e0d1 commit 50221e3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions operator/price.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const http = require('http');

const getPrice = (symbol) => {
console.log('Getting price for', symbol);
const req = http.request({
hostname: 'data-api.binance.vision',
path: '/api/v3/ticker/price?symbol=' + symbol,
method: 'GET'
}, (res) => {
let data = '';

res.on('data', (chunk) => {
data += chunk;
});

res.on('end', () => {
try {
const parsedData = JSON.parse(data);
console.log('Price received:', parsedData.price);
resolve(parsedData.price);
} catch (e) {
reject(`Error parsing JSON: ${e.message}`);
}
});
});

req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});

req.end();
}

module.exports = { getPrice };

0 comments on commit 50221e3

Please sign in to comment.