@pear-protocol/market-sdk 0.0.1-preview.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,9 +42,9 @@ class LocalBook {
42
42
  bbo() {
43
43
  const bestBid = this._bids[0] ? new BigNumber(this._bids[0][0]) : null;
44
44
  const bestAsk = this._asks[0] ? new BigNumber(this._asks[0][0]) : null;
45
- const spread = bestBid !== null && bestAsk !== null ? bestAsk.minus(bestBid) : null;
46
- const midPrice = bestBid !== null && bestAsk !== null ? bestAsk.plus(bestBid).div(2) : null;
47
- const spreadPct = spread !== null && midPrice !== null && !midPrice.isZero() ? spread.div(midPrice).times(100) : null;
45
+ const spread = bestBid && bestAsk ? bestAsk.minus(bestBid) : null;
46
+ const midPrice = bestBid && bestAsk ? bestAsk.plus(bestBid).div(2) : null;
47
+ const spreadPct = spread && midPrice && !midPrice.isZero() ? spread.div(midPrice).times(100) : null;
48
48
  return {
49
49
  bestBid: bestBid?.toFixed() ?? null,
50
50
  bestAsk: bestAsk?.toFixed() ?? null,
@@ -21,6 +21,7 @@ class BinanceDepthWs extends BaseDepthWs {
21
21
  };
22
22
  }
23
23
  subscribe(symbol) {
24
+ if (this.symbolStates.has(symbol)) return;
24
25
  this.symbolStates.set(symbol, { phase: "buffering", buffer: [] });
25
26
  super.subscribe(symbol);
26
27
  this.bootstrap(symbol);
@@ -104,7 +105,8 @@ class BinanceDepthWs extends BaseDepthWs {
104
105
  let msg;
105
106
  try {
106
107
  msg = JSON.parse(data);
107
- } catch {
108
+ } catch (err) {
109
+ console.error("Failed to parse Binance diff message:", data, err);
108
110
  return null;
109
111
  }
110
112
  if (msg.e !== "depthUpdate") return null;
@@ -16,7 +16,8 @@ class BybitDepthWs extends BaseDepthWs {
16
16
  let msg;
17
17
  try {
18
18
  msg = JSON.parse(data);
19
- } catch {
19
+ } catch (err) {
20
+ console.error("Failed to parse Bybit depth message:", data, err);
20
21
  return null;
21
22
  }
22
23
  const topic = msg.topic;
@@ -68,7 +68,8 @@ class HyperliquidDepthWs extends BaseDepthWs {
68
68
  let msg;
69
69
  try {
70
70
  msg = JSON.parse(data);
71
- } catch {
71
+ } catch (err) {
72
+ console.error("Failed to parse Hyperliquid depth message:", data, err);
72
73
  return null;
73
74
  }
74
75
  if (msg.channel !== "l2Book" || !msg.data) return null;
@@ -12,7 +12,8 @@ class OkxDepthWs extends BaseDepthWs {
12
12
  let msg;
13
13
  try {
14
14
  msg = JSON.parse(data);
15
- } catch {
15
+ } catch (err) {
16
+ console.error("Failed to parse OKX depth message:", data, err);
16
17
  return null;
17
18
  }
18
19
  if (!msg.arg || msg.arg.channel !== "books") return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/market-sdk",
3
- "version": "0.0.1-preview.0",
3
+ "version": "0.0.2",
4
4
  "description": "Pear Protocol Market SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -25,12 +25,12 @@
25
25
  "typecheck": "tsc --noEmit"
26
26
  },
27
27
  "dependencies": {
28
- "@pear-protocol/types": "0.0.12",
28
+ "@pear-protocol/types": "0.0.13",
29
29
  "bignumber.js": "^9.1.2",
30
30
  "partysocket": "^1.0.3"
31
31
  },
32
32
  "devDependencies": {
33
- "@backend/typescript-config": "0.0.0",
33
+ "@backend/typescript-config": "workspace:*",
34
34
  "tsup": "8.5.1",
35
35
  "typescript": "5.9.3"
36
36
  }