From aced36c5ec732755f4889d43475eb365e6a9f9e8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 14 Oct 2024 00:08:09 -0700 Subject: send rate from memory --- lib/rates.ts | 4 +++- routes/rates.ts | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rates.ts b/lib/rates.ts index b337d543..0dc3f8aa 100644 --- a/lib/rates.ts +++ b/lib/rates.ts @@ -5,6 +5,7 @@ import { g, s } from "$lib/db"; import { sleep } from "$lib/utils"; import WebSocket from "ws"; +export let rate; let last; let ws; let connect = async () => { @@ -28,7 +29,8 @@ let connect = async () => { (await got("https://api.nobitex.ir/v2/orderbook/BTCIRT").json()) as any ).lastTradePrice; - s("rate", msg.c); + rate = msg.c; + s("rate", rate); s("rates", rates); last = Date.now(); } catch (e) { diff --git a/routes/rates.ts b/routes/rates.ts index f75afc57..e904d438 100644 --- a/routes/rates.ts +++ b/routes/rates.ts @@ -1,13 +1,14 @@ import { g } from "$lib/db"; +import { rate } from "$lib/rates"; export default { async fx(_, res) { let { fx } = await g("fx"); - res.send({fx}); + res.send({ fx }); }, async last(_, res) { - res.send(await g("rate")); + res.send(rate || (await g("rate"))); }, async index(_, res) { -- cgit v1.2.3