@pear-protocol/market-sdk 0.3.0 → 0.3.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.
- package/README.md +1 -0
- package/dist/chart/chart.js +1 -1
- package/dist/chart/collector/helpers.js +2 -2
- package/dist/chart/ws/index.js +2 -4
- package/dist/funding-rate/fetcher/index.js +2 -2
- package/dist/orderbook/book/local-book.js +1 -1
- package/dist/orderbook/ws/index.js +2 -4
- package/dist/orderbook/ws/lighter.js +4 -1
- package/dist/transport/index.js +2 -4
- package/dist/transport/lighter.d.ts +2 -0
- package/dist/transport/lighter.js +19 -0
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/chart/chart.js
CHANGED
|
@@ -19,9 +19,9 @@ async function fetchHistoricalCandles(connector, symbol, startTime, endTime, int
|
|
|
19
19
|
case "lighter":
|
|
20
20
|
case "lighter_rhc":
|
|
21
21
|
return fetchHistoricalCandles$1(connector, symbol, startTime, endTime, interval, authToken);
|
|
22
|
-
default:
|
|
23
|
-
throw new Error(`Unsupported connector: ${connector}`);
|
|
24
22
|
}
|
|
23
|
+
const unsupported = connector;
|
|
24
|
+
throw new Error(`Unsupported connector: ${String(unsupported)}`);
|
|
25
25
|
}
|
|
26
26
|
__name(fetchHistoricalCandles, "fetchHistoricalCandles");
|
|
27
27
|
|
package/dist/chart/ws/index.js
CHANGED
|
@@ -20,11 +20,9 @@ function createCandleWs(transport, connector, onCandle) {
|
|
|
20
20
|
case "lighter":
|
|
21
21
|
case "lighter_rhc":
|
|
22
22
|
return new LighterCandleWs(transport, onCandle);
|
|
23
|
-
default: {
|
|
24
|
-
const _exhaustive = connector;
|
|
25
|
-
throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
|
|
26
|
-
}
|
|
27
23
|
}
|
|
24
|
+
const unsupported = connector;
|
|
25
|
+
throw new Error(`Unsupported exchange: ${String(unsupported)}`);
|
|
28
26
|
}
|
|
29
27
|
__name(createCandleWs, "createCandleWs");
|
|
30
28
|
|
|
@@ -19,9 +19,9 @@ async function fetchHistoricalFundingRates(connector, symbol, startTime, endTime
|
|
|
19
19
|
case "lighter":
|
|
20
20
|
case "lighter_rhc":
|
|
21
21
|
return fetchHistoricalFundingRates$1(connector, symbol, startTime, endTime, duration, authToken);
|
|
22
|
-
default:
|
|
23
|
-
throw new Error(`Unsupported connector: ${connector}`);
|
|
24
22
|
}
|
|
23
|
+
const unsupported = connector;
|
|
24
|
+
throw new Error(`Unsupported connector: ${String(unsupported)}`);
|
|
25
25
|
}
|
|
26
26
|
__name(fetchHistoricalFundingRates, "fetchHistoricalFundingRates");
|
|
27
27
|
|
|
@@ -20,11 +20,9 @@ function createDepthWs(transport, connector, onUpdate) {
|
|
|
20
20
|
case "lighter":
|
|
21
21
|
case "lighter_rhc":
|
|
22
22
|
return new LighterDepthWs(transport, onUpdate);
|
|
23
|
-
default: {
|
|
24
|
-
const _exhaustive = connector;
|
|
25
|
-
throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
|
|
26
|
-
}
|
|
27
23
|
}
|
|
24
|
+
const unsupported = connector;
|
|
25
|
+
throw new Error(`Unsupported exchange: ${String(unsupported)}`);
|
|
28
26
|
}
|
|
29
27
|
__name(createDepthWs, "createDepthWs");
|
|
30
28
|
|
|
@@ -59,7 +59,10 @@ class LighterDepthWs extends BaseDepthWs {
|
|
|
59
59
|
const symbol = msg.channel.slice(colonIdx + 1);
|
|
60
60
|
const book = msg.order_book;
|
|
61
61
|
if (!book || book.code !== 0) return null;
|
|
62
|
-
const isSnapshot =
|
|
62
|
+
const isSnapshot = msg.type === "subscribed/order_book";
|
|
63
|
+
if (!isSnapshot && !this.snapshotReceived.get(symbol)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
63
66
|
if (!isSnapshot) {
|
|
64
67
|
const prevNonce = this.lastNonce.get(symbol);
|
|
65
68
|
if (prevNonce !== void 0 && book.begin_nonce !== prevNonce) {
|
package/dist/transport/index.js
CHANGED
|
@@ -20,11 +20,9 @@ function CreateTransport(connector, options) {
|
|
|
20
20
|
case "lighter":
|
|
21
21
|
case "lighter_rhc":
|
|
22
22
|
return new LighterTransport(connector, options?.authToken);
|
|
23
|
-
default: {
|
|
24
|
-
const _exhaustive = connector;
|
|
25
|
-
throw new Error(`Unsupported connector: ${String(_exhaustive)}`);
|
|
26
|
-
}
|
|
27
23
|
}
|
|
24
|
+
const unsupported = connector;
|
|
25
|
+
throw new Error(`Unsupported connector: ${String(unsupported)}`);
|
|
28
26
|
}
|
|
29
27
|
__name(CreateTransport, "CreateTransport");
|
|
30
28
|
|
|
@@ -36,6 +36,8 @@ declare class LighterTransport extends BaseTransport {
|
|
|
36
36
|
protected getPingIntervalMs(): number;
|
|
37
37
|
/** The keep-alive frame the venue expects. */
|
|
38
38
|
protected buildPingMessage(): WsMessage;
|
|
39
|
+
/** Answers the venue's keep-alive ping and surfaces its error frames, which no channel parser reads. */
|
|
40
|
+
private handleControlFrame;
|
|
39
41
|
/** Opens the socket and keeps the token fresh for as long as it stays open. */
|
|
40
42
|
private openSocket;
|
|
41
43
|
/** Re-mints the cached token on a timer, because reconnects resubscribe without warning. */
|
|
@@ -22,6 +22,7 @@ class LighterTransport extends BaseTransport {
|
|
|
22
22
|
super();
|
|
23
23
|
this.connector = connector;
|
|
24
24
|
this.authTokenProvider = authTokenProvider;
|
|
25
|
+
this.addMessageListener((data) => this.handleControlFrame(data));
|
|
25
26
|
}
|
|
26
27
|
/** Holds the socket until a first token lands, so the opening subscriptions carry it. */
|
|
27
28
|
connect() {
|
|
@@ -80,6 +81,24 @@ class LighterTransport extends BaseTransport {
|
|
|
80
81
|
type: "ping"
|
|
81
82
|
};
|
|
82
83
|
}
|
|
84
|
+
/** Answers the venue's keep-alive ping and surfaces its error frames, which no channel parser reads. */
|
|
85
|
+
handleControlFrame(data) {
|
|
86
|
+
let frame;
|
|
87
|
+
try {
|
|
88
|
+
frame = JSON.parse(data);
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (frame.type === "ping") {
|
|
93
|
+
this.send({
|
|
94
|
+
type: "pong"
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (frame.type === void 0 && frame.error !== void 0) {
|
|
99
|
+
console.warn("Lighter stream reported an error", frame.error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
83
102
|
/** Opens the socket and keeps the token fresh for as long as it stays open. */
|
|
84
103
|
openSocket() {
|
|
85
104
|
super.connect();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/market-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Pear Protocol Market SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"build": "tsup",
|
|
24
24
|
"clean": "rm -rf dist .turbo",
|
|
25
25
|
"test": "vitest run",
|
|
26
|
-
"typecheck": "
|
|
26
|
+
"typecheck": "bunx --package bun@1.4.3 bun --check --threads=2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@pear-protocol/types": "^2.
|
|
29
|
+
"@pear-protocol/types": "^2.27.0",
|
|
30
30
|
"bignumber.js": "^9.1.2",
|
|
31
31
|
"partysocket": "^1.0.3"
|
|
32
32
|
},
|