@pear-protocol/market-sdk 0.0.13 → 0.1.0
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 +27 -0
- package/dist/chart/cache/index.d.ts +1 -1
- package/dist/chart/cache/index.js +15 -3
- package/dist/chart/chart.d.ts +1 -1
- package/dist/chart/chart.js +14 -23
- package/dist/chart/collector/binance.d.ts +1 -1
- package/dist/chart/collector/binance.js +4 -0
- package/dist/chart/collector/bybit.d.ts +1 -1
- package/dist/chart/collector/bybit.js +12 -1
- package/dist/chart/collector/helpers.d.ts +2 -2
- package/dist/chart/collector/helpers.js +5 -2
- package/dist/chart/collector/hyperliquid.d.ts +1 -1
- package/dist/chart/collector/hyperliquid.js +12 -2
- package/dist/chart/collector/index.d.ts +1 -1
- package/dist/chart/collector/index.js +28 -12
- package/dist/chart/collector/lighter.d.ts +2 -2
- package/dist/chart/collector/lighter.js +10 -4
- package/dist/chart/collector/okx.d.ts +1 -1
- package/dist/chart/collector/okx.js +12 -1
- package/dist/chart/compute/asset.d.ts +1 -1
- package/dist/chart/compute/asset.js +4 -0
- package/dist/chart/compute/index.d.ts +1 -1
- package/dist/chart/compute/performance.d.ts +1 -1
- package/dist/chart/compute/performance.js +20 -4
- package/dist/chart/compute/price-ratio.d.ts +1 -1
- package/dist/chart/compute/price-ratio.js +8 -1
- package/dist/chart/compute/weighted-ratio.d.ts +1 -1
- package/dist/chart/compute/weighted-ratio.js +9 -1
- package/dist/chart/types.d.ts +1 -1
- package/dist/chart/utils.d.ts +1 -1
- package/dist/chart/utils.js +19 -11
- package/dist/chart/ws/base-candle.d.ts +11 -5
- package/dist/chart/ws/base-candle.js +6 -2
- package/dist/chart/ws/binance.d.ts +4 -6
- package/dist/chart/ws/binance.js +33 -19
- package/dist/chart/ws/bybit.d.ts +4 -6
- package/dist/chart/ws/bybit.js +40 -24
- package/dist/chart/ws/hyperliquid.d.ts +4 -6
- package/dist/chart/ws/hyperliquid.js +37 -19
- package/dist/chart/ws/index.js +3 -0
- package/dist/chart/ws/lighter.d.ts +20 -20
- package/dist/chart/ws/lighter.js +83 -196
- package/dist/chart/ws/okx.d.ts +4 -6
- package/dist/chart/ws/okx.js +47 -23
- package/dist/funding-rate/fetcher/binance.d.ts +1 -1
- package/dist/funding-rate/fetcher/binance.js +7 -1
- package/dist/funding-rate/fetcher/bybit.d.ts +1 -1
- package/dist/funding-rate/fetcher/bybit.js +15 -13
- package/dist/funding-rate/fetcher/http-client.d.ts +1 -1
- package/dist/funding-rate/fetcher/http-client.js +15 -10
- package/dist/funding-rate/fetcher/hyperliquid.d.ts +1 -1
- package/dist/funding-rate/fetcher/hyperliquid.js +7 -1
- package/dist/funding-rate/fetcher/index.d.ts +2 -2
- package/dist/funding-rate/fetcher/index.js +5 -2
- package/dist/funding-rate/fetcher/lighter.d.ts +2 -2
- package/dist/funding-rate/fetcher/lighter.js +11 -3
- package/dist/funding-rate/fetcher/okx.d.ts +1 -1
- package/dist/funding-rate/fetcher/okx.js +14 -12
- package/dist/funding-rate/funding-rate.d.ts +1 -1
- package/dist/funding-rate/funding-rate.js +30 -21
- package/dist/funding-rate/types.d.ts +1 -1
- package/dist/funding-rate/utils.d.ts +1 -1
- package/dist/funding-rate/utils.js +26 -5
- package/dist/index.d.ts +2 -2
- package/dist/orderbook/book/aggregate.d.ts +1 -1
- package/dist/orderbook/book/aggregate.js +16 -3
- package/dist/orderbook/book/local-book.d.ts +1 -1
- package/dist/orderbook/book/local-book.js +16 -5
- package/dist/orderbook/orderbook.d.ts +1 -1
- package/dist/orderbook/orderbook.js +29 -13
- package/dist/orderbook/types.d.ts +1 -1
- package/dist/orderbook/types.js +7 -1
- package/dist/orderbook/utils.d.ts +1 -1
- package/dist/orderbook/utils.js +5 -0
- package/dist/orderbook/ws/base-depth.js +10 -1
- package/dist/orderbook/ws/binance.js +28 -7
- package/dist/orderbook/ws/bybit.js +20 -5
- package/dist/orderbook/ws/hyperliquid.js +31 -11
- package/dist/orderbook/ws/index.js +3 -0
- package/dist/orderbook/ws/lighter.js +30 -7
- package/dist/orderbook/ws/okx.js +23 -2
- package/dist/shared/types.d.ts +6 -1
- package/dist/transport/base-transport.d.ts +4 -0
- package/dist/transport/base-transport.js +13 -0
- package/dist/transport/binance.js +5 -0
- package/dist/transport/bybit.js +8 -1
- package/dist/transport/hyperliquid.js +8 -1
- package/dist/transport/index.d.ts +11 -3
- package/dist/transport/index.js +5 -2
- package/dist/transport/lighter.d.ts +31 -1
- package/dist/transport/lighter.js +86 -1
- package/dist/transport/okx.js +5 -0
- package/package.json +5 -3
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createCandleLookups, getCompleteTimestamps } from '../utils';
|
|
2
2
|
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
5
|
function computePriceRatioCandles(longTokens, shortTokens, tokenCandles) {
|
|
4
6
|
if (longTokens.length === 0 && shortTokens.length === 0) return [];
|
|
5
7
|
const candleLookups = createCandleLookups(tokenCandles);
|
|
6
|
-
const allSymbols = [
|
|
8
|
+
const allSymbols = [
|
|
9
|
+
...longTokens,
|
|
10
|
+
...shortTokens
|
|
11
|
+
].map((t) => t.symbol);
|
|
7
12
|
const completeTimestamps = getCompleteTimestamps(candleLookups, allSymbols);
|
|
8
13
|
const bars = [];
|
|
9
14
|
for (const timestamp of completeTimestamps) {
|
|
@@ -61,6 +66,7 @@ function computePriceRatioCandles(longTokens, shortTokens, tokenCandles) {
|
|
|
61
66
|
}
|
|
62
67
|
return bars;
|
|
63
68
|
}
|
|
69
|
+
__name(computePriceRatioCandles, "computePriceRatioCandles");
|
|
64
70
|
function computeRealtimePriceRatioBar(longTokens, shortTokens, snapshot) {
|
|
65
71
|
let longSumO = 0;
|
|
66
72
|
let longSumH = 0;
|
|
@@ -103,5 +109,6 @@ function computeRealtimePriceRatioBar(longTokens, shortTokens, snapshot) {
|
|
|
103
109
|
close: longSumC / shortSumC
|
|
104
110
|
};
|
|
105
111
|
}
|
|
112
|
+
__name(computeRealtimePriceRatioBar, "computeRealtimePriceRatioBar");
|
|
106
113
|
|
|
107
114
|
export { computePriceRatioCandles, computeRealtimePriceRatioBar };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TokenSelection, CandleData, Bar } from '../types.js';
|
|
2
2
|
import '../../transport/index.js';
|
|
3
3
|
import '@pear-protocol/types';
|
|
4
|
+
import '../../shared/types.js';
|
|
4
5
|
import '../../transport/base-transport.js';
|
|
5
6
|
import 'partysocket';
|
|
6
|
-
import '../../shared/types.js';
|
|
7
7
|
|
|
8
8
|
declare function computeWeightedRatioCandles(longTokens: TokenSelection[], shortTokens: TokenSelection[], tokenCandles: Record<string, CandleData[]>): Bar[];
|
|
9
9
|
declare function computeRealtimeWeightedRatioBar(longTokens: TokenSelection[], shortTokens: TokenSelection[], snapshot: Record<string, CandleData>): Bar | null;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { createCandleLookups, getCompleteTimestamps } from '../utils';
|
|
2
2
|
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
5
|
function pow(base, exponent) {
|
|
4
6
|
if (base <= 0) return 0;
|
|
5
7
|
return Math.exp(exponent * Math.log(base));
|
|
6
8
|
}
|
|
9
|
+
__name(pow, "pow");
|
|
7
10
|
function computeWeightedRatioCandles(longTokens, shortTokens, tokenCandles) {
|
|
8
11
|
if (longTokens.length === 0 && shortTokens.length === 0) return [];
|
|
9
12
|
const candleLookups = createCandleLookups(tokenCandles);
|
|
10
|
-
const allSymbols = [
|
|
13
|
+
const allSymbols = [
|
|
14
|
+
...longTokens,
|
|
15
|
+
...shortTokens
|
|
16
|
+
].map((t) => t.symbol);
|
|
11
17
|
const completeTimestamps = getCompleteTimestamps(candleLookups, allSymbols);
|
|
12
18
|
const bars = [];
|
|
13
19
|
for (const timestamp of completeTimestamps) {
|
|
@@ -64,6 +70,7 @@ function computeWeightedRatioCandles(longTokens, shortTokens, tokenCandles) {
|
|
|
64
70
|
}
|
|
65
71
|
return bars;
|
|
66
72
|
}
|
|
73
|
+
__name(computeWeightedRatioCandles, "computeWeightedRatioCandles");
|
|
67
74
|
function computeRealtimeWeightedRatioBar(longTokens, shortTokens, snapshot) {
|
|
68
75
|
let longOpen = 1;
|
|
69
76
|
let longHigh = 1;
|
|
@@ -105,5 +112,6 @@ function computeRealtimeWeightedRatioBar(longTokens, shortTokens, snapshot) {
|
|
|
105
112
|
close: longClose * shortClose
|
|
106
113
|
};
|
|
107
114
|
}
|
|
115
|
+
__name(computeRealtimeWeightedRatioBar, "computeRealtimeWeightedRatioBar");
|
|
108
116
|
|
|
109
117
|
export { computeRealtimeWeightedRatioBar, computeWeightedRatioCandles };
|
package/dist/chart/types.d.ts
CHANGED
package/dist/chart/utils.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CandleData, CandleInterval, HistoricalRange } from './types.js';
|
|
2
2
|
import '../transport/index.js';
|
|
3
3
|
import '@pear-protocol/types';
|
|
4
|
+
import '../shared/types.js';
|
|
4
5
|
import '../transport/base-transport.js';
|
|
5
6
|
import 'partysocket';
|
|
6
|
-
import '../shared/types.js';
|
|
7
7
|
|
|
8
8
|
declare const createKey: (symbol: string, interval: CandleInterval) => string;
|
|
9
9
|
declare const getIntervalSeconds: (interval: CandleInterval) => number;
|
package/dist/chart/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const createKey = /* @__PURE__ */ __name((symbol, interval) => `${symbol}-${interval}`, "createKey");
|
|
4
|
+
const getIntervalSeconds = /* @__PURE__ */ __name((interval) => {
|
|
3
5
|
switch (interval) {
|
|
4
6
|
case "1m":
|
|
5
7
|
return 60;
|
|
@@ -30,21 +32,27 @@ const getIntervalSeconds = (interval) => {
|
|
|
30
32
|
case "1M":
|
|
31
33
|
return 30 * 24 * 60 * 60;
|
|
32
34
|
}
|
|
33
|
-
};
|
|
34
|
-
const mergeRanges = (ranges, newRange) => {
|
|
35
|
-
const all = [
|
|
35
|
+
}, "getIntervalSeconds");
|
|
36
|
+
const mergeRanges = /* @__PURE__ */ __name((ranges, newRange) => {
|
|
37
|
+
const all = [
|
|
38
|
+
...ranges,
|
|
39
|
+
newRange
|
|
40
|
+
].sort((a, b) => a.start - b.start);
|
|
36
41
|
const merged = [];
|
|
37
42
|
for (const r of all) {
|
|
38
43
|
const last = merged[merged.length - 1];
|
|
39
44
|
if (merged.length === 0 || !last || r.start > last.end) {
|
|
40
|
-
merged.push({
|
|
45
|
+
merged.push({
|
|
46
|
+
start: r.start,
|
|
47
|
+
end: r.end
|
|
48
|
+
});
|
|
41
49
|
} else {
|
|
42
50
|
last.end = Math.max(last.end, r.end);
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
return merged;
|
|
46
|
-
};
|
|
47
|
-
const createCandleLookups = (tokenCandles) => {
|
|
54
|
+
}, "mergeRanges");
|
|
55
|
+
const createCandleLookups = /* @__PURE__ */ __name((tokenCandles) => {
|
|
48
56
|
const lookups = {};
|
|
49
57
|
for (const [symbol, candles] of Object.entries(tokenCandles)) {
|
|
50
58
|
const lookup = /* @__PURE__ */ new Map();
|
|
@@ -54,8 +62,8 @@ const createCandleLookups = (tokenCandles) => {
|
|
|
54
62
|
lookups[symbol] = lookup;
|
|
55
63
|
}
|
|
56
64
|
return lookups;
|
|
57
|
-
};
|
|
58
|
-
const getCompleteTimestamps = (candleLookups, requiredSymbols) => {
|
|
65
|
+
}, "createCandleLookups");
|
|
66
|
+
const getCompleteTimestamps = /* @__PURE__ */ __name((candleLookups, requiredSymbols) => {
|
|
59
67
|
if (requiredSymbols.length === 0) return [];
|
|
60
68
|
let baseSymbol;
|
|
61
69
|
let baseLookup;
|
|
@@ -86,6 +94,6 @@ const getCompleteTimestamps = (candleLookups, requiredSymbols) => {
|
|
|
86
94
|
}
|
|
87
95
|
result.sort((a, b) => a - b);
|
|
88
96
|
return result;
|
|
89
|
-
};
|
|
97
|
+
}, "getCompleteTimestamps");
|
|
90
98
|
|
|
91
99
|
export { createCandleLookups, createKey, getCompleteTimestamps, getIntervalSeconds, mergeRanges };
|
|
@@ -6,6 +6,10 @@ import 'partysocket';
|
|
|
6
6
|
import '../../transport/index.js';
|
|
7
7
|
|
|
8
8
|
type CandleHandler = (symbol: string, candle: CandleData) => void;
|
|
9
|
+
type ParsedCandle = {
|
|
10
|
+
symbol: string;
|
|
11
|
+
candle: CandleData;
|
|
12
|
+
};
|
|
9
13
|
declare abstract class BaseCandleWs {
|
|
10
14
|
protected transport: BaseTransport;
|
|
11
15
|
protected onCandle: CandleHandler;
|
|
@@ -14,10 +18,12 @@ declare abstract class BaseCandleWs {
|
|
|
14
18
|
private subscribedKeys;
|
|
15
19
|
protected abstract buildSubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
16
20
|
protected abstract buildUnsubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* One venue message can carry several candles: on rollover Lighter sends the just-closed period
|
|
23
|
+
* alongside the freshly opened one, and dropping the closed one would leave that bar missing its
|
|
24
|
+
* final trades. Venues that only ever send one candle return a single-element array.
|
|
25
|
+
*/
|
|
26
|
+
protected abstract parseMessages(data: string): ParsedCandle[];
|
|
21
27
|
constructor(transport: BaseTransport, onCandle: CandleHandler);
|
|
22
28
|
start(): void;
|
|
23
29
|
stop(): void;
|
|
@@ -27,4 +33,4 @@ declare abstract class BaseCandleWs {
|
|
|
27
33
|
unsubscribe(symbol: string, interval: CandleInterval): void;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
export { BaseCandleWs, type CandleHandler };
|
|
36
|
+
export { BaseCandleWs, type CandleHandler, type ParsedCandle };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
3
|
class BaseCandleWs {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "BaseCandleWs");
|
|
6
|
+
}
|
|
2
7
|
transport;
|
|
3
8
|
onCandle;
|
|
4
9
|
messageListenerId = null;
|
|
@@ -11,8 +16,7 @@ class BaseCandleWs {
|
|
|
11
16
|
start() {
|
|
12
17
|
if (this.messageListenerId) return;
|
|
13
18
|
this.messageListenerId = this.transport.addMessageListener((data) => {
|
|
14
|
-
const result
|
|
15
|
-
if (result) {
|
|
19
|
+
for (const result of this.parseMessages(data)) {
|
|
16
20
|
this.onCandle(result.symbol, result.candle);
|
|
17
21
|
}
|
|
18
22
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WsMessage } from '../../shared/types.js';
|
|
2
|
-
import { CandleInterval
|
|
3
|
-
import { BaseCandleWs } from './base-candle.js';
|
|
2
|
+
import { CandleInterval } from '../types.js';
|
|
3
|
+
import { BaseCandleWs, ParsedCandle } from './base-candle.js';
|
|
4
4
|
import '../../transport/index.js';
|
|
5
5
|
import '@pear-protocol/types';
|
|
6
6
|
import '../../transport/base-transport.js';
|
|
@@ -10,10 +10,8 @@ declare class BinanceCandleWs extends BaseCandleWs {
|
|
|
10
10
|
private idCounter;
|
|
11
11
|
protected buildSubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
12
12
|
protected buildUnsubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
candle: CandleData;
|
|
16
|
-
} | null;
|
|
13
|
+
/** Translates one Binance kline frame into a single-candle batch. */
|
|
14
|
+
protected parseMessages(data: string): ParsedCandle[];
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export { BinanceCandleWs };
|
package/dist/chart/ws/binance.js
CHANGED
|
@@ -1,42 +1,56 @@
|
|
|
1
1
|
import { BaseCandleWs } from './base-candle';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const toStreamName = /* @__PURE__ */ __name((symbol, interval) => `${symbol.toLowerCase()}@kline_${interval}`, "toStreamName");
|
|
4
6
|
class BinanceCandleWs extends BaseCandleWs {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "BinanceCandleWs");
|
|
9
|
+
}
|
|
5
10
|
idCounter = 1;
|
|
6
11
|
buildSubscribeMessage(symbol, interval) {
|
|
7
12
|
return {
|
|
8
13
|
method: "SUBSCRIBE",
|
|
9
|
-
params: [
|
|
14
|
+
params: [
|
|
15
|
+
toStreamName(symbol, interval)
|
|
16
|
+
],
|
|
10
17
|
id: this.idCounter++
|
|
11
18
|
};
|
|
12
19
|
}
|
|
13
20
|
buildUnsubscribeMessage(symbol, interval) {
|
|
14
21
|
return {
|
|
15
22
|
method: "UNSUBSCRIBE",
|
|
16
|
-
params: [
|
|
23
|
+
params: [
|
|
24
|
+
toStreamName(symbol, interval)
|
|
25
|
+
],
|
|
17
26
|
id: this.idCounter++
|
|
18
27
|
};
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
/** Translates one Binance kline frame into a single-candle batch. */
|
|
30
|
+
parseMessages(data) {
|
|
31
|
+
let message;
|
|
22
32
|
try {
|
|
23
|
-
|
|
33
|
+
message = JSON.parse(data);
|
|
24
34
|
} catch {
|
|
25
|
-
return
|
|
35
|
+
return [];
|
|
26
36
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (message.e !== "kline" || !message.k) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const kline = message.k;
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
symbol: kline.s,
|
|
44
|
+
candle: {
|
|
45
|
+
t: kline.t,
|
|
46
|
+
T: kline.T,
|
|
47
|
+
o: Number(kline.o),
|
|
48
|
+
h: Number(kline.h),
|
|
49
|
+
l: Number(kline.l),
|
|
50
|
+
c: Number(kline.c)
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
|
-
|
|
53
|
+
];
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
|
package/dist/chart/ws/bybit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WsMessage } from '../../shared/types.js';
|
|
2
|
-
import { CandleInterval
|
|
3
|
-
import { BaseCandleWs } from './base-candle.js';
|
|
2
|
+
import { CandleInterval } from '../types.js';
|
|
3
|
+
import { BaseCandleWs, ParsedCandle } from './base-candle.js';
|
|
4
4
|
import '../../transport/index.js';
|
|
5
5
|
import '@pear-protocol/types';
|
|
6
6
|
import '../../transport/base-transport.js';
|
|
@@ -9,10 +9,8 @@ import 'partysocket';
|
|
|
9
9
|
declare class BybitCandleWs extends BaseCandleWs {
|
|
10
10
|
protected buildSubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
11
11
|
protected buildUnsubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
candle: CandleData;
|
|
15
|
-
} | null;
|
|
12
|
+
/** Translates one Bybit kline frame into a single-candle batch. */
|
|
13
|
+
protected parseMessages(data: string): ParsedCandle[];
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
export { BybitCandleWs };
|
package/dist/chart/ws/bybit.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BaseCandleWs } from './base-candle';
|
|
2
2
|
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
5
|
const intervalMap = {
|
|
4
6
|
"1m": "1",
|
|
5
7
|
"3m": "3",
|
|
@@ -16,47 +18,61 @@ const intervalMap = {
|
|
|
16
18
|
"1w": "W",
|
|
17
19
|
"1M": "M"
|
|
18
20
|
};
|
|
19
|
-
const toTopic = (symbol, interval) => `kline.${intervalMap[interval]}.${symbol}
|
|
20
|
-
const fromTopic = (topic) => {
|
|
21
|
+
const toTopic = /* @__PURE__ */ __name((symbol, interval) => `kline.${intervalMap[interval]}.${symbol}`, "toTopic");
|
|
22
|
+
const fromTopic = /* @__PURE__ */ __name((topic) => {
|
|
21
23
|
const parts = topic.split(".");
|
|
22
24
|
return parts[2] ?? "";
|
|
23
|
-
};
|
|
25
|
+
}, "fromTopic");
|
|
24
26
|
class BybitCandleWs extends BaseCandleWs {
|
|
27
|
+
static {
|
|
28
|
+
__name(this, "BybitCandleWs");
|
|
29
|
+
}
|
|
25
30
|
buildSubscribeMessage(symbol, interval) {
|
|
26
31
|
return {
|
|
27
32
|
op: "subscribe",
|
|
28
|
-
args: [
|
|
33
|
+
args: [
|
|
34
|
+
toTopic(symbol, interval)
|
|
35
|
+
]
|
|
29
36
|
};
|
|
30
37
|
}
|
|
31
38
|
buildUnsubscribeMessage(symbol, interval) {
|
|
32
39
|
return {
|
|
33
40
|
op: "unsubscribe",
|
|
34
|
-
args: [
|
|
41
|
+
args: [
|
|
42
|
+
toTopic(symbol, interval)
|
|
43
|
+
]
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
/** Translates one Bybit kline frame into a single-candle batch. */
|
|
47
|
+
parseMessages(data) {
|
|
48
|
+
let message;
|
|
39
49
|
try {
|
|
40
|
-
|
|
50
|
+
message = JSON.parse(data);
|
|
41
51
|
} catch {
|
|
42
|
-
return
|
|
52
|
+
return [];
|
|
43
53
|
}
|
|
44
|
-
const topic =
|
|
45
|
-
const
|
|
46
|
-
if (!topic || !
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const topic = message.topic;
|
|
55
|
+
const klines = message.data;
|
|
56
|
+
if (!topic || !klines || !Array.isArray(klines) || klines.length === 0) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
if (!topic.startsWith("kline.")) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const kline = klines[0];
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
symbol: fromTopic(topic),
|
|
66
|
+
candle: {
|
|
67
|
+
t: kline.start,
|
|
68
|
+
T: kline.end,
|
|
69
|
+
o: Number(kline.open),
|
|
70
|
+
h: Number(kline.high),
|
|
71
|
+
l: Number(kline.low),
|
|
72
|
+
c: Number(kline.close)
|
|
73
|
+
}
|
|
58
74
|
}
|
|
59
|
-
|
|
75
|
+
];
|
|
60
76
|
}
|
|
61
77
|
}
|
|
62
78
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WsMessage } from '../../shared/types.js';
|
|
2
|
-
import { CandleInterval
|
|
3
|
-
import { BaseCandleWs } from './base-candle.js';
|
|
2
|
+
import { CandleInterval } from '../types.js';
|
|
3
|
+
import { BaseCandleWs, ParsedCandle } from './base-candle.js';
|
|
4
4
|
import '../../transport/index.js';
|
|
5
5
|
import '@pear-protocol/types';
|
|
6
6
|
import '../../transport/base-transport.js';
|
|
@@ -22,10 +22,8 @@ interface HyperliquidUnsubscribeMessage extends WsMessage {
|
|
|
22
22
|
declare class HyperliquidCandleWs extends BaseCandleWs {
|
|
23
23
|
protected buildSubscribeMessage(symbol: string, interval: CandleInterval): HyperliquidSubscribeMessage;
|
|
24
24
|
protected buildUnsubscribeMessage(symbol: string, interval: CandleInterval): HyperliquidUnsubscribeMessage;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
candle: CandleData;
|
|
28
|
-
} | null;
|
|
25
|
+
/** Translates one Hyperliquid candle frame into a single-candle batch. */
|
|
26
|
+
protected parseMessages(data: string): ParsedCandle[];
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export { HyperliquidCandleWs };
|
|
@@ -1,39 +1,57 @@
|
|
|
1
1
|
import { BaseCandleWs } from './base-candle';
|
|
2
2
|
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
5
|
class HyperliquidCandleWs extends BaseCandleWs {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "HyperliquidCandleWs");
|
|
8
|
+
}
|
|
4
9
|
buildSubscribeMessage(symbol, interval) {
|
|
5
10
|
return {
|
|
6
11
|
method: "subscribe",
|
|
7
|
-
subscription: {
|
|
12
|
+
subscription: {
|
|
13
|
+
type: "candle",
|
|
14
|
+
coin: symbol,
|
|
15
|
+
interval
|
|
16
|
+
}
|
|
8
17
|
};
|
|
9
18
|
}
|
|
10
19
|
buildUnsubscribeMessage(symbol, interval) {
|
|
11
20
|
return {
|
|
12
21
|
method: "unsubscribe",
|
|
13
|
-
subscription: {
|
|
22
|
+
subscription: {
|
|
23
|
+
type: "candle",
|
|
24
|
+
coin: symbol,
|
|
25
|
+
interval
|
|
26
|
+
}
|
|
14
27
|
};
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
/** Translates one Hyperliquid candle frame into a single-candle batch. */
|
|
30
|
+
parseMessages(data) {
|
|
31
|
+
let message;
|
|
18
32
|
try {
|
|
19
|
-
|
|
33
|
+
message = JSON.parse(data);
|
|
20
34
|
} catch {
|
|
21
|
-
return
|
|
35
|
+
return [];
|
|
22
36
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
if (message.channel !== "candle" || !message.data) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const payload = message.data;
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
symbol: payload.s,
|
|
44
|
+
candle: {
|
|
45
|
+
s: payload.s,
|
|
46
|
+
t: payload.t,
|
|
47
|
+
T: payload.T,
|
|
48
|
+
o: Number(payload.o),
|
|
49
|
+
h: Number(payload.h),
|
|
50
|
+
l: Number(payload.l),
|
|
51
|
+
c: Number(payload.c)
|
|
52
|
+
}
|
|
35
53
|
}
|
|
36
|
-
|
|
54
|
+
];
|
|
37
55
|
}
|
|
38
56
|
}
|
|
39
57
|
|
package/dist/chart/ws/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { HyperliquidCandleWs } from './hyperliquid';
|
|
|
5
5
|
import { LighterCandleWs } from './lighter';
|
|
6
6
|
import { OkxCandleWs } from './okx';
|
|
7
7
|
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
10
|
function createCandleWs(transport, connector, onCandle) {
|
|
9
11
|
switch (connector) {
|
|
10
12
|
case "hyperliquid":
|
|
@@ -23,5 +25,6 @@ function createCandleWs(transport, connector, onCandle) {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
28
|
+
__name(createCandleWs, "createCandleWs");
|
|
26
29
|
|
|
27
30
|
export { createCandleWs };
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { WsMessage } from '../../shared/types.js';
|
|
2
|
-
import { CandleInterval
|
|
3
|
-
import { BaseCandleWs } from './base-candle.js';
|
|
2
|
+
import { CandleInterval } from '../types.js';
|
|
3
|
+
import { BaseCandleWs, ParsedCandle } from './base-candle.js';
|
|
4
4
|
import '../../transport/index.js';
|
|
5
5
|
import '@pear-protocol/types';
|
|
6
6
|
import '../../transport/base-transport.js';
|
|
7
7
|
import 'partysocket';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Lighter publishes ready-made OHLC candles on a dedicated channel, so this class only translates
|
|
11
|
+
* them onto CandleData — it never aggregates the trade tape and never seeds itself over REST, because
|
|
12
|
+
* the subscribe acknowledgement already carries the current live candle.
|
|
13
|
+
* Docs: https://apidocs.lighter.xyz/docs/websocket-reference#candlesticks
|
|
14
|
+
*/
|
|
15
|
+
|
|
9
16
|
declare class LighterCandleWs extends BaseCandleWs {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
stop(): void;
|
|
22
|
-
subscribe(symbol: string, interval: CandleInterval): void;
|
|
23
|
-
unsubscribe(symbol: string, interval: CandleInterval): void;
|
|
24
|
-
onHistoricalDataFetched(symbol: string, interval: CandleInterval, candles: CandleData[]): void;
|
|
25
|
-
private applyCandleState;
|
|
26
|
-
private seedFromHistory;
|
|
27
|
-
private handleTradeMessage;
|
|
17
|
+
/** Subscribes to a market's candle stream; `symbol` is Lighter's numeric market id. */
|
|
18
|
+
protected buildSubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
19
|
+
/** Mirrors the subscribe channel — Lighter keys unsubscribes by the same slash-delimited name. */
|
|
20
|
+
protected buildUnsubscribeMessage(symbol: string, interval: CandleInterval): WsMessage;
|
|
21
|
+
/**
|
|
22
|
+
* Translates one candle message into CandleData, oldest first.
|
|
23
|
+
*
|
|
24
|
+
* Lighter batches updates every 500ms and, when a period rolls over, sends the just-closed candle
|
|
25
|
+
* followed by the newly opened one — both are emitted so the closed bar keeps its final trades.
|
|
26
|
+
*/
|
|
27
|
+
protected parseMessages(data: string): ParsedCandle[];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export { LighterCandleWs };
|