mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-17 00:31:34 +03:00
Removed ws-heartbeat
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import WebsocketHeartbeatJs from 'websocket-heartbeat-js';
|
||||
import { z } from 'zod';
|
||||
import WebSocket from 'isomorphic-ws';
|
||||
import tickerInfoSchema from './schemas/tickerInfoSchema';
|
||||
|
||||
const schema = z.array(z.union([
|
||||
@@ -7,17 +7,21 @@ const schema = z.array(z.union([
|
||||
tickerInfoSchema,
|
||||
]));
|
||||
export default class PriceFeedAllTickersWS {
|
||||
private pairsWebSocket: WebsocketHeartbeatJs;
|
||||
private pairsWebSocket: WebSocket;
|
||||
|
||||
constructor(
|
||||
url: string,
|
||||
updateData: (pairs: z.infer<typeof tickerInfoSchema>[]) => void,
|
||||
) {
|
||||
this.pairsWebSocket = new WebsocketHeartbeatJs({ url });
|
||||
this.pairsWebSocket = new WebSocket(url);
|
||||
|
||||
setInterval(() => {
|
||||
this.pairsWebSocket.send('heartbeat');
|
||||
}, 15000);
|
||||
|
||||
this.pairsWebSocket.onmessage = (e) => {
|
||||
if (e.data === 'pong') return;
|
||||
const json = JSON.parse(e.data);
|
||||
const json: unknown = JSON.parse(e.data.toString());
|
||||
const data = schema.parse(json);
|
||||
data.shift(); // Unnecessary timestamp
|
||||
const tickersData = z.array(tickerInfoSchema).parse(data);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import WebsocketHeartbeatJs from 'websocket-heartbeat-js';
|
||||
import WebSocket from 'isomorphic-ws';
|
||||
import { z } from 'zod';
|
||||
|
||||
const schema = z.tuple([
|
||||
@@ -7,18 +7,22 @@ const schema = z.tuple([
|
||||
z.number(), // price
|
||||
]);
|
||||
export default class PriceFeedLastPriceWS {
|
||||
private pairsWebSocket: WebsocketHeartbeatJs;
|
||||
private pairsWebSocket: WebSocket;
|
||||
|
||||
constructor(
|
||||
url: string,
|
||||
pair: string,
|
||||
updateData: (price: number) => void,
|
||||
) {
|
||||
this.pairsWebSocket = new WebsocketHeartbeatJs({ url: url + pair });
|
||||
this.pairsWebSocket = new WebSocket(url + pair);
|
||||
|
||||
setInterval(() => {
|
||||
this.pairsWebSocket.send('heartbeat');
|
||||
}, 15000);
|
||||
|
||||
this.pairsWebSocket.onmessage = (e) => {
|
||||
if (e.data === 'pong') return;
|
||||
const json = JSON.parse(e.data);
|
||||
const json: unknown = JSON.parse(e.data.toString());
|
||||
const [,, price] = schema.parse(json);
|
||||
|
||||
updateData(price);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import WebsocketHeartbeatJs from 'websocket-heartbeat-js';
|
||||
import WebSocket from 'isomorphic-ws';
|
||||
import { z } from 'zod';
|
||||
import tickerInfoSchema from './schemas/tickerInfoSchema';
|
||||
|
||||
@@ -8,20 +8,22 @@ const schema = z.tuple([
|
||||
]);
|
||||
|
||||
export default class PriceFeedTickerWS {
|
||||
priceWebSocket: WebsocketHeartbeatJs;
|
||||
priceWebSocket: WebSocket;
|
||||
|
||||
constructor(
|
||||
symbol: string,
|
||||
url: string,
|
||||
updateData: (pair: z.infer<typeof tickerInfoSchema>) => void,
|
||||
) {
|
||||
this.priceWebSocket = new WebsocketHeartbeatJs({
|
||||
url: `${url}${symbol}`,
|
||||
});
|
||||
this.priceWebSocket = new WebSocket(`${url}${symbol}`);
|
||||
|
||||
setInterval(() => {
|
||||
this.priceWebSocket.send('heartbeat');
|
||||
}, 15000);
|
||||
|
||||
this.priceWebSocket.onmessage = (e) => {
|
||||
if (e.data === 'pong') return;
|
||||
const data = JSON.parse(e.data);
|
||||
const data: unknown = JSON.parse(e.data.toString());
|
||||
const [, tickerData] = schema.parse(data);
|
||||
|
||||
if (tickerData === undefined) return;
|
||||
|
||||
Reference in New Issue
Block a user