@orderly.network/hooks 1.0.25-alpha.8 → 1.0.25
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 +410 -0
- package/dist/index.d.ts +410 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
|
+
export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
|
|
3
|
+
import * as swr__internal from 'swr/_internal';
|
|
4
|
+
import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
|
|
5
|
+
import * as swr_infinite from 'swr/infinite';
|
|
6
|
+
import { SWRInfiniteKeyLoader, SWRInfiniteConfiguration } from 'swr/infinite';
|
|
7
|
+
import * as _orderly_network_core from '@orderly.network/core';
|
|
8
|
+
import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract } from '@orderly.network/core';
|
|
9
|
+
export { default as useConstant } from 'use-constant';
|
|
10
|
+
import { WS } from '@orderly.network/net';
|
|
11
|
+
import * as react from 'react';
|
|
12
|
+
import { PropsWithChildren } from 'react';
|
|
13
|
+
import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus } from '@orderly.network/types';
|
|
14
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
15
|
+
import * as swr_subscription from 'swr/subscription';
|
|
16
|
+
import { Decimal } from '@orderly.network/utils';
|
|
17
|
+
export * from 'use-debounce';
|
|
18
|
+
|
|
19
|
+
declare global {
|
|
20
|
+
interface Window {
|
|
21
|
+
__ORDERLY_VERSION__?: {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare const _default: "1.0.25";
|
|
27
|
+
|
|
28
|
+
declare type useQueryOptions<T> = SWRConfiguration & {
|
|
29
|
+
formatter?: (data: any) => T;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* useQuery
|
|
34
|
+
* @description for public api
|
|
35
|
+
* @param query
|
|
36
|
+
* @param options
|
|
37
|
+
*/
|
|
38
|
+
declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* useQuery
|
|
42
|
+
* @description for public api
|
|
43
|
+
* @param query
|
|
44
|
+
* @param options
|
|
45
|
+
*/
|
|
46
|
+
declare const useLazyQuery: <T, R = any>(query: Parameters<typeof useSWR>["0"], options?: (SWRMutationConfiguration<any, any, swr__internal.Key, any, any> & {
|
|
47
|
+
formatter?: ((data: any) => R) | undefined;
|
|
48
|
+
init?: RequestInit | undefined;
|
|
49
|
+
}) | undefined) => SWRMutationResponse;
|
|
50
|
+
|
|
51
|
+
declare type HTTP_METHOD = "POST" | "PUT" | "DELETE";
|
|
52
|
+
declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E, swr__internal.Key, any, any> | undefined) => readonly [(data: any, params?: any, options?: any) => Promise<any>, {
|
|
53
|
+
readonly data: any;
|
|
54
|
+
readonly error: E | undefined;
|
|
55
|
+
readonly reset: () => void;
|
|
56
|
+
readonly isMutating: boolean;
|
|
57
|
+
}];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* usePrivateQuery
|
|
61
|
+
* @description for private api
|
|
62
|
+
* @param query
|
|
63
|
+
* @param options
|
|
64
|
+
*/
|
|
65
|
+
declare const usePrivateQuery: <T>(query: string, options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
|
|
66
|
+
|
|
67
|
+
declare const usePrivateInfiniteQuery: (getKey: SWRInfiniteKeyLoader, options?: (SWRInfiniteConfiguration<any, any, swr__internal.BareFetcher<any>> & {
|
|
68
|
+
formatter?: ((data: any) => any) | undefined;
|
|
69
|
+
}) | undefined) => swr_infinite.SWRInfiniteResponse<any, any>;
|
|
70
|
+
|
|
71
|
+
declare const useBoolean: (initialValue?: boolean) => [boolean, {
|
|
72
|
+
setTrue: () => void;
|
|
73
|
+
setFalse: () => void;
|
|
74
|
+
toggle: () => void;
|
|
75
|
+
}];
|
|
76
|
+
|
|
77
|
+
declare const useAccount: () => {
|
|
78
|
+
account: _orderly_network_core.Account;
|
|
79
|
+
state: AccountState;
|
|
80
|
+
createOrderlyKey: (remember: boolean) => Promise<any>;
|
|
81
|
+
createAccount: () => Promise<any>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
declare const useAccountInstance: () => Account;
|
|
85
|
+
|
|
86
|
+
declare const usePreLoadData: () => {
|
|
87
|
+
error: any;
|
|
88
|
+
done: boolean;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare const useEventEmitter: () => EventEmitter<string | symbol, any>;
|
|
92
|
+
|
|
93
|
+
declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
|
|
94
|
+
|
|
95
|
+
declare function useLocalStorage<T>(key: string, initialValue: T): [any, (value: T) => void];
|
|
96
|
+
|
|
97
|
+
declare const useWS: () => WS;
|
|
98
|
+
|
|
99
|
+
declare const useConfig: <T>(key?: ConfigKey | undefined, defaultValue?: T | undefined) => ConfigStore | T;
|
|
100
|
+
|
|
101
|
+
interface OrderlyConfigContextState {
|
|
102
|
+
fetcher?: (url: string, init: RequestInit) => Promise<any>;
|
|
103
|
+
configStore: ConfigStore;
|
|
104
|
+
keyStore: OrderlyKeyStore;
|
|
105
|
+
getWalletAdapter: getWalletAdapterFunc;
|
|
106
|
+
networkId: NetworkId;
|
|
107
|
+
/**
|
|
108
|
+
* @hidden
|
|
109
|
+
*/
|
|
110
|
+
onlyTestnet?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* @hidden
|
|
113
|
+
*/
|
|
114
|
+
enableSwapDeposit?: boolean;
|
|
115
|
+
}
|
|
116
|
+
declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
|
|
117
|
+
declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
|
|
118
|
+
|
|
119
|
+
declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
|
|
120
|
+
[K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
|
|
121
|
+
}[R];
|
|
122
|
+
interface ConfigProviderProps {
|
|
123
|
+
configStore?: ConfigStore;
|
|
124
|
+
keyStore?: OrderlyKeyStore;
|
|
125
|
+
contracts?: IContract;
|
|
126
|
+
getWalletAdapter?: getWalletAdapterFunc;
|
|
127
|
+
brokerId: string;
|
|
128
|
+
networkId: NetworkId;
|
|
129
|
+
enableSwapDeposit?: boolean;
|
|
130
|
+
}
|
|
131
|
+
declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
|
|
132
|
+
|
|
133
|
+
declare type ConnectedChain = {
|
|
134
|
+
id: string;
|
|
135
|
+
};
|
|
136
|
+
interface WalletConnectorContextState {
|
|
137
|
+
connect: () => Promise<any[]>;
|
|
138
|
+
disconnect: (options: any) => Promise<any[]>;
|
|
139
|
+
connecting: boolean;
|
|
140
|
+
setChain: (options: any) => Promise<any>;
|
|
141
|
+
chains: any[];
|
|
142
|
+
wallet: any;
|
|
143
|
+
connectedChain: ConnectedChain | null;
|
|
144
|
+
settingChain: boolean;
|
|
145
|
+
}
|
|
146
|
+
declare const WalletConnectorContext: react.Context<WalletConnectorContextState>;
|
|
147
|
+
declare const useWalletConnector: () => WalletConnectorContextState;
|
|
148
|
+
|
|
149
|
+
declare type OrderBookItem = number[];
|
|
150
|
+
declare type OrderbookData = {
|
|
151
|
+
asks: OrderBookItem[];
|
|
152
|
+
bids: OrderBookItem[];
|
|
153
|
+
};
|
|
154
|
+
declare type OrderbookOptions = {
|
|
155
|
+
level?: number;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* @name useOrderbookStream
|
|
159
|
+
* @description React hook that returns the current orderbook for a given market
|
|
160
|
+
*/
|
|
161
|
+
declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions | undefined) => ({
|
|
162
|
+
asks: OrderBookItem[];
|
|
163
|
+
bids: OrderBookItem[];
|
|
164
|
+
markPrice: any;
|
|
165
|
+
middlePrice: number[];
|
|
166
|
+
onDepthChange?: undefined;
|
|
167
|
+
depth?: undefined;
|
|
168
|
+
allDepths?: undefined;
|
|
169
|
+
isLoading?: undefined;
|
|
170
|
+
onItemClick?: undefined;
|
|
171
|
+
} | {
|
|
172
|
+
onDepthChange: (depth: number) => void;
|
|
173
|
+
depth: number | undefined;
|
|
174
|
+
allDepths: any[];
|
|
175
|
+
isLoading: boolean;
|
|
176
|
+
onItemClick: (item: OrderBookItem) => void;
|
|
177
|
+
asks?: undefined;
|
|
178
|
+
bids?: undefined;
|
|
179
|
+
markPrice?: undefined;
|
|
180
|
+
middlePrice?: undefined;
|
|
181
|
+
})[];
|
|
182
|
+
|
|
183
|
+
declare type UseOrderEntryOptions = {
|
|
184
|
+
commify?: boolean;
|
|
185
|
+
validate?: (data: OrderEntity) => {
|
|
186
|
+
[P in keyof OrderEntity]?: string;
|
|
187
|
+
} | null | undefined;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Create Order
|
|
191
|
+
* @param symbol
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions | undefined) => {
|
|
195
|
+
maxQty: number;
|
|
196
|
+
freeCollateral: number;
|
|
197
|
+
markPrice: any;
|
|
198
|
+
onSubmit: (values: OrderEntity) => Promise<any>;
|
|
199
|
+
submitting: boolean;
|
|
200
|
+
helper: {
|
|
201
|
+
calculate: (values: any, field: string, value: any) => unknown;
|
|
202
|
+
validator: (values: any) => any;
|
|
203
|
+
};
|
|
204
|
+
symbolConfig: any;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
declare const useSymbolsInfo: () => Record<string, any>;
|
|
208
|
+
|
|
209
|
+
declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
|
|
210
|
+
|
|
211
|
+
declare const useMarketsStream: () => {
|
|
212
|
+
data: WSMessage.Ticker[] | null;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
216
|
+
|
|
217
|
+
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
218
|
+
|
|
219
|
+
declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
220
|
+
|
|
221
|
+
declare const useLeverage: () => any;
|
|
222
|
+
|
|
223
|
+
declare const useTickerStream: (symbol: string) => API.MarketInfo;
|
|
224
|
+
|
|
225
|
+
declare const useFundingRate: (symbol: string) => {
|
|
226
|
+
est_funding_rate: string;
|
|
227
|
+
countDown: string;
|
|
228
|
+
symbol?: string | undefined;
|
|
229
|
+
est_funding_rate_timestamp?: number | undefined;
|
|
230
|
+
last_funding_rate?: number | undefined;
|
|
231
|
+
last_funding_rate_timestamp?: number | undefined;
|
|
232
|
+
next_funding_time?: number | undefined;
|
|
233
|
+
sum_unitary_funding?: number | undefined;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
declare const usePositionStream: (symbol?: string | undefined, options?: Partial<swr__internal.PublicConfiguration<any, any, swr__internal.BareFetcher<any>>> | undefined) => readonly [{
|
|
237
|
+
readonly rows: API.PositionExt[] | null;
|
|
238
|
+
readonly aggregated: any;
|
|
239
|
+
readonly totalCollateral: Decimal;
|
|
240
|
+
readonly totalValue: Decimal;
|
|
241
|
+
readonly totalUnrealizedROI: number;
|
|
242
|
+
}, any, {
|
|
243
|
+
readonly loading: false;
|
|
244
|
+
readonly error: any;
|
|
245
|
+
readonly loadMore: () => void;
|
|
246
|
+
readonly refresh: () => void;
|
|
247
|
+
}];
|
|
248
|
+
|
|
249
|
+
declare type Params = {
|
|
250
|
+
symbol?: string;
|
|
251
|
+
status?: OrderStatus;
|
|
252
|
+
size?: number;
|
|
253
|
+
side?: OrderSide;
|
|
254
|
+
};
|
|
255
|
+
declare const useOrderStream: (params: Params) => readonly [any[] | null, {
|
|
256
|
+
readonly total: any;
|
|
257
|
+
readonly isLoading: boolean;
|
|
258
|
+
readonly loadMore: () => void;
|
|
259
|
+
readonly cancelAllOrders: () => void;
|
|
260
|
+
readonly updateOrder: (orderId: string, order: OrderEntity) => Promise<any>;
|
|
261
|
+
readonly cancelOrder: (orderId: string, symbol?: string | undefined) => Promise<any>;
|
|
262
|
+
readonly errors: {
|
|
263
|
+
readonly cancelOrder: unknown;
|
|
264
|
+
readonly updateOrder: unknown;
|
|
265
|
+
};
|
|
266
|
+
readonly submitting: {
|
|
267
|
+
readonly cancelOrder: boolean;
|
|
268
|
+
readonly updateOrder: boolean;
|
|
269
|
+
};
|
|
270
|
+
}];
|
|
271
|
+
|
|
272
|
+
interface MarketTradeStreamOptions {
|
|
273
|
+
limit?: number;
|
|
274
|
+
}
|
|
275
|
+
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
276
|
+
data: API.Trade[];
|
|
277
|
+
isLoading: boolean;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
declare type CollateralOutputs = {
|
|
281
|
+
totalCollateral: number;
|
|
282
|
+
freeCollateral: number;
|
|
283
|
+
totalValue: number;
|
|
284
|
+
availableBalance: number;
|
|
285
|
+
unsettledPnL: number;
|
|
286
|
+
};
|
|
287
|
+
declare type Options = {
|
|
288
|
+
dp: number;
|
|
289
|
+
};
|
|
290
|
+
declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
291
|
+
|
|
292
|
+
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
293
|
+
|
|
294
|
+
declare const useMarginRatio: () => {
|
|
295
|
+
marginRatio: number;
|
|
296
|
+
currentLeverage: number;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
declare type inputOptions = {
|
|
300
|
+
filter?: (item: API.Chain) => boolean;
|
|
301
|
+
pick?: "dexs" | "network_infos" | "token_infos";
|
|
302
|
+
crossEnabled?: boolean;
|
|
303
|
+
/** if true, use wooSwap api, else use orderly api only */
|
|
304
|
+
wooSwapEnabled?: boolean;
|
|
305
|
+
};
|
|
306
|
+
declare const useChains: (networkId?: NetworkId | undefined, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
|
|
307
|
+
testnet: API.Chain[];
|
|
308
|
+
mainnet: API.Chain[];
|
|
309
|
+
}, {
|
|
310
|
+
readonly findByChainId: (chainId: number, field?: string | undefined) => (API.Chain & {
|
|
311
|
+
nativeToken?: API.TokenInfo | undefined;
|
|
312
|
+
}) | (<K extends never>(prop: K) => ((API.Chain & {
|
|
313
|
+
nativeToken?: API.TokenInfo | undefined;
|
|
314
|
+
}) | undefined)[K]) | undefined;
|
|
315
|
+
readonly error: any;
|
|
316
|
+
}];
|
|
317
|
+
|
|
318
|
+
declare const useChain: (token: string) => {
|
|
319
|
+
chains: API.Chain | null;
|
|
320
|
+
isLoading: boolean;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
declare const useWithdraw: () => {
|
|
324
|
+
withdraw: (inputs: {
|
|
325
|
+
chainId: number;
|
|
326
|
+
token: string;
|
|
327
|
+
amount: number;
|
|
328
|
+
}) => Promise<any>;
|
|
329
|
+
isLoading: boolean;
|
|
330
|
+
maxAmount: number;
|
|
331
|
+
availableBalance: number;
|
|
332
|
+
unsettledPnL: number;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
declare type useDepositOptions = {
|
|
336
|
+
address?: string;
|
|
337
|
+
decimals?: number;
|
|
338
|
+
crossChainRouteAddress?: string;
|
|
339
|
+
depositorAddress?: string;
|
|
340
|
+
networkId?: NetworkId;
|
|
341
|
+
srcChainId?: number;
|
|
342
|
+
srcToken?: string;
|
|
343
|
+
/**
|
|
344
|
+
* @hidden
|
|
345
|
+
*/
|
|
346
|
+
wooSwapEnabled?: boolean;
|
|
347
|
+
};
|
|
348
|
+
declare const useDeposit: (options?: useDepositOptions | undefined) => {
|
|
349
|
+
dst: {
|
|
350
|
+
symbol: string;
|
|
351
|
+
address: string | undefined;
|
|
352
|
+
decimals: number | undefined;
|
|
353
|
+
chainId: number;
|
|
354
|
+
network: string;
|
|
355
|
+
};
|
|
356
|
+
balance: string;
|
|
357
|
+
allowance: string;
|
|
358
|
+
isNativeToken: boolean;
|
|
359
|
+
balanceRevalidating: boolean;
|
|
360
|
+
allowanceRevalidating: boolean;
|
|
361
|
+
approve: (amount: string | undefined) => Promise<any>;
|
|
362
|
+
deposit: (amount: string) => Promise<any>;
|
|
363
|
+
fetchBalances: (tokens: API.TokenInfo[]) => Promise<void>;
|
|
364
|
+
fetchBalance: (address: string, decimals?: number | undefined) => Promise<string>;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
declare const useHoldingStream: () => {
|
|
368
|
+
data: API.Holding[] | undefined;
|
|
369
|
+
usdc: API.Holding | undefined;
|
|
370
|
+
isLoading: boolean;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
declare const useWalletSubscription: (options?: {
|
|
374
|
+
onMessage?: ((data: any) => void) | undefined;
|
|
375
|
+
} | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
376
|
+
|
|
377
|
+
declare const useSettleSubscription: (options?: {
|
|
378
|
+
onMessage?: ((data: any) => void) | undefined;
|
|
379
|
+
} | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
380
|
+
|
|
381
|
+
declare const usePrivateDataObserver: () => void;
|
|
382
|
+
|
|
383
|
+
declare function useMediaQuery(query: string): boolean;
|
|
384
|
+
|
|
385
|
+
/** @hidden */
|
|
386
|
+
declare const useWooSwapQuery: () => {
|
|
387
|
+
query: (inputs: any) => Promise<any> | undefined;
|
|
388
|
+
loading: boolean;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/** @hidden */
|
|
392
|
+
declare const useWooCrossSwapQuery: () => {
|
|
393
|
+
query: (inputs: {
|
|
394
|
+
srcNetwork: string;
|
|
395
|
+
srcToken: string;
|
|
396
|
+
amount: bigint;
|
|
397
|
+
slippage: number;
|
|
398
|
+
dstToken: string;
|
|
399
|
+
crossChainRouteAddress: string;
|
|
400
|
+
}) => Promise<any> | undefined;
|
|
401
|
+
loading: boolean;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
/** @hidden */
|
|
405
|
+
declare const useCrossSwap: () => any;
|
|
406
|
+
|
|
407
|
+
/** @hidden */
|
|
408
|
+
declare const useSwap: () => any;
|
|
409
|
+
|
|
410
|
+
export { ConfigProviderProps, OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery, _default as version };
|