@orderly.network/hooks 0.0.80 → 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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +85 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
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 = {
|
|
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.
|
|
519
|
-
config["
|
|
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
|
|
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);
|
|
@@ -1675,12 +1721,25 @@ var useMarketsStream = () => {
|
|
|
1675
1721
|
var useLeverage = () => {
|
|
1676
1722
|
const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
|
|
1677
1723
|
const [update] = useMutation("/v1/client/leverage");
|
|
1724
|
+
const { data: config } = useQuery("/v1/public/config");
|
|
1678
1725
|
const updateLeverage = useCallback((data2) => {
|
|
1679
1726
|
return update(data2).then((res) => {
|
|
1680
|
-
|
|
1727
|
+
console.log(res);
|
|
1728
|
+
if (res.success) {
|
|
1729
|
+
return mutate2();
|
|
1730
|
+
} else {
|
|
1731
|
+
throw new Error(res.message);
|
|
1732
|
+
}
|
|
1681
1733
|
});
|
|
1682
1734
|
}, []);
|
|
1683
|
-
return [
|
|
1735
|
+
return [
|
|
1736
|
+
prop("max_leverage", data),
|
|
1737
|
+
{
|
|
1738
|
+
update: updateLeverage,
|
|
1739
|
+
// config: [1, 2, 3, 4, 5, 10, 15, 20],
|
|
1740
|
+
config: config ? config?.available_futures_leverage?.split(",").map((item) => parseInt(item)) : []
|
|
1741
|
+
}
|
|
1742
|
+
];
|
|
1684
1743
|
};
|
|
1685
1744
|
var useFundingRate = (symbol) => {
|
|
1686
1745
|
if (!symbol) {
|
|
@@ -2928,7 +2987,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
2928
2987
|
const { filter, pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
|
|
2929
2988
|
const { configStore, networkId: envNetworkId } = useContext(OrderlyContext);
|
|
2930
2989
|
const field = options?.pick;
|
|
2931
|
-
const
|
|
2990
|
+
const map2 = useRef(
|
|
2932
2991
|
/* @__PURE__ */ new Map()
|
|
2933
2992
|
);
|
|
2934
2993
|
const { data, error: swapSupportError } = useSWR(
|
|
@@ -2986,7 +3045,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
2986
3045
|
if (!options.filter(_chain))
|
|
2987
3046
|
return;
|
|
2988
3047
|
}
|
|
2989
|
-
|
|
3048
|
+
map2.current.set(chainId, _chain);
|
|
2990
3049
|
orderlyChainsArr.push(_chain);
|
|
2991
3050
|
});
|
|
2992
3051
|
});
|
|
@@ -3035,7 +3094,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3035
3094
|
});
|
|
3036
3095
|
if (item.token_infos?.length === 0)
|
|
3037
3096
|
return;
|
|
3038
|
-
|
|
3097
|
+
map2.current.set(item.network_infos.chain_id, item);
|
|
3039
3098
|
if (typeof options?.filter === "function") {
|
|
3040
3099
|
if (!options.filter(item))
|
|
3041
3100
|
return;
|
|
@@ -3070,7 +3129,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3070
3129
|
}, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
|
|
3071
3130
|
const findByChainId = useCallback(
|
|
3072
3131
|
(chainId, field2) => {
|
|
3073
|
-
const chain =
|
|
3132
|
+
const chain = map2.current.get(chainId);
|
|
3074
3133
|
if (chain) {
|
|
3075
3134
|
chain.nativeToken = chain.token_infos?.find(
|
|
3076
3135
|
(item) => item.address === nativeTokenAddress
|
|
@@ -3081,7 +3140,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3081
3140
|
}
|
|
3082
3141
|
return chain;
|
|
3083
3142
|
},
|
|
3084
|
-
[chains,
|
|
3143
|
+
[chains, map2.current]
|
|
3085
3144
|
);
|
|
3086
3145
|
return [
|
|
3087
3146
|
chains,
|
|
@@ -4103,6 +4162,6 @@ var useSwap = () => {
|
|
|
4103
4162
|
};
|
|
4104
4163
|
};
|
|
4105
4164
|
|
|
4106
|
-
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 };
|
|
4107
4166
|
//# sourceMappingURL=out.js.map
|
|
4108
4167
|
//# sourceMappingURL=index.mjs.map
|