diff options
| author | Adam Soltys <[email protected]> | 2024-10-14 00:08:09 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-14 00:08:09 -0700 |
| commit | aced36c5ec732755f4889d43475eb365e6a9f9e8 (patch) | |
| tree | 6be792469a6c578615401e6f79ff27a5476b8b51 | |
| parent | afbef8dd8dac9e1e71415914f2ecab7ce85f1fa5 (diff) | |
| download | coinos-server-aced36c5ec732755f4889d43475eb365e6a9f9e8.tar.gz coinos-server-aced36c5ec732755f4889d43475eb365e6a9f9e8.zip | |
send rate from memory
| -rw-r--r-- | lib/rates.ts | 4 | ||||
| -rw-r--r-- | 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) { |
