aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rates.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:29:04 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:34:42 -0700
commitaa4cd39c943b67169def224e224bd07b815b70ec (patch)
tree2af857ac971705f4d20eb017864f0365d0b57ea6 /lib/rates.ts
parentbc9c04f6519f32d3b444d4df0b276eba960480a9 (diff)
downloadcoinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.tar.gz
coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.zip
biome lint
Diffstat (limited to 'lib/rates.ts')
-rw-r--r--lib/rates.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/rates.ts b/lib/rates.ts
index 0dc3f8aa..1778cdd1 100644
--- a/lib/rates.ts
+++ b/lib/rates.ts
@@ -8,24 +8,24 @@ import WebSocket from "ws";
export let rate;
let last;
let ws;
-let connect = async () => {
+const connect = async () => {
if (ws && ws.readyState === 1 && Date.now() - last < 5000) return;
if (ws) ws.terminate() && (await sleep(Math.round(Math.random() * 1000)));
ws = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@ticker");
- ws.onmessage = async function (event) {
+ ws.onmessage = async (event) => {
try {
- let msg = JSON.parse(event.data);
- let rates = (await g("rates")) || {};
- let { fx } = await g("fx") || {};
+ const msg = JSON.parse(event.data);
+ const rates = (await g("rates")) || {};
+ const { fx } = (await g("fx")) || {};
if (!fx) return;
Object.keys(fx).map((symbol) => {
rates[symbol] = msg.c * fx[symbol];
});
- rates["IRT"] = (
+ rates.IRT = (
(await got("https://api.nobitex.ir/v2/orderbook/BTCIRT").json()) as any
).lastTradePrice;
@@ -39,18 +39,18 @@ let connect = async () => {
}
};
- ws.onerror = async function (error) {
+ ws.onerror = async (error) => {
err("binance socket error", error.message);
};
return ws;
};
-export let getFx = async () => {
+export const getFx = async () => {
connect();
- let date = 0,
- fx = await g("fx");
+ let date = 0;
+ let fx = await g("fx");
if (fx) ({ date, fx } = fx);
if (Date.now() - date > 24 * 60 * 60 * 1000) {
@@ -64,7 +64,7 @@ export let getFx = async () => {
({ fx } = (await got("https://coinos.io/api/fx").json()) as any);
}
- let USD = fx["USD"];
+ const USD = fx.USD;
Object.keys(fx).map((k) => {
fx[k] = fx[k] / USD;