@orderly.network/hooks 0.0.81 → 0.0.82

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/index.mjs CHANGED
@@ -471,6 +471,48 @@ var useConfig = () => {
471
471
  const { configStore } = useContext(OrderlyContext);
472
472
  return configStore;
473
473
  };
474
+ var useMarkPrice = (symbol) => {
475
+ const ws = useWS();
476
+ return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {
477
+ const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
478
+ onMessage: (message) => {
479
+ next(null, message.price);
480
+ }
481
+ });
482
+ return () => {
483
+ unsubscribe?.();
484
+ };
485
+ });
486
+ };
487
+ var useIndexPrice = (symbol) => {
488
+ symbol = symbol.replace("PERP", "SPOT");
489
+ const ws = useWS();
490
+ return useSWRSubscription(`${symbol}@indexprice`, (key, { next }) => {
491
+ const unsubscribe = ws.subscribe(`${symbol}@indexprice`, {
492
+ onMessage: (message) => {
493
+ next(null, message.price);
494
+ }
495
+ });
496
+ return () => {
497
+ unsubscribe?.();
498
+ };
499
+ });
500
+ };
501
+ var useOpenInterest = (symbol) => {
502
+ const ws = useWS();
503
+ return useSWRSubscription(`${symbol}@openinterest`, (key, { next }) => {
504
+ const unsubscribe = ws.subscribe(`${symbol}@openinterest`, {
505
+ onMessage: (message) => {
506
+ next(null, message.openInterest);
507
+ }
508
+ });
509
+ return () => {
510
+ unsubscribe?.();
511
+ };
512
+ });
513
+ };
514
+
515
+ // src/orderly/useTickerStream.ts
474
516
  var useTickerStream = (symbol) => {
475
517
  if (!symbol) {
476
518
  throw new Error("useFuturesForSymbol requires a symbol");
@@ -506,17 +548,31 @@ var useTickerStream = (symbol) => {
506
548
  unsubscribe?.();
507
549
  };
508
550
  }, [symbol]);
551
+ const { data: markPrice } = useMarkPrice(symbol);
552
+ const { data: indexPrice } = useIndexPrice(symbol);
553
+ const { data: openInterest } = useOpenInterest(symbol);
509
554
  const value = useMemo(() => {
510
555
  if (!info)
511
556
  return null;
512
557
  if (!ticker)
513
558
  return info;
514
- const config = { ...info };
559
+ const config = {
560
+ ...info,
561
+ mark_price: markPrice,
562
+ index_price: indexPrice,
563
+ open_interest: openInterest
564
+ };
565
+ if (ticker.open !== void 0) {
566
+ config["24h_open"] = ticker.open;
567
+ }
515
568
  if (ticker.close !== void 0) {
516
569
  config["24h_close"] = ticker.close;
517
570
  }
518
- if (ticker.open !== void 0) {
519
- config["24h_open"] = ticker.open;
571
+ if (ticker.high !== void 0) {
572
+ config["24h_high"] = ticker.high;
573
+ }
574
+ if (ticker.low !== void 0) {
575
+ config["24h_low"] = ticker.low;
520
576
  }
521
577
  if (ticker.volume !== void 0) {
522
578
  config["24h_volumn"] = ticker.volume;
@@ -528,19 +584,6 @@ var useTickerStream = (symbol) => {
528
584
  }, [info, symbol, ticker]);
529
585
  return value;
530
586
  };
531
- var useMarkPrice = (symbol) => {
532
- const ws = useWS();
533
- return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {
534
- const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
535
- onMessage: (message) => {
536
- next(null, message.price);
537
- }
538
- });
539
- return () => {
540
- unsubscribe?.();
541
- };
542
- });
543
- };
544
587
 
545
588
  // src/utils/createGetter.ts
546
589
  function createGetter(data, depth = 2) {
@@ -680,7 +723,8 @@ var mergeOrderbook = (data, update) => {
680
723
  bids
681
724
  };
682
725
  };
683
- var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) => {
726
+ var INIT_DATA = { asks: [], bids: [] };
727
+ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
684
728
  if (!symbol) {
685
729
  throw new Error("useOrderbookStream requires a symbol");
686
730
  }
@@ -701,6 +745,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
701
745
  const ticker = useTickerStream(symbol);
702
746
  const eventEmitter = useEventEmitter();
703
747
  useEffect(() => {
748
+ setIsLoading(true);
704
749
  ws.onceSubscribe(
705
750
  {
706
751
  event: "request",
@@ -723,6 +768,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
723
768
  );
724
769
  return () => {
725
770
  setRequestData(null);
771
+ setData(INIT_DATA);
726
772
  };
727
773
  }, [symbol, depth]);
728
774
  const { data: markPrice } = useMarkPrice(symbol);
@@ -4116,6 +4162,6 @@ var useSwap = () => {
4116
4162
  };
4117
4163
  };
4118
4164
 
4119
- export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
4165
+ export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
4120
4166
  //# sourceMappingURL=out.js.map
4121
4167
  //# sourceMappingURL=index.mjs.map