@orderly.network/hooks 2.8.4 → 2.8.5-alpha.0
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.d.mts
CHANGED
|
@@ -36,7 +36,7 @@ declare global {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
declare const _default: "2.8.
|
|
39
|
+
declare const _default: "2.8.5-alpha.0";
|
|
40
40
|
|
|
41
41
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
42
42
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -705,7 +705,7 @@ declare const useSymbolInfo: (symbol?: string) => ((<Key extends keyof _orderly_
|
|
|
705
705
|
declare const useAccountInfo: () => swr.SWRResponse<API.AccountInfo, any, any>;
|
|
706
706
|
|
|
707
707
|
declare const useMarketsStream: () => {
|
|
708
|
-
data: WSMessage.Ticker[]
|
|
708
|
+
data: WSMessage.Ticker[];
|
|
709
709
|
};
|
|
710
710
|
|
|
711
711
|
declare enum MarketsType$1 {
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare global {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
declare const _default: "2.8.
|
|
39
|
+
declare const _default: "2.8.5-alpha.0";
|
|
40
40
|
|
|
41
41
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
42
42
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -705,7 +705,7 @@ declare const useSymbolInfo: (symbol?: string) => ((<Key extends keyof _orderly_
|
|
|
705
705
|
declare const useAccountInfo: () => swr.SWRResponse<API.AccountInfo, any, any>;
|
|
706
706
|
|
|
707
707
|
declare const useMarketsStream: () => {
|
|
708
|
-
data: WSMessage.Ticker[]
|
|
708
|
+
data: WSMessage.Ticker[];
|
|
709
709
|
};
|
|
710
710
|
|
|
711
711
|
declare enum MarketsType$1 {
|
package/dist/index.js
CHANGED
|
@@ -64,9 +64,9 @@ var __export = (target, all) => {
|
|
|
64
64
|
// src/version.ts
|
|
65
65
|
if (typeof window !== "undefined") {
|
|
66
66
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
67
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
67
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.5-alpha.0";
|
|
68
68
|
}
|
|
69
|
-
var version_default = "2.8.
|
|
69
|
+
var version_default = "2.8.5-alpha.0";
|
|
70
70
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
71
71
|
var noCacheConfig = {
|
|
72
72
|
dedupingInterval: 0,
|
|
@@ -3231,28 +3231,42 @@ var ProxyConfigStore = class {
|
|
|
3231
3231
|
this._originConfigStore.clear();
|
|
3232
3232
|
}
|
|
3233
3233
|
};
|
|
3234
|
+
var useMarketStore = zustand.create(
|
|
3235
|
+
(set, get3) => ({
|
|
3236
|
+
market: [],
|
|
3237
|
+
marketMap: null,
|
|
3238
|
+
actions: {
|
|
3239
|
+
updateMarket: (data) => {
|
|
3240
|
+
const marketMap = {};
|
|
3241
|
+
data.forEach((item) => {
|
|
3242
|
+
marketMap[item.symbol] = item;
|
|
3243
|
+
});
|
|
3244
|
+
set({
|
|
3245
|
+
market: data,
|
|
3246
|
+
marketMap
|
|
3247
|
+
});
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
})
|
|
3251
|
+
);
|
|
3252
|
+
var useMarketList = () => {
|
|
3253
|
+
return useMarketStore((state) => state.market);
|
|
3254
|
+
};
|
|
3255
|
+
var useMarketMap = () => {
|
|
3256
|
+
return useMarketStore((state) => state.marketMap);
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
// src/orderly/useMarketsStream.ts
|
|
3234
3260
|
var useMarketsStream = () => {
|
|
3235
3261
|
const ws = useWS();
|
|
3236
|
-
const
|
|
3237
|
-
revalidateOnFocus: false
|
|
3238
|
-
});
|
|
3262
|
+
const futures = useMarketList();
|
|
3239
3263
|
const topic = "tickers";
|
|
3240
3264
|
const { data: tickers } = useSWRSubscription__default.default("tickers", (_, { next }) => {
|
|
3241
|
-
const unsubscribe = ws.subscribe(
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
{
|
|
3245
|
-
onMessage: (message) => {
|
|
3246
|
-
next(null, message);
|
|
3247
|
-
}
|
|
3248
|
-
// onUnsubscribe: () => {
|
|
3249
|
-
// return "markprices";
|
|
3250
|
-
// },
|
|
3251
|
-
// onError: (error: any) => {
|
|
3252
|
-
//
|
|
3253
|
-
// },
|
|
3265
|
+
const unsubscribe = ws.subscribe(topic, {
|
|
3266
|
+
onMessage: (message) => {
|
|
3267
|
+
next(null, message);
|
|
3254
3268
|
}
|
|
3255
|
-
);
|
|
3269
|
+
});
|
|
3256
3270
|
return () => {
|
|
3257
3271
|
unsubscribe?.();
|
|
3258
3272
|
};
|
|
@@ -4018,37 +4032,6 @@ var useMarkPrice = (symbol) => {
|
|
|
4018
4032
|
}, [symbol]);
|
|
4019
4033
|
return { data: price };
|
|
4020
4034
|
};
|
|
4021
|
-
var useFutures = () => {
|
|
4022
|
-
const { data, isLoading, error } = useQuery(
|
|
4023
|
-
`/v1/public/futures`,
|
|
4024
|
-
{
|
|
4025
|
-
revalidateOnFocus: false
|
|
4026
|
-
}
|
|
4027
|
-
);
|
|
4028
|
-
const [sortedData, setSortedData] = React2.useState(data);
|
|
4029
|
-
useWS();
|
|
4030
|
-
React2.useEffect(() => {
|
|
4031
|
-
}, []);
|
|
4032
|
-
React2.useEffect(() => {
|
|
4033
|
-
if (data) {
|
|
4034
|
-
const sortedData2 = data.sort((a, b) => {
|
|
4035
|
-
return 0;
|
|
4036
|
-
});
|
|
4037
|
-
setSortedData(sortedData2);
|
|
4038
|
-
}
|
|
4039
|
-
}, [data]);
|
|
4040
|
-
const sortBy = React2.useCallback((key) => {
|
|
4041
|
-
}, [data]);
|
|
4042
|
-
const filterBy = React2.useCallback((key) => {
|
|
4043
|
-
}, [data]);
|
|
4044
|
-
return {
|
|
4045
|
-
data: sortedData,
|
|
4046
|
-
sortBy,
|
|
4047
|
-
filterBy,
|
|
4048
|
-
isLoading,
|
|
4049
|
-
error
|
|
4050
|
-
};
|
|
4051
|
-
};
|
|
4052
4035
|
var useIndexPrice = (symbol) => {
|
|
4053
4036
|
symbol = symbol.replace("PERP", "SPOT");
|
|
4054
4037
|
const symbolRef = React2.useRef(symbol);
|
|
@@ -4126,24 +4109,17 @@ var useTickerStream = (symbol) => {
|
|
|
4126
4109
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
4127
4110
|
const { data: indexPrice } = useIndexPrice(symbol);
|
|
4128
4111
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
4129
|
-
const
|
|
4112
|
+
const marketMap = useMarketMap();
|
|
4130
4113
|
const value = React2.useMemo(() => {
|
|
4131
4114
|
if (!info)
|
|
4132
4115
|
return null;
|
|
4133
4116
|
if (!ticker || ticker.symbol !== symbol)
|
|
4134
4117
|
return info;
|
|
4135
|
-
const futureIndex = futures?.findIndex(
|
|
4136
|
-
(item) => item.symbol === symbol
|
|
4137
|
-
);
|
|
4138
|
-
let _oi = openInterest;
|
|
4139
|
-
if (!_oi && futureIndex !== -1 && futures) {
|
|
4140
|
-
_oi = futures[futureIndex].open_interest;
|
|
4141
|
-
}
|
|
4142
4118
|
const config = {
|
|
4143
4119
|
...info,
|
|
4144
4120
|
mark_price: markPrice,
|
|
4145
4121
|
index_price: indexPrice,
|
|
4146
|
-
open_interest:
|
|
4122
|
+
open_interest: openInterest || marketMap?.[symbol]?.open_interest
|
|
4147
4123
|
};
|
|
4148
4124
|
if (ticker.open !== void 0) {
|
|
4149
4125
|
config["24h_open"] = ticker.open;
|
|
@@ -4166,7 +4142,7 @@ var useTickerStream = (symbol) => {
|
|
|
4166
4142
|
config["24h_change"] = new utils.Decimal(ticker.close).minus(ticker.open).toNumber();
|
|
4167
4143
|
}
|
|
4168
4144
|
return config;
|
|
4169
|
-
}, [info, symbol, ticker,
|
|
4145
|
+
}, [info, symbol, ticker, openInterest, marketMap]);
|
|
4170
4146
|
return value;
|
|
4171
4147
|
};
|
|
4172
4148
|
|
|
@@ -10975,54 +10951,46 @@ var useTokenInfo = (token) => {
|
|
|
10975
10951
|
return tokensInfo?.find((item) => item.token === token);
|
|
10976
10952
|
}, [tokensInfo, token]);
|
|
10977
10953
|
};
|
|
10978
|
-
var
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
//
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
immer$1.produce((state) => {
|
|
10998
|
-
state.market = data;
|
|
10999
|
-
})
|
|
11000
|
-
);
|
|
11001
|
-
}
|
|
10954
|
+
var useFutures = () => {
|
|
10955
|
+
const { dataAdapter } = useOrderlyContext();
|
|
10956
|
+
const { data } = useQuery("/v1/public/futures", {
|
|
10957
|
+
// 24 hours
|
|
10958
|
+
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
10959
|
+
revalidateOnFocus: true,
|
|
10960
|
+
// 24 hours
|
|
10961
|
+
dedupingInterval: 1e3 * 60 * 60 * 24
|
|
10962
|
+
// onSuccess will not be called, because /v1/public/futures trigger multiple times
|
|
10963
|
+
// onSuccess(data: API.MarketInfo[]) {
|
|
10964
|
+
// if (!data || !data?.length) {
|
|
10965
|
+
// return [];
|
|
10966
|
+
// }
|
|
10967
|
+
// updateMarket(data as API.MarketInfoExt[]);
|
|
10968
|
+
// },
|
|
10969
|
+
});
|
|
10970
|
+
const futures = React2.useMemo(() => {
|
|
10971
|
+
if (Array.isArray(data)) {
|
|
10972
|
+
return typeof dataAdapter?.symbolList === "function" ? dataAdapter.symbolList(data) : data;
|
|
11002
10973
|
}
|
|
11003
|
-
|
|
11004
|
-
);
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
};
|
|
11008
|
-
var useMarketMap = () => {
|
|
11009
|
-
return useMarketStore((state) => state.marketMap);
|
|
10974
|
+
return [];
|
|
10975
|
+
}, [data, dataAdapter?.symbolList]);
|
|
10976
|
+
return {
|
|
10977
|
+
data: futures
|
|
10978
|
+
};
|
|
11010
10979
|
};
|
|
11011
10980
|
|
|
11012
10981
|
// src/orderly/usePublicDataObserver.ts
|
|
11013
10982
|
var publicQueryOptions = {
|
|
10983
|
+
// 24 hours, not effective, because revalidateOnFocus is false
|
|
11014
10984
|
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
11015
10985
|
revalidateOnFocus: false,
|
|
10986
|
+
// 24 hours
|
|
11016
10987
|
dedupingInterval: 1e3 * 60 * 60 * 24
|
|
11017
10988
|
};
|
|
11018
10989
|
var usePublicDataObserver = () => {
|
|
11019
10990
|
const { setSymbolsInfo, setFundingRates, setRwaSymbolsInfo } = useAppStore(
|
|
11020
10991
|
(state) => state.actions
|
|
11021
10992
|
);
|
|
11022
|
-
const { updateMarket } = useMarketStore((state) => state.actions);
|
|
11023
10993
|
const symbols = useSymbolStore((state) => state.data);
|
|
11024
|
-
const { dataAdapter } = useOrderlyContext();
|
|
11025
|
-
const resolveList = typeof dataAdapter?.symbolList === "function" ? dataAdapter.symbolList : (oriVal) => oriVal;
|
|
11026
10994
|
React2.useEffect(() => {
|
|
11027
10995
|
if (!symbols || !symbols?.length) {
|
|
11028
10996
|
return;
|
|
@@ -11083,23 +11051,11 @@ var usePublicDataObserver = () => {
|
|
|
11083
11051
|
setFundingRates(obj);
|
|
11084
11052
|
}
|
|
11085
11053
|
});
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
return [];
|
|
11092
|
-
}
|
|
11093
|
-
updateMarket(data);
|
|
11094
|
-
},
|
|
11095
|
-
formatter(data) {
|
|
11096
|
-
const rowsData = data.rows;
|
|
11097
|
-
if (Array.isArray(rowsData)) {
|
|
11098
|
-
return resolveList(rowsData);
|
|
11099
|
-
}
|
|
11100
|
-
return resolveList(data);
|
|
11101
|
-
}
|
|
11102
|
-
});
|
|
11054
|
+
const { data: futures } = useFutures();
|
|
11055
|
+
const { updateMarket } = useMarketStore((state) => state.actions);
|
|
11056
|
+
React2.useEffect(() => {
|
|
11057
|
+
updateMarket(futures);
|
|
11058
|
+
}, [futures]);
|
|
11103
11059
|
};
|
|
11104
11060
|
function getEstFundingRate(data) {
|
|
11105
11061
|
if (!data) {
|