@pear-protocol/symmio-client 0.2.29 → 0.2.30

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.
@@ -8706,8 +8706,6 @@ interface SymmTokenSelectionMarket extends MarketItem {
8706
8706
  priceChange24hPercent: number | null;
8707
8707
  }
8708
8708
  interface UseSymmTokenSelectionMarketsReturn {
8709
- query: ReturnType<typeof useSymmHedgerMarkets>;
8710
- priceQuery: ReturnType<typeof useQuery>;
8711
8709
  markets: SymmTokenSelectionMarket[];
8712
8710
  marketsBySymbol: Map<string, SymmTokenSelectionMarket>;
8713
8711
  marketsById: Map<number, SymmTokenSelectionMarket>;
@@ -8875,6 +8873,8 @@ interface SymmTokenMetadata {
8875
8873
  priceChange24hPercent: number;
8876
8874
  netFunding: number;
8877
8875
  markPrice: number;
8876
+ fundingRate: number;
8877
+ nextFundingTime: number;
8878
8878
  }
8879
8879
  interface UseSymmTokenSelectionMetadataReturn {
8880
8880
  query: ReturnType<typeof useQuery>;
@@ -9099,8 +9099,12 @@ type SymmWsState = {
9099
9099
  declare const useSymmWsStore: zustand.UseBoundStore<zustand.StoreApi<SymmWsState>>;
9100
9100
 
9101
9101
  type MarkPrices = Record<string, number>;
9102
+ type FundingRates = Record<string, number>;
9103
+ type NextFundingTimes = Record<string, number>;
9102
9104
  type BinanceMarkPriceState = {
9103
9105
  markPrices: MarkPrices;
9106
+ fundingRates: FundingRates;
9107
+ nextFundingTimes: NextFundingTimes;
9104
9108
  subscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
9105
9109
  unsubscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
9106
9110
  };
@@ -8706,8 +8706,6 @@ interface SymmTokenSelectionMarket extends MarketItem {
8706
8706
  priceChange24hPercent: number | null;
8707
8707
  }
8708
8708
  interface UseSymmTokenSelectionMarketsReturn {
8709
- query: ReturnType<typeof useSymmHedgerMarkets>;
8710
- priceQuery: ReturnType<typeof useQuery>;
8711
8709
  markets: SymmTokenSelectionMarket[];
8712
8710
  marketsBySymbol: Map<string, SymmTokenSelectionMarket>;
8713
8711
  marketsById: Map<number, SymmTokenSelectionMarket>;
@@ -8875,6 +8873,8 @@ interface SymmTokenMetadata {
8875
8873
  priceChange24hPercent: number;
8876
8874
  netFunding: number;
8877
8875
  markPrice: number;
8876
+ fundingRate: number;
8877
+ nextFundingTime: number;
8878
8878
  }
8879
8879
  interface UseSymmTokenSelectionMetadataReturn {
8880
8880
  query: ReturnType<typeof useQuery>;
@@ -9099,8 +9099,12 @@ type SymmWsState = {
9099
9099
  declare const useSymmWsStore: zustand.UseBoundStore<zustand.StoreApi<SymmWsState>>;
9100
9100
 
9101
9101
  type MarkPrices = Record<string, number>;
9102
+ type FundingRates = Record<string, number>;
9103
+ type NextFundingTimes = Record<string, number>;
9102
9104
  type BinanceMarkPriceState = {
9103
9105
  markPrices: MarkPrices;
9106
+ fundingRates: FundingRates;
9107
+ nextFundingTimes: NextFundingTimes;
9104
9108
  subscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
9105
9109
  unsubscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
9106
9110
  };
@@ -161,7 +161,9 @@ var BinanceWsManager = class {
161
161
  symbol: normalizeBaseSymbol(raw.s),
162
162
  markPrice: parseFloat(raw.p),
163
163
  indexPrice: parseFloat(raw.i),
164
- time: raw.E
164
+ time: raw.E,
165
+ fundingRate: parseFloat(raw.r ?? "0"),
166
+ nextFundingTime: Number(raw.T ?? 0)
165
167
  });
166
168
  };
167
169
  this.addStreamCallback(streamName, id, wrappedCb);
@@ -180,7 +182,9 @@ var BinanceWsManager = class {
180
182
  symbol: normalizeBaseSymbol(entry.s),
181
183
  markPrice: parseFloat(entry.p),
182
184
  indexPrice: parseFloat(entry.i),
183
- time: entry.E
185
+ time: entry.E,
186
+ fundingRate: parseFloat(entry.r ?? "0"),
187
+ nextFundingTime: Number(entry.T ?? 0)
184
188
  }))
185
189
  );
186
190
  };
@@ -360,6 +364,8 @@ function getPrevRefCount(binanceSymbol) {
360
364
  }
361
365
  var useBinanceMarkPriceStore = zustand.create((set) => ({
362
366
  markPrices: {},
367
+ fundingRates: {},
368
+ nextFundingTimes: {},
363
369
  subscribeSymbol: (symmSymbol, rawBinanceSymbol) => {
364
370
  const binanceSymbol = normalizeBinanceSymbol(rawBinanceSymbol);
365
371
  const nextRefCount = getNextRefCount(binanceSymbol);
@@ -372,16 +378,29 @@ var useBinanceMarkPriceStore = zustand.create((set) => ({
372
378
  allMarkPricesUnsubscribe = wsManager.subscribeAllMarkPrices((entries) => {
373
379
  set((state) => {
374
380
  let nextMarkPrices = null;
381
+ let nextFundingRates = null;
382
+ let nextFundingTimes = null;
375
383
  entries.forEach((entry) => {
376
384
  const canonicalSymbol = normalizeBinanceSymbol(entry.symbol);
377
385
  const mappedSymbols = streamSymbols.get(canonicalSymbol);
378
386
  if (!mappedSymbols || mappedSymbols.size === 0) return;
379
387
  nextMarkPrices ??= { ...state.markPrices };
388
+ nextFundingRates ??= { ...state.fundingRates };
389
+ nextFundingTimes ??= { ...state.nextFundingTimes };
380
390
  mappedSymbols.forEach((mappedSymbol) => {
381
391
  nextMarkPrices[mappedSymbol] = entry.markPrice;
392
+ nextFundingRates[mappedSymbol] = entry.fundingRate;
393
+ nextFundingTimes[mappedSymbol] = entry.nextFundingTime;
382
394
  });
383
395
  });
384
- return nextMarkPrices ? { markPrices: nextMarkPrices } : state;
396
+ if (!nextMarkPrices || !nextFundingRates || !nextFundingTimes) {
397
+ return state;
398
+ }
399
+ return {
400
+ markPrices: nextMarkPrices,
401
+ fundingRates: nextFundingRates,
402
+ nextFundingTimes
403
+ };
385
404
  });
386
405
  });
387
406
  }
@@ -410,10 +429,20 @@ var useBinanceMarkPriceStore = zustand.create((set) => ({
410
429
  allMarkPricesUnsubscribe = null;
411
430
  }
412
431
  set((state) => {
413
- if (state.markPrices[symmSymbol] == null) return state;
432
+ if (state.markPrices[symmSymbol] == null && state.fundingRates[symmSymbol] == null && state.nextFundingTimes[symmSymbol] == null) {
433
+ return state;
434
+ }
414
435
  const nextMarkPrices = { ...state.markPrices };
436
+ const nextFundingRates = { ...state.fundingRates };
437
+ const nextFundingTimes = { ...state.nextFundingTimes };
415
438
  delete nextMarkPrices[symmSymbol];
416
- return { markPrices: nextMarkPrices };
439
+ delete nextFundingRates[symmSymbol];
440
+ delete nextFundingTimes[symmSymbol];
441
+ return {
442
+ markPrices: nextMarkPrices,
443
+ fundingRates: nextFundingRates,
444
+ nextFundingTimes
445
+ };
417
446
  });
418
447
  }
419
448
  }));
@@ -25562,7 +25591,9 @@ function useSymmTokenSelectionMarkets(params) {
25562
25591
  }, [baseMarkets, liveMarkPrices, priceQuery.data]);
25563
25592
  const marketsBySymbol = react.useMemo(
25564
25593
  () => new Map(
25565
- markets.filter((m) => !!m.symbol).map((m) => [m.symbol, m])
25594
+ markets.filter(
25595
+ (m) => !!m.symbol
25596
+ ).map((m) => [m.symbol, m])
25566
25597
  ),
25567
25598
  [markets]
25568
25599
  );
@@ -25570,64 +25601,7 @@ function useSymmTokenSelectionMarkets(params) {
25570
25601
  () => new Map(markets.map((market) => [market.id, market])),
25571
25602
  [markets]
25572
25603
  );
25573
- react.useEffect(() => {
25574
- console.debug("[useSymmTokenSelectionMarkets] data flow", {
25575
- params,
25576
- query: {
25577
- status: query.status,
25578
- fetchStatus: query.fetchStatus,
25579
- isLoading: query.isLoading,
25580
- isSuccess: query.isSuccess,
25581
- isError: query.isError,
25582
- error: query.error
25583
- },
25584
- priceQuery: {
25585
- status: priceQuery.status,
25586
- fetchStatus: priceQuery.fetchStatus,
25587
- isLoading: priceQuery.isLoading,
25588
- isSuccess: priceQuery.isSuccess,
25589
- isError: priceQuery.isError,
25590
- error: priceQuery.error
25591
- },
25592
- marketSymbols,
25593
- symbolsKey,
25594
- liveMarkPrices,
25595
- tickerSnapshots: priceQuery.data?.tickerSnapshots ?? {},
25596
- result: {
25597
- marketCount: markets.length,
25598
- markets: markets.map((market) => ({
25599
- id: market.id,
25600
- symbol: market.symbol,
25601
- markPrice: market.markPrice,
25602
- prevDayPrice: market.prevDayPrice,
25603
- priceChange24h: market.priceChange24h,
25604
- priceChange24hPercent: market.priceChange24hPercent
25605
- }))
25606
- }
25607
- });
25608
- }, [
25609
- liveMarkPrices,
25610
- marketSymbols,
25611
- markets,
25612
- params,
25613
- priceQuery.data,
25614
- priceQuery.error,
25615
- priceQuery.fetchStatus,
25616
- priceQuery.isError,
25617
- priceQuery.isLoading,
25618
- priceQuery.isSuccess,
25619
- priceQuery.status,
25620
- query.error,
25621
- query.fetchStatus,
25622
- query.isError,
25623
- query.isLoading,
25624
- query.isSuccess,
25625
- query.status,
25626
- symbolsKey
25627
- ]);
25628
25604
  return {
25629
- query,
25630
- priceQuery,
25631
25605
  markets,
25632
25606
  marketsBySymbol,
25633
25607
  marketsById,
@@ -26168,7 +26142,7 @@ async function fetchTickerSnapshot(symbol) {
26168
26142
  openPrice: ticker.openPrice
26169
26143
  };
26170
26144
  }
26171
- function toSymmTokenMetadata(currentPrice, prevDayPrice) {
26145
+ function toSymmTokenMetadata(currentPrice, prevDayPrice, fundingRate, nextFundingTime) {
26172
26146
  const priceChange24h = currentPrice - prevDayPrice;
26173
26147
  const priceChange24hPercent = prevDayPrice !== 0 ? (currentPrice - prevDayPrice) / prevDayPrice * 100 : 0;
26174
26148
  return {
@@ -26176,9 +26150,10 @@ function toSymmTokenMetadata(currentPrice, prevDayPrice) {
26176
26150
  prevDayPrice,
26177
26151
  priceChange24h,
26178
26152
  priceChange24hPercent,
26179
- netFunding: 0,
26180
- // SYMM funding integration deferred
26181
- markPrice: currentPrice
26153
+ netFunding: fundingRate,
26154
+ markPrice: currentPrice,
26155
+ fundingRate,
26156
+ nextFundingTime
26182
26157
  };
26183
26158
  }
26184
26159
  function useSymmTokenSelectionMetadata(selection, options = {}) {
@@ -26192,6 +26167,12 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
26192
26167
  const unavailableReason = isUnsupported ? `Binance market data is unavailable for ${unsupportedSymbols.join(", ")}.` : null;
26193
26168
  const symbolsKey = [...selectedSymbols].sort().join(",");
26194
26169
  const liveMarkPrices = useBinanceMarkPriceStore((state) => state.markPrices);
26170
+ const liveFundingRates = useBinanceMarkPriceStore(
26171
+ (state) => state.fundingRates
26172
+ );
26173
+ const liveNextFundingTimes = useBinanceMarkPriceStore(
26174
+ (state) => state.nextFundingTimes
26175
+ );
26195
26176
  const query = reactQuery.useQuery({
26196
26177
  queryKey: ["symm", "chart-metadata", symbolsKey],
26197
26178
  queryFn: async () => {
@@ -26224,13 +26205,27 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
26224
26205
  const isLoading = query.isLoading;
26225
26206
  for (const token of longTokens) {
26226
26207
  const currentPrice = liveMarkPrices[token.symbol];
26208
+ const fundingRate = liveFundingRates[token.symbol];
26209
+ const nextFundingTime = liveNextFundingTimes[token.symbol];
26227
26210
  const ticker = tickerSnapshots[token.symbol];
26228
- longMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.openPrice) : null;
26211
+ longMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(
26212
+ currentPrice,
26213
+ ticker.openPrice,
26214
+ fundingRate ?? 0,
26215
+ nextFundingTime ?? 0
26216
+ ) : null;
26229
26217
  }
26230
26218
  for (const token of shortTokens) {
26231
26219
  const currentPrice = liveMarkPrices[token.symbol];
26220
+ const fundingRate = liveFundingRates[token.symbol];
26221
+ const nextFundingTime = liveNextFundingTimes[token.symbol];
26232
26222
  const ticker = tickerSnapshots[token.symbol];
26233
- shortMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(currentPrice, ticker.openPrice) : null;
26223
+ shortMeta[token.symbol] = currentPrice != null && ticker ? toSymmTokenMetadata(
26224
+ currentPrice,
26225
+ ticker.openPrice,
26226
+ fundingRate ?? 0,
26227
+ nextFundingTime ?? 0
26228
+ ) : null;
26234
26229
  }
26235
26230
  const allLongReady = longTokens.every(
26236
26231
  (t) => longMeta[t.symbol]?.currentPrice != null
@@ -26268,60 +26263,17 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
26268
26263
  }, [
26269
26264
  isUnsupported,
26270
26265
  longTokens,
26266
+ query,
26271
26267
  query.data,
26272
26268
  query.isLoading,
26273
26269
  shortTokens,
26274
26270
  unavailableReason,
26275
26271
  unsupportedSymbols,
26276
26272
  selectedSymbols.length,
26273
+ liveFundingRates,
26274
+ liveNextFundingTimes,
26277
26275
  liveMarkPrices
26278
26276
  ]);
26279
- react.useEffect(() => {
26280
- console.debug("[useSymmTokenSelectionMetadata] data flow", {
26281
- selection,
26282
- options,
26283
- query: {
26284
- status: query.status,
26285
- fetchStatus: query.fetchStatus,
26286
- isLoading: query.isLoading,
26287
- isSuccess: query.isSuccess,
26288
- isError: query.isError,
26289
- error: query.error
26290
- },
26291
- selectedSymbols,
26292
- unsupportedSymbols,
26293
- unavailableReason,
26294
- liveMarkPrices,
26295
- tickerSnapshots: query.data?.tickerSnapshots ?? {},
26296
- result: {
26297
- isLoading: result.isLoading,
26298
- isPriceDataReady: result.isPriceDataReady,
26299
- isUnsupported: result.isUnsupported,
26300
- longTokensMetadata: result.longTokensMetadata,
26301
- shortTokensMetadata: result.shortTokensMetadata,
26302
- weightedRatio: result.weightedRatio,
26303
- weightedRatio24h: result.weightedRatio24h,
26304
- priceRatio: result.priceRatio,
26305
- priceRatio24h: result.priceRatio24h,
26306
- sumNetFunding: result.sumNetFunding
26307
- }
26308
- });
26309
- }, [
26310
- liveMarkPrices,
26311
- options,
26312
- query.data,
26313
- query.error,
26314
- query.fetchStatus,
26315
- query.isError,
26316
- query.isLoading,
26317
- query.isSuccess,
26318
- query.status,
26319
- result,
26320
- selectedSymbols,
26321
- selection,
26322
- unavailableReason,
26323
- unsupportedSymbols
26324
- ]);
26325
26277
  return result;
26326
26278
  }
26327
26279