@pear-protocol/symmio-client 0.2.28 → 0.2.29
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/dist/react/index.js +56 -24
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +56 -24
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +27 -10
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +27 -10
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function toBinanceSymbol(symmSymbol) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// src/utils/binance-ws.ts
|
|
74
|
-
var BINANCE_WS_URL = "wss://fstream.binance.com/ws";
|
|
74
|
+
var BINANCE_WS_URL = "wss://fstream.binance.com/market/ws";
|
|
75
75
|
var RECONNECT_DELAYS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
76
76
|
var STABLE_QUOTES = ["USDT0", "USDT", "USDC", "USDE", "USDH", "USD"];
|
|
77
77
|
function normalizeBaseSymbol(symbol) {
|
|
@@ -101,6 +101,22 @@ function extractTickers(payload) {
|
|
|
101
101
|
}
|
|
102
102
|
return [];
|
|
103
103
|
}
|
|
104
|
+
function extractWsPayload(payload) {
|
|
105
|
+
if (payload && typeof payload === "object" && "data" in payload) {
|
|
106
|
+
return payload.data ?? payload;
|
|
107
|
+
}
|
|
108
|
+
return payload;
|
|
109
|
+
}
|
|
110
|
+
function isKlinePayload(payload) {
|
|
111
|
+
return Boolean(
|
|
112
|
+
payload && typeof payload === "object" && payload.e === "kline" && typeof payload.s === "string" && payload.k && typeof payload.k.i === "string"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
function isMarkPricePayload(payload) {
|
|
116
|
+
return Boolean(
|
|
117
|
+
payload && typeof payload === "object" && payload.e === "markPriceUpdate" && typeof payload.s === "string"
|
|
118
|
+
);
|
|
119
|
+
}
|
|
104
120
|
var BinanceWsManager = class {
|
|
105
121
|
ws = null;
|
|
106
122
|
streams = /* @__PURE__ */ new Map();
|
|
@@ -254,17 +270,18 @@ var BinanceWsManager = class {
|
|
|
254
270
|
};
|
|
255
271
|
}
|
|
256
272
|
handleMessage(data) {
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
const payload = extractWsPayload(data);
|
|
274
|
+
if (Array.isArray(payload)) {
|
|
275
|
+
this.dispatchToStream("!markPrice@arr@1s", payload);
|
|
259
276
|
return;
|
|
260
277
|
}
|
|
261
|
-
if (
|
|
262
|
-
const k =
|
|
263
|
-
const streamName = `${
|
|
264
|
-
this.dispatchToStream(streamName,
|
|
265
|
-
} else if (
|
|
266
|
-
const streamName = `${
|
|
267
|
-
this.dispatchToStream(streamName,
|
|
278
|
+
if (isKlinePayload(payload)) {
|
|
279
|
+
const k = payload.k;
|
|
280
|
+
const streamName = `${payload.s.toLowerCase()}@kline_${k.i}`;
|
|
281
|
+
this.dispatchToStream(streamName, payload);
|
|
282
|
+
} else if (isMarkPricePayload(payload)) {
|
|
283
|
+
const streamName = `${payload.s.toLowerCase()}@markPrice@1s`;
|
|
284
|
+
this.dispatchToStream(streamName, payload);
|
|
268
285
|
}
|
|
269
286
|
}
|
|
270
287
|
dispatchToStream(streamName, data) {
|
|
@@ -25437,7 +25454,7 @@ function useSymmHedgerMarkets(params) {
|
|
|
25437
25454
|
|
|
25438
25455
|
// src/utils/binance-api.ts
|
|
25439
25456
|
var BINANCE_FAPI_BASE = "https://fapi.binance.com";
|
|
25440
|
-
async function
|
|
25457
|
+
async function fetchKlines(symbol, interval, startTime, endTime, limit = 1500) {
|
|
25441
25458
|
const params = new URLSearchParams({
|
|
25442
25459
|
symbol,
|
|
25443
25460
|
interval,
|
|
@@ -25445,9 +25462,9 @@ async function fetchMarkPriceKlines(symbol, interval, startTime, endTime, limit
|
|
|
25445
25462
|
endTime: String(endTime),
|
|
25446
25463
|
limit: String(Math.min(limit, 1500))
|
|
25447
25464
|
});
|
|
25448
|
-
const response = await fetch(`${BINANCE_FAPI_BASE}/fapi/v1/
|
|
25465
|
+
const response = await fetch(`${BINANCE_FAPI_BASE}/fapi/v1/klines?${params}`);
|
|
25449
25466
|
if (!response.ok) {
|
|
25450
|
-
throw new Error(`Binance
|
|
25467
|
+
throw new Error(`Binance klines failed: ${response.status}`);
|
|
25451
25468
|
}
|
|
25452
25469
|
const data = await response.json();
|
|
25453
25470
|
return data.map((k) => ({
|
|
@@ -25467,7 +25484,7 @@ async function fetch24hrTicker(symbol) {
|
|
|
25467
25484
|
const data = await response.json();
|
|
25468
25485
|
return {
|
|
25469
25486
|
lastPrice: parseFloat(data.lastPrice),
|
|
25470
|
-
|
|
25487
|
+
openPrice: parseFloat(data.openPrice),
|
|
25471
25488
|
priceChangePercent: parseFloat(data.priceChangePercent)
|
|
25472
25489
|
};
|
|
25473
25490
|
}
|
|
@@ -25481,7 +25498,7 @@ async function fetch24hrTickers() {
|
|
|
25481
25498
|
for (const item of data) {
|
|
25482
25499
|
result[item.symbol] = {
|
|
25483
25500
|
lastPrice: parseFloat(item.lastPrice),
|
|
25484
|
-
|
|
25501
|
+
openPrice: parseFloat(item.openPrice),
|
|
25485
25502
|
priceChangePercent: parseFloat(item.priceChangePercent)
|
|
25486
25503
|
};
|
|
25487
25504
|
}
|
|
@@ -25517,7 +25534,7 @@ function useSymmTokenSelectionMarkets(params) {
|
|
|
25517
25534
|
return;
|
|
25518
25535
|
}
|
|
25519
25536
|
const ticker = allTickers[binanceSymbol];
|
|
25520
|
-
tickerSnapshots[symbol] = ticker ? {
|
|
25537
|
+
tickerSnapshots[symbol] = ticker ? { openPrice: ticker.openPrice } : null;
|
|
25521
25538
|
});
|
|
25522
25539
|
return { tickerSnapshots };
|
|
25523
25540
|
},
|
|
@@ -25530,7 +25547,7 @@ function useSymmTokenSelectionMarkets(params) {
|
|
|
25530
25547
|
return baseMarkets.map((market) => {
|
|
25531
25548
|
const symbol = market.symbol ?? "";
|
|
25532
25549
|
const markPrice = symbol ? liveMarkPrices[symbol] ?? null : null;
|
|
25533
|
-
const prevDayPrice = symbol ? snapshots[symbol]?.
|
|
25550
|
+
const prevDayPrice = symbol ? snapshots[symbol]?.openPrice ?? null : null;
|
|
25534
25551
|
const priceChange24h = markPrice != null && prevDayPrice != null ? markPrice - prevDayPrice : null;
|
|
25535
25552
|
const priceChange24hPercent = markPrice != null && prevDayPrice != null && prevDayPrice !== 0 ? (markPrice - prevDayPrice) / prevDayPrice * 100 : null;
|
|
25536
25553
|
return {
|
|
@@ -26148,7 +26165,7 @@ async function fetchTickerSnapshot(symbol) {
|
|
|
26148
26165
|
const ticker = await fetch24hrTicker(resolution.binanceSymbol);
|
|
26149
26166
|
if (!ticker) return null;
|
|
26150
26167
|
return {
|
|
26151
|
-
|
|
26168
|
+
openPrice: ticker.openPrice
|
|
26152
26169
|
};
|
|
26153
26170
|
}
|
|
26154
26171
|
function toSymmTokenMetadata(currentPrice, prevDayPrice) {
|
|
@@ -26208,12 +26225,12 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
|
|
|
26208
26225
|
for (const token of longTokens) {
|
|
26209
26226
|
const currentPrice = liveMarkPrices[token.symbol];
|
|
26210
26227
|
const ticker = tickerSnapshots[token.symbol];
|
|
26211
|
-
longMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.
|
|
26228
|
+
longMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.openPrice) : null;
|
|
26212
26229
|
}
|
|
26213
26230
|
for (const token of shortTokens) {
|
|
26214
26231
|
const currentPrice = liveMarkPrices[token.symbol];
|
|
26215
26232
|
const ticker = tickerSnapshots[token.symbol];
|
|
26216
|
-
shortMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.
|
|
26233
|
+
shortMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.openPrice) : null;
|
|
26217
26234
|
}
|
|
26218
26235
|
const allLongReady = longTokens.every(
|
|
26219
26236
|
(t) => longMeta[t.symbol]?.currentPrice != null
|
|
@@ -26334,10 +26351,13 @@ function toBinanceInterval(interval) {
|
|
|
26334
26351
|
}
|
|
26335
26352
|
|
|
26336
26353
|
// src/react/hooks/use-symm-chart-candles.ts
|
|
26354
|
+
function areIntervalsEqual(currentInterval, nextInterval) {
|
|
26355
|
+
return currentInterval === toBinanceInterval(nextInterval);
|
|
26356
|
+
}
|
|
26337
26357
|
async function fetchSymbolKlines(symbol, interval, start, end) {
|
|
26338
26358
|
const binanceSymbol = toBinanceSymbol(symbol);
|
|
26339
26359
|
if (!binanceSymbol) return [];
|
|
26340
|
-
const klines = await
|
|
26360
|
+
const klines = await fetchKlines(
|
|
26341
26361
|
binanceSymbol,
|
|
26342
26362
|
toBinanceInterval(interval),
|
|
26343
26363
|
start,
|
|
@@ -26498,6 +26518,15 @@ function useSymmChartCandles(selection) {
|
|
|
26498
26518
|
wsUnsubsRef.current.push(unsub);
|
|
26499
26519
|
}
|
|
26500
26520
|
}, [emitRealtimeBar, isUnsupported, selectedSymbols]);
|
|
26521
|
+
const setRealtimeInterval = react.useCallback((interval) => {
|
|
26522
|
+
if (areIntervalsEqual(activeIntervalRef.current, interval)) {
|
|
26523
|
+
return;
|
|
26524
|
+
}
|
|
26525
|
+
activeIntervalRef.current = toBinanceInterval(interval);
|
|
26526
|
+
if (listenersRef.current.size > 0) {
|
|
26527
|
+
setupWsSubscriptions();
|
|
26528
|
+
}
|
|
26529
|
+
}, [setupWsSubscriptions]);
|
|
26501
26530
|
react.useEffect(() => {
|
|
26502
26531
|
if (listenersRef.current.size > 0) {
|
|
26503
26532
|
setupWsSubscriptions();
|
|
@@ -26509,6 +26538,7 @@ function useSymmChartCandles(selection) {
|
|
|
26509
26538
|
}, [setupWsSubscriptions]);
|
|
26510
26539
|
const fetchBasketCandles = react.useCallback(
|
|
26511
26540
|
async (start, end, interval) => {
|
|
26541
|
+
setRealtimeInterval(interval);
|
|
26512
26542
|
const longSymbol = longTokens[0]?.symbol;
|
|
26513
26543
|
const shortSymbol = shortTokens[0]?.symbol;
|
|
26514
26544
|
if (isUnsupported) {
|
|
@@ -26534,18 +26564,20 @@ function useSymmChartCandles(selection) {
|
|
|
26534
26564
|
Object.fromEntries(entries)
|
|
26535
26565
|
);
|
|
26536
26566
|
},
|
|
26537
|
-
[isUnsupported, longTokens, shortTokens]
|
|
26567
|
+
[isUnsupported, longTokens, setRealtimeInterval, shortTokens]
|
|
26538
26568
|
);
|
|
26539
26569
|
const fetchPerformanceCandles = react.useCallback(
|
|
26540
26570
|
async (start, end, interval, symbol) => {
|
|
26571
|
+
setRealtimeInterval(interval);
|
|
26541
26572
|
const parts = symbol.split(" ");
|
|
26542
26573
|
const assetSymbol = parts.length >= 2 ? parts.slice(1).join(" ") : symbol;
|
|
26543
26574
|
return fetchSymbolKlines(assetSymbol, interval, start, end);
|
|
26544
26575
|
},
|
|
26545
|
-
[]
|
|
26576
|
+
[setRealtimeInterval]
|
|
26546
26577
|
);
|
|
26547
26578
|
const fetchOverallPerformanceCandles = react.useCallback(
|
|
26548
26579
|
async (start, end, interval) => {
|
|
26580
|
+
setRealtimeInterval(interval);
|
|
26549
26581
|
const longSymbol = longTokens[0]?.symbol;
|
|
26550
26582
|
const shortSymbol = shortTokens[0]?.symbol;
|
|
26551
26583
|
if (isUnsupported) return [];
|
|
@@ -26602,7 +26634,7 @@ function useSymmChartCandles(selection) {
|
|
|
26602
26634
|
}
|
|
26603
26635
|
return result;
|
|
26604
26636
|
},
|
|
26605
|
-
[isUnsupported, longTokens, shortTokens]
|
|
26637
|
+
[isUnsupported, longTokens, setRealtimeInterval, shortTokens]
|
|
26606
26638
|
);
|
|
26607
26639
|
const addRealtimeListener = react.useCallback((cb) => {
|
|
26608
26640
|
const id = Math.random().toString(36).slice(2);
|