mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Removed ws-heartbeat
This commit is contained in:
61
package-lock.json
generated
61
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.4",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.4",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-signer": "^5.6.0",
|
||||
@@ -15,7 +15,6 @@
|
||||
"bignumber.js": "^9.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"csprng": "^0.1.2",
|
||||
"ethers": "^5.6.2",
|
||||
"isomorphic-ws": "^4.0.1",
|
||||
"just-clone": "^5.0.1",
|
||||
@@ -24,13 +23,11 @@
|
||||
"stream-browserify": "^3.0.0",
|
||||
"tiny-invariant": "^1.2.0",
|
||||
"uuid": "^8.3.2",
|
||||
"websocket-heartbeat-js": "^1.1.0",
|
||||
"ws": "^8.5.0",
|
||||
"zod": "^3.14.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typechain/ethers-v5": "^10.0.0",
|
||||
"@types/csprng": "^0.1.2",
|
||||
"@types/node": "^17.0.23",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/socket.io-client": "1.4.33",
|
||||
@@ -2568,12 +2565,6 @@
|
||||
"@babel/types": "^7.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/csprng": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/csprng/-/csprng-0.1.2.tgz",
|
||||
"integrity": "sha512-QJdNKn4a5JfDcIQLaVjKcVFhm9Es8U8kMOwPYof3TDO5CjLodooAYdGy+pAShgefOwe0bRextBLO5gC0k3Q3Iw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/eslint": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz",
|
||||
@@ -4493,17 +4484,6 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/csprng": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/csprng/-/csprng-0.1.2.tgz",
|
||||
"integrity": "sha1-S8aPEvo2jSUqWYQcusqXSxirReI=",
|
||||
"dependencies": {
|
||||
"sequin": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cssom": {
|
||||
"version": "0.4.4",
|
||||
"dev": true,
|
||||
@@ -9938,14 +9918,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/sequin": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/sequin/-/sequin-0.1.1.tgz",
|
||||
"integrity": "sha1-XC04nWajg3NOqvvEXt6ywcsb5wE=",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/serialize-javascript": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
||||
@@ -10904,11 +10876,6 @@
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/websocket-heartbeat-js": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/websocket-heartbeat-js/-/websocket-heartbeat-js-1.1.0.tgz",
|
||||
"integrity": "sha512-5BSa6e8LUs0I8XrZXPUxAzo5Zmd45s69WmuY+7rNUjhgSzN1YUjFs1QWQJqfuq+JKpAuwp0fdlNNxODZNHGXhA=="
|
||||
},
|
||||
"node_modules/whatwg-encoding": {
|
||||
"version": "1.0.5",
|
||||
"dev": true,
|
||||
@@ -12792,12 +12759,6 @@
|
||||
"@babel/types": "^7.3.0"
|
||||
}
|
||||
},
|
||||
"@types/csprng": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/csprng/-/csprng-0.1.2.tgz",
|
||||
"integrity": "sha512-QJdNKn4a5JfDcIQLaVjKcVFhm9Es8U8kMOwPYof3TDO5CjLodooAYdGy+pAShgefOwe0bRextBLO5gC0k3Q3Iw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/eslint": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz",
|
||||
@@ -14272,14 +14233,6 @@
|
||||
"randomfill": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"csprng": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/csprng/-/csprng-0.1.2.tgz",
|
||||
"integrity": "sha1-S8aPEvo2jSUqWYQcusqXSxirReI=",
|
||||
"requires": {
|
||||
"sequin": "*"
|
||||
}
|
||||
},
|
||||
"cssom": {
|
||||
"version": "0.4.4",
|
||||
"dev": true
|
||||
@@ -18048,11 +18001,6 @@
|
||||
"lru-cache": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"sequin": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/sequin/-/sequin-0.1.1.tgz",
|
||||
"integrity": "sha1-XC04nWajg3NOqvvEXt6ywcsb5wE="
|
||||
},
|
||||
"serialize-javascript": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
||||
@@ -18724,11 +18672,6 @@
|
||||
"integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==",
|
||||
"dev": true
|
||||
},
|
||||
"websocket-heartbeat-js": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/websocket-heartbeat-js/-/websocket-heartbeat-js-1.1.0.tgz",
|
||||
"integrity": "sha512-5BSa6e8LUs0I8XrZXPUxAzo5Zmd45s69WmuY+7rNUjhgSzN1YUjFs1QWQJqfuq+JKpAuwp0fdlNNxODZNHGXhA=="
|
||||
},
|
||||
"whatwg-encoding": {
|
||||
"version": "1.0.5",
|
||||
"dev": true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.4",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
@@ -39,7 +39,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typechain/ethers-v5": "^10.0.0",
|
||||
"@types/csprng": "^0.1.2",
|
||||
"@types/node": "^17.0.23",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/socket.io-client": "1.4.33",
|
||||
@@ -68,7 +67,6 @@
|
||||
"bignumber.js": "^9.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"csprng": "^0.1.2",
|
||||
"ethers": "^5.6.2",
|
||||
"isomorphic-ws": "^4.0.1",
|
||||
"just-clone": "^5.0.1",
|
||||
@@ -77,7 +75,6 @@
|
||||
"stream-browserify": "^3.0.0",
|
||||
"tiny-invariant": "^1.2.0",
|
||||
"uuid": "^8.3.2",
|
||||
"websocket-heartbeat-js": "^1.1.0",
|
||||
"ws": "^8.5.0",
|
||||
"zod": "^3.14.4"
|
||||
},
|
||||
|
||||
@@ -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