@orderly.network/hooks 2.8.4 → 2.8.5
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +67 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -38,9 +38,9 @@ var __export = (target, all) => {
|
|
|
38
38
|
// src/version.ts
|
|
39
39
|
if (typeof window !== "undefined") {
|
|
40
40
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
41
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
41
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.5";
|
|
42
42
|
}
|
|
43
|
-
var version_default = "2.8.
|
|
43
|
+
var version_default = "2.8.5";
|
|
44
44
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
45
45
|
var noCacheConfig = {
|
|
46
46
|
dedupingInterval: 0,
|
|
@@ -3205,28 +3205,42 @@ var ProxyConfigStore = class {
|
|
|
3205
3205
|
this._originConfigStore.clear();
|
|
3206
3206
|
}
|
|
3207
3207
|
};
|
|
3208
|
+
var useMarketStore = create(
|
|
3209
|
+
(set, get3) => ({
|
|
3210
|
+
market: [],
|
|
3211
|
+
marketMap: null,
|
|
3212
|
+
actions: {
|
|
3213
|
+
updateMarket: (data) => {
|
|
3214
|
+
const marketMap = {};
|
|
3215
|
+
data.forEach((item) => {
|
|
3216
|
+
marketMap[item.symbol] = item;
|
|
3217
|
+
});
|
|
3218
|
+
set({
|
|
3219
|
+
market: data,
|
|
3220
|
+
marketMap
|
|
3221
|
+
});
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
})
|
|
3225
|
+
);
|
|
3226
|
+
var useMarketList = () => {
|
|
3227
|
+
return useMarketStore((state) => state.market);
|
|
3228
|
+
};
|
|
3229
|
+
var useMarketMap = () => {
|
|
3230
|
+
return useMarketStore((state) => state.marketMap);
|
|
3231
|
+
};
|
|
3232
|
+
|
|
3233
|
+
// src/orderly/useMarketsStream.ts
|
|
3208
3234
|
var useMarketsStream = () => {
|
|
3209
3235
|
const ws = useWS();
|
|
3210
|
-
const
|
|
3211
|
-
revalidateOnFocus: false
|
|
3212
|
-
});
|
|
3236
|
+
const futures = useMarketList();
|
|
3213
3237
|
const topic = "tickers";
|
|
3214
3238
|
const { data: tickers } = useSWRSubscription("tickers", (_, { next }) => {
|
|
3215
|
-
const unsubscribe = ws.subscribe(
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
{
|
|
3219
|
-
onMessage: (message) => {
|
|
3220
|
-
next(null, message);
|
|
3221
|
-
}
|
|
3222
|
-
// onUnsubscribe: () => {
|
|
3223
|
-
// return "markprices";
|
|
3224
|
-
// },
|
|
3225
|
-
// onError: (error: any) => {
|
|
3226
|
-
//
|
|
3227
|
-
// },
|
|
3239
|
+
const unsubscribe = ws.subscribe(topic, {
|
|
3240
|
+
onMessage: (message) => {
|
|
3241
|
+
next(null, message);
|
|
3228
3242
|
}
|
|
3229
|
-
);
|
|
3243
|
+
});
|
|
3230
3244
|
return () => {
|
|
3231
3245
|
unsubscribe?.();
|
|
3232
3246
|
};
|
|
@@ -3992,37 +4006,6 @@ var useMarkPrice = (symbol) => {
|
|
|
3992
4006
|
}, [symbol]);
|
|
3993
4007
|
return { data: price };
|
|
3994
4008
|
};
|
|
3995
|
-
var useFutures = () => {
|
|
3996
|
-
const { data, isLoading, error } = useQuery(
|
|
3997
|
-
`/v1/public/futures`,
|
|
3998
|
-
{
|
|
3999
|
-
revalidateOnFocus: false
|
|
4000
|
-
}
|
|
4001
|
-
);
|
|
4002
|
-
const [sortedData, setSortedData] = useState(data);
|
|
4003
|
-
useWS();
|
|
4004
|
-
useEffect(() => {
|
|
4005
|
-
}, []);
|
|
4006
|
-
useEffect(() => {
|
|
4007
|
-
if (data) {
|
|
4008
|
-
const sortedData2 = data.sort((a, b) => {
|
|
4009
|
-
return 0;
|
|
4010
|
-
});
|
|
4011
|
-
setSortedData(sortedData2);
|
|
4012
|
-
}
|
|
4013
|
-
}, [data]);
|
|
4014
|
-
const sortBy = useCallback((key) => {
|
|
4015
|
-
}, [data]);
|
|
4016
|
-
const filterBy = useCallback((key) => {
|
|
4017
|
-
}, [data]);
|
|
4018
|
-
return {
|
|
4019
|
-
data: sortedData,
|
|
4020
|
-
sortBy,
|
|
4021
|
-
filterBy,
|
|
4022
|
-
isLoading,
|
|
4023
|
-
error
|
|
4024
|
-
};
|
|
4025
|
-
};
|
|
4026
4009
|
var useIndexPrice = (symbol) => {
|
|
4027
4010
|
symbol = symbol.replace("PERP", "SPOT");
|
|
4028
4011
|
const symbolRef = useRef(symbol);
|
|
@@ -4100,24 +4083,17 @@ var useTickerStream = (symbol) => {
|
|
|
4100
4083
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
4101
4084
|
const { data: indexPrice } = useIndexPrice(symbol);
|
|
4102
4085
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
4103
|
-
const
|
|
4086
|
+
const marketMap = useMarketMap();
|
|
4104
4087
|
const value = useMemo(() => {
|
|
4105
4088
|
if (!info)
|
|
4106
4089
|
return null;
|
|
4107
4090
|
if (!ticker || ticker.symbol !== symbol)
|
|
4108
4091
|
return info;
|
|
4109
|
-
const futureIndex = futures?.findIndex(
|
|
4110
|
-
(item) => item.symbol === symbol
|
|
4111
|
-
);
|
|
4112
|
-
let _oi = openInterest;
|
|
4113
|
-
if (!_oi && futureIndex !== -1 && futures) {
|
|
4114
|
-
_oi = futures[futureIndex].open_interest;
|
|
4115
|
-
}
|
|
4116
4092
|
const config = {
|
|
4117
4093
|
...info,
|
|
4118
4094
|
mark_price: markPrice,
|
|
4119
4095
|
index_price: indexPrice,
|
|
4120
|
-
open_interest:
|
|
4096
|
+
open_interest: openInterest || marketMap?.[symbol]?.open_interest
|
|
4121
4097
|
};
|
|
4122
4098
|
if (ticker.open !== void 0) {
|
|
4123
4099
|
config["24h_open"] = ticker.open;
|
|
@@ -4140,7 +4116,7 @@ var useTickerStream = (symbol) => {
|
|
|
4140
4116
|
config["24h_change"] = new Decimal(ticker.close).minus(ticker.open).toNumber();
|
|
4141
4117
|
}
|
|
4142
4118
|
return config;
|
|
4143
|
-
}, [info, symbol, ticker,
|
|
4119
|
+
}, [info, symbol, ticker, openInterest, marketMap]);
|
|
4144
4120
|
return value;
|
|
4145
4121
|
};
|
|
4146
4122
|
|
|
@@ -10949,54 +10925,46 @@ var useTokenInfo = (token) => {
|
|
|
10949
10925
|
return tokensInfo?.find((item) => item.token === token);
|
|
10950
10926
|
}, [tokensInfo, token]);
|
|
10951
10927
|
};
|
|
10952
|
-
var
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
//
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
10964
|
-
|
|
10965
|
-
|
|
10966
|
-
|
|
10967
|
-
|
|
10968
|
-
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
produce((state) => {
|
|
10972
|
-
state.market = data;
|
|
10973
|
-
})
|
|
10974
|
-
);
|
|
10975
|
-
}
|
|
10928
|
+
var useFutures = () => {
|
|
10929
|
+
const { dataAdapter } = useOrderlyContext();
|
|
10930
|
+
const { data } = useQuery("/v1/public/futures", {
|
|
10931
|
+
// 24 hours
|
|
10932
|
+
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
10933
|
+
revalidateOnFocus: true,
|
|
10934
|
+
// 24 hours
|
|
10935
|
+
dedupingInterval: 1e3 * 60 * 60 * 24
|
|
10936
|
+
// onSuccess will not be called, because /v1/public/futures trigger multiple times
|
|
10937
|
+
// onSuccess(data: API.MarketInfo[]) {
|
|
10938
|
+
// if (!data || !data?.length) {
|
|
10939
|
+
// return [];
|
|
10940
|
+
// }
|
|
10941
|
+
// updateMarket(data as API.MarketInfoExt[]);
|
|
10942
|
+
// },
|
|
10943
|
+
});
|
|
10944
|
+
const futures = useMemo(() => {
|
|
10945
|
+
if (Array.isArray(data)) {
|
|
10946
|
+
return typeof dataAdapter?.symbolList === "function" ? dataAdapter.symbolList(data) : data;
|
|
10976
10947
|
}
|
|
10977
|
-
|
|
10978
|
-
);
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
};
|
|
10982
|
-
var useMarketMap = () => {
|
|
10983
|
-
return useMarketStore((state) => state.marketMap);
|
|
10948
|
+
return [];
|
|
10949
|
+
}, [data, dataAdapter?.symbolList]);
|
|
10950
|
+
return {
|
|
10951
|
+
data: futures
|
|
10952
|
+
};
|
|
10984
10953
|
};
|
|
10985
10954
|
|
|
10986
10955
|
// src/orderly/usePublicDataObserver.ts
|
|
10987
10956
|
var publicQueryOptions = {
|
|
10957
|
+
// 24 hours, not effective, because revalidateOnFocus is false
|
|
10988
10958
|
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
10989
10959
|
revalidateOnFocus: false,
|
|
10960
|
+
// 24 hours
|
|
10990
10961
|
dedupingInterval: 1e3 * 60 * 60 * 24
|
|
10991
10962
|
};
|
|
10992
10963
|
var usePublicDataObserver = () => {
|
|
10993
10964
|
const { setSymbolsInfo, setFundingRates, setRwaSymbolsInfo } = useAppStore(
|
|
10994
10965
|
(state) => state.actions
|
|
10995
10966
|
);
|
|
10996
|
-
const { updateMarket } = useMarketStore((state) => state.actions);
|
|
10997
10967
|
const symbols = useSymbolStore((state) => state.data);
|
|
10998
|
-
const { dataAdapter } = useOrderlyContext();
|
|
10999
|
-
const resolveList = typeof dataAdapter?.symbolList === "function" ? dataAdapter.symbolList : (oriVal) => oriVal;
|
|
11000
10968
|
useEffect(() => {
|
|
11001
10969
|
if (!symbols || !symbols?.length) {
|
|
11002
10970
|
return;
|
|
@@ -11057,23 +11025,11 @@ var usePublicDataObserver = () => {
|
|
|
11057
11025
|
setFundingRates(obj);
|
|
11058
11026
|
}
|
|
11059
11027
|
});
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
return [];
|
|
11066
|
-
}
|
|
11067
|
-
updateMarket(data);
|
|
11068
|
-
},
|
|
11069
|
-
formatter(data) {
|
|
11070
|
-
const rowsData = data.rows;
|
|
11071
|
-
if (Array.isArray(rowsData)) {
|
|
11072
|
-
return resolveList(rowsData);
|
|
11073
|
-
}
|
|
11074
|
-
return resolveList(data);
|
|
11075
|
-
}
|
|
11076
|
-
});
|
|
11028
|
+
const { data: futures } = useFutures();
|
|
11029
|
+
const { updateMarket } = useMarketStore((state) => state.actions);
|
|
11030
|
+
useEffect(() => {
|
|
11031
|
+
updateMarket(futures);
|
|
11032
|
+
}, [futures]);
|
|
11077
11033
|
};
|
|
11078
11034
|
function getEstFundingRate(data) {
|
|
11079
11035
|
if (!data) {
|