-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (21 loc) · 838 Bytes
/
index.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
import fs from "fs";
import path from "path";
import { tokenToId } from "./config.js";
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
const connection = new PriceServiceConnection("https://hermes.pyth.network");
async function Pyth() {
const marketPricesPyth = {};
try {
const prices = await connection.getLatestPriceFeeds(Object.values(tokenToId));
for (const symbol in tokenToId) {
const index = Object.keys(tokenToId).indexOf(symbol);
const price = prices[index].price.price * 10 ** prices[index].price.expo;
marketPricesPyth[symbol] = price;
// console.log(`Symbol: ${symbol} -- ID: ${tokenToId[symbol]} -- Price: ${price}$`);
}
fs.writeFileSync(path.join("./prices.json"), JSON.stringify(marketPricesPyth, null, 2));
} catch (error) {
console.error(error);
}
}
Pyth();