@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.d.mts
CHANGED
|
@@ -207,8 +207,13 @@ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionRespons
|
|
|
207
207
|
|
|
208
208
|
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
209
209
|
|
|
210
|
+
declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
211
|
+
|
|
212
|
+
declare const useOpenInterest: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
213
|
+
|
|
210
214
|
declare const useLeverage: () => ({
|
|
211
215
|
update: (data: any) => any;
|
|
216
|
+
config: any;
|
|
212
217
|
} | undefined)[];
|
|
213
218
|
|
|
214
219
|
declare const useTickerStream: (symbol: string) => any;
|
|
@@ -481,4 +486,4 @@ declare const useSwap: () => {
|
|
|
481
486
|
status: WS_WalletStatusEnum;
|
|
482
487
|
};
|
|
483
488
|
|
|
484
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
|
489
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -207,8 +207,13 @@ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionRespons
|
|
|
207
207
|
|
|
208
208
|
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
209
209
|
|
|
210
|
+
declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
211
|
+
|
|
212
|
+
declare const useOpenInterest: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
213
|
+
|
|
210
214
|
declare const useLeverage: () => ({
|
|
211
215
|
update: (data: any) => any;
|
|
216
|
+
config: any;
|
|
212
217
|
} | undefined)[];
|
|
213
218
|
|
|
214
219
|
declare const useTickerStream: (symbol: string) => any;
|
|
@@ -481,4 +486,4 @@ declare const useSwap: () => {
|
|
|
481
486
|
status: WS_WalletStatusEnum;
|
|
482
487
|
};
|
|
483
488
|
|
|
484
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
|
489
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.js
CHANGED
|
@@ -480,6 +480,48 @@ var useConfig = () => {
|
|
|
480
480
|
const { configStore } = React2.useContext(OrderlyContext);
|
|
481
481
|
return configStore;
|
|
482
482
|
};
|
|
483
|
+
var useMarkPrice = (symbol) => {
|
|
484
|
+
const ws = useWS();
|
|
485
|
+
return useSWRSubscription__default.default(`${symbol}@markprice`, (key, { next }) => {
|
|
486
|
+
const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
|
|
487
|
+
onMessage: (message) => {
|
|
488
|
+
next(null, message.price);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
return () => {
|
|
492
|
+
unsubscribe?.();
|
|
493
|
+
};
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
var useIndexPrice = (symbol) => {
|
|
497
|
+
symbol = symbol.replace("PERP", "SPOT");
|
|
498
|
+
const ws = useWS();
|
|
499
|
+
return useSWRSubscription__default.default(`${symbol}@indexprice`, (key, { next }) => {
|
|
500
|
+
const unsubscribe = ws.subscribe(`${symbol}@indexprice`, {
|
|
501
|
+
onMessage: (message) => {
|
|
502
|
+
next(null, message.price);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
return () => {
|
|
506
|
+
unsubscribe?.();
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
var useOpenInterest = (symbol) => {
|
|
511
|
+
const ws = useWS();
|
|
512
|
+
return useSWRSubscription__default.default(`${symbol}@openinterest`, (key, { next }) => {
|
|
513
|
+
const unsubscribe = ws.subscribe(`${symbol}@openinterest`, {
|
|
514
|
+
onMessage: (message) => {
|
|
515
|
+
next(null, message.openInterest);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
return () => {
|
|
519
|
+
unsubscribe?.();
|
|
520
|
+
};
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/orderly/useTickerStream.ts
|
|
483
525
|
var useTickerStream = (symbol) => {
|
|
484
526
|
if (!symbol) {
|
|
485
527
|
throw new Error("useFuturesForSymbol requires a symbol");
|
|
@@ -515,17 +557,31 @@ var useTickerStream = (symbol) => {
|
|
|
515
557
|
unsubscribe?.();
|
|
516
558
|
};
|
|
517
559
|
}, [symbol]);
|
|
560
|
+
const { data: markPrice } = useMarkPrice(symbol);
|
|
561
|
+
const { data: indexPrice } = useIndexPrice(symbol);
|
|
562
|
+
const { data: openInterest } = useOpenInterest(symbol);
|
|
518
563
|
const value = React2.useMemo(() => {
|
|
519
564
|
if (!info)
|
|
520
565
|
return null;
|
|
521
566
|
if (!ticker)
|
|
522
567
|
return info;
|
|
523
|
-
const config = {
|
|
568
|
+
const config = {
|
|
569
|
+
...info,
|
|
570
|
+
mark_price: markPrice,
|
|
571
|
+
index_price: indexPrice,
|
|
572
|
+
open_interest: openInterest
|
|
573
|
+
};
|
|
574
|
+
if (ticker.open !== void 0) {
|
|
575
|
+
config["24h_open"] = ticker.open;
|
|
576
|
+
}
|
|
524
577
|
if (ticker.close !== void 0) {
|
|
525
578
|
config["24h_close"] = ticker.close;
|
|
526
579
|
}
|
|
527
|
-
if (ticker.
|
|
528
|
-
config["
|
|
580
|
+
if (ticker.high !== void 0) {
|
|
581
|
+
config["24h_high"] = ticker.high;
|
|
582
|
+
}
|
|
583
|
+
if (ticker.low !== void 0) {
|
|
584
|
+
config["24h_low"] = ticker.low;
|
|
529
585
|
}
|
|
530
586
|
if (ticker.volume !== void 0) {
|
|
531
587
|
config["24h_volumn"] = ticker.volume;
|
|
@@ -537,19 +593,6 @@ var useTickerStream = (symbol) => {
|
|
|
537
593
|
}, [info, symbol, ticker]);
|
|
538
594
|
return value;
|
|
539
595
|
};
|
|
540
|
-
var useMarkPrice = (symbol) => {
|
|
541
|
-
const ws = useWS();
|
|
542
|
-
return useSWRSubscription__default.default(`${symbol}@markprice`, (key, { next }) => {
|
|
543
|
-
const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
|
|
544
|
-
onMessage: (message) => {
|
|
545
|
-
next(null, message.price);
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
return () => {
|
|
549
|
-
unsubscribe?.();
|
|
550
|
-
};
|
|
551
|
-
});
|
|
552
|
-
};
|
|
553
596
|
|
|
554
597
|
// src/utils/createGetter.ts
|
|
555
598
|
function createGetter(data, depth = 2) {
|
|
@@ -689,7 +732,8 @@ var mergeOrderbook = (data, update) => {
|
|
|
689
732
|
bids
|
|
690
733
|
};
|
|
691
734
|
};
|
|
692
|
-
var
|
|
735
|
+
var INIT_DATA = { asks: [], bids: [] };
|
|
736
|
+
var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
693
737
|
if (!symbol) {
|
|
694
738
|
throw new Error("useOrderbookStream requires a symbol");
|
|
695
739
|
}
|
|
@@ -710,6 +754,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
710
754
|
const ticker = useTickerStream(symbol);
|
|
711
755
|
const eventEmitter = useEventEmitter();
|
|
712
756
|
React2.useEffect(() => {
|
|
757
|
+
setIsLoading(true);
|
|
713
758
|
ws.onceSubscribe(
|
|
714
759
|
{
|
|
715
760
|
event: "request",
|
|
@@ -732,6 +777,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
732
777
|
);
|
|
733
778
|
return () => {
|
|
734
779
|
setRequestData(null);
|
|
780
|
+
setData(INIT_DATA);
|
|
735
781
|
};
|
|
736
782
|
}, [symbol, depth]);
|
|
737
783
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
@@ -1684,12 +1730,25 @@ var useMarketsStream = () => {
|
|
|
1684
1730
|
var useLeverage = () => {
|
|
1685
1731
|
const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
|
|
1686
1732
|
const [update] = useMutation("/v1/client/leverage");
|
|
1733
|
+
const { data: config } = useQuery("/v1/public/config");
|
|
1687
1734
|
const updateLeverage = React2.useCallback((data2) => {
|
|
1688
1735
|
return update(data2).then((res) => {
|
|
1689
|
-
|
|
1736
|
+
console.log(res);
|
|
1737
|
+
if (res.success) {
|
|
1738
|
+
return mutate2();
|
|
1739
|
+
} else {
|
|
1740
|
+
throw new Error(res.message);
|
|
1741
|
+
}
|
|
1690
1742
|
});
|
|
1691
1743
|
}, []);
|
|
1692
|
-
return [
|
|
1744
|
+
return [
|
|
1745
|
+
ramda.prop("max_leverage", data),
|
|
1746
|
+
{
|
|
1747
|
+
update: updateLeverage,
|
|
1748
|
+
// config: [1, 2, 3, 4, 5, 10, 15, 20],
|
|
1749
|
+
config: config ? config?.available_futures_leverage?.split(",").map((item) => parseInt(item)) : []
|
|
1750
|
+
}
|
|
1751
|
+
];
|
|
1693
1752
|
};
|
|
1694
1753
|
var useFundingRate = (symbol) => {
|
|
1695
1754
|
if (!symbol) {
|
|
@@ -2937,7 +2996,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
2937
2996
|
const { filter, pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
|
|
2938
2997
|
const { configStore, networkId: envNetworkId } = React2.useContext(OrderlyContext);
|
|
2939
2998
|
const field = options?.pick;
|
|
2940
|
-
const
|
|
2999
|
+
const map2 = React2.useRef(
|
|
2941
3000
|
/* @__PURE__ */ new Map()
|
|
2942
3001
|
);
|
|
2943
3002
|
const { data, error: swapSupportError } = useSWR__default.default(
|
|
@@ -2995,7 +3054,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
2995
3054
|
if (!options.filter(_chain))
|
|
2996
3055
|
return;
|
|
2997
3056
|
}
|
|
2998
|
-
|
|
3057
|
+
map2.current.set(chainId, _chain);
|
|
2999
3058
|
orderlyChainsArr.push(_chain);
|
|
3000
3059
|
});
|
|
3001
3060
|
});
|
|
@@ -3044,7 +3103,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3044
3103
|
});
|
|
3045
3104
|
if (item.token_infos?.length === 0)
|
|
3046
3105
|
return;
|
|
3047
|
-
|
|
3106
|
+
map2.current.set(item.network_infos.chain_id, item);
|
|
3048
3107
|
if (typeof options?.filter === "function") {
|
|
3049
3108
|
if (!options.filter(item))
|
|
3050
3109
|
return;
|
|
@@ -3079,7 +3138,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3079
3138
|
}, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
|
|
3080
3139
|
const findByChainId = React2.useCallback(
|
|
3081
3140
|
(chainId, field2) => {
|
|
3082
|
-
const chain =
|
|
3141
|
+
const chain = map2.current.get(chainId);
|
|
3083
3142
|
if (chain) {
|
|
3084
3143
|
chain.nativeToken = chain.token_infos?.find(
|
|
3085
3144
|
(item) => item.address === nativeTokenAddress
|
|
@@ -3090,7 +3149,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3090
3149
|
}
|
|
3091
3150
|
return chain;
|
|
3092
3151
|
},
|
|
3093
|
-
[chains,
|
|
3152
|
+
[chains, map2.current]
|
|
3094
3153
|
);
|
|
3095
3154
|
return [
|
|
3096
3155
|
chains,
|
|
@@ -4146,6 +4205,7 @@ exports.useExecutionReport = useExecutionReport;
|
|
|
4146
4205
|
exports.useFetures = useFetures;
|
|
4147
4206
|
exports.useFundingRate = useFundingRate;
|
|
4148
4207
|
exports.useHoldingStream = useHoldingStream;
|
|
4208
|
+
exports.useIndexPrice = useIndexPrice;
|
|
4149
4209
|
exports.useLazyQuery = useLazyQuery;
|
|
4150
4210
|
exports.useLeverage = useLeverage;
|
|
4151
4211
|
exports.useLocalStorage = useLocalStorage;
|
|
@@ -4156,6 +4216,7 @@ exports.useMarketTradeStream = useMarketTradeStream;
|
|
|
4156
4216
|
exports.useMarketsStream = useMarketsStream;
|
|
4157
4217
|
exports.useMaxQty = useMaxQty;
|
|
4158
4218
|
exports.useMutation = useMutation;
|
|
4219
|
+
exports.useOpenInterest = useOpenInterest;
|
|
4159
4220
|
exports.useOrderEntry = useOrderEntry;
|
|
4160
4221
|
exports.useOrderStream = useOrderStream;
|
|
4161
4222
|
exports.useOrderbookStream = useOrderbookStream;
|