@orderly.network/hooks 0.0.53 → 0.0.55

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.
@@ -0,0 +1,451 @@
1
+ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
+ export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
3
+ import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
4
+ import * as _orderly_network_core from '@orderly.network/core';
5
+ import { Account, AccountState, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract, EventEmitter } from '@orderly.network/core';
6
+ import * as react from 'react';
7
+ import react__default, { FC, PropsWithChildren } from 'react';
8
+ export { default as useConstant } from 'use-constant';
9
+ import { WS } from '@orderly.network/net';
10
+ import { OrderSide, OrderEntity, API, WSMessage } from '@orderly.network/types';
11
+ import * as swr__internal from 'swr/_internal';
12
+ import * as swr_subscription from 'swr/subscription';
13
+ export * from 'use-debounce';
14
+
15
+ type useQueryOptions<T> = SWRConfiguration & {
16
+ formatter?: (data: any) => T;
17
+ };
18
+
19
+ /**
20
+ * useQuery
21
+ * @description for public api
22
+ * @param query
23
+ * @param options
24
+ */
25
+ declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
26
+
27
+ /**
28
+ * useQuery
29
+ * @description for public api
30
+ * @param query
31
+ * @param options
32
+ */
33
+ declare const useLazyQuery: <T, R = any>(query: Parameters<typeof useSWR>["0"], options?: (SWRMutationConfiguration<any, any> & {
34
+ formatter?: ((data: any) => R) | undefined;
35
+ init?: RequestInit | undefined;
36
+ }) | undefined) => SWRMutationResponse;
37
+
38
+ type HTTP_METHOD = "POST" | "PUT" | "DELETE";
39
+ declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E> | undefined) => [any, any];
40
+
41
+ /**
42
+ * usePrivateQuery
43
+ * @description for private api
44
+ * @param query
45
+ * @param options
46
+ */
47
+ declare const usePrivateQuery: <T>(query: string, options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
48
+
49
+ declare const useBoolean: (initialValue?: boolean) => [boolean, {
50
+ setTrue: () => void;
51
+ setFalse: () => void;
52
+ toggle: () => void;
53
+ }];
54
+
55
+ declare const useTradingView: () => {};
56
+
57
+ declare const usePrivateObserve: <T>() => {
58
+ data: T | undefined;
59
+ };
60
+
61
+ declare const useTopicObserve: <T>(topic: string) => {
62
+ data: T | undefined;
63
+ };
64
+
65
+ declare const useAccount: () => {
66
+ account: Account;
67
+ state: AccountState;
68
+ login: (address: string) => void;
69
+ createOrderlyKey: (remember: boolean) => Promise<string>;
70
+ createAccount: () => Promise<string>;
71
+ disconnect: () => Promise<void>;
72
+ connect: () => Promise<any>;
73
+ setChain: (chainId: number) => Promise<any>;
74
+ };
75
+
76
+ declare const useAccountInstance: () => Account;
77
+
78
+ interface OrderlyAppConfig {
79
+ logoUrl: string;
80
+ theme: any;
81
+ }
82
+ type AppStateErrors = {
83
+ ChainNetworkNotSupport: boolean;
84
+ IpNotSupport: boolean;
85
+ NetworkError: boolean;
86
+ };
87
+ interface OrderlyContextState extends OrderlyAppConfig {
88
+ fetcher?: (url: string, init: RequestInit) => Promise<any>;
89
+ apiBaseUrl: string;
90
+ klineDataUrl: string;
91
+ configStore: ConfigStore;
92
+ keyStore: OrderlyKeyStore;
93
+ getWalletAdapter: getWalletAdapterFunc;
94
+ contractManager: IContract;
95
+ networkId: string;
96
+ brokerId: string;
97
+ onWalletConnect?: () => Promise<any>;
98
+ onWalletDisconnect?: () => Promise<any>;
99
+ onSetChain?: (chainId: number) => Promise<any>;
100
+ errors: AppStateErrors;
101
+ }
102
+ declare const OrderlyContext: react.Context<OrderlyContextState>;
103
+ declare const OrderlyProvider: react.Provider<OrderlyContextState>;
104
+
105
+ declare const useAppState: () => {
106
+ errors: AppStateErrors;
107
+ };
108
+
109
+ declare const usePreLoadData: () => {
110
+ error: any;
111
+ done: boolean;
112
+ };
113
+
114
+ declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
115
+
116
+ declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
117
+
118
+ declare function useLocalStorage<T>(key: string, initialValue: T): [T, any];
119
+
120
+ type useRunOnceProps = {
121
+ fn: () => any;
122
+ sessionKey?: string;
123
+ };
124
+ declare const useRunOnce: react__default.FC<useRunOnceProps>;
125
+
126
+ declare const DataSourceProvider: FC<PropsWithChildren>;
127
+
128
+ declare const useWS: () => WS;
129
+
130
+ declare const useConfig: () => _orderly_network_core.ConfigStore;
131
+
132
+ type OrderBookItem = number[];
133
+ type OrderbookData = {
134
+ asks: OrderBookItem[];
135
+ bids: OrderBookItem[];
136
+ };
137
+ type OrderbookOptions = {
138
+ level?: number;
139
+ };
140
+ /**
141
+ * @name useOrderbookStream
142
+ * @description React hook that returns the current orderbook for a given market
143
+ */
144
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
145
+ asks: OrderBookItem[];
146
+ bids: OrderBookItem[];
147
+ markPrice: any;
148
+ middlePrice: any[];
149
+ onDepthChange?: undefined;
150
+ depth?: undefined;
151
+ allDepths?: undefined;
152
+ isLoading?: undefined;
153
+ onItemClick?: undefined;
154
+ } | {
155
+ onDepthChange: (depth: number) => void;
156
+ depth: number | undefined;
157
+ allDepths: any[];
158
+ isLoading: boolean;
159
+ onItemClick: (item: OrderBookItem) => void;
160
+ asks?: undefined;
161
+ bids?: undefined;
162
+ markPrice?: undefined;
163
+ middlePrice?: undefined;
164
+ })[];
165
+
166
+ interface OrderEntryReturn {
167
+ onSubmit: (values: OrderEntity) => Promise<any>;
168
+ maxQty: number;
169
+ freeCollateral: number;
170
+ markPrice: number;
171
+ symbolConfig: API.SymbolExt;
172
+ helper: {
173
+ calculate: (values: any, field: string, value: any) => any;
174
+ validator: (values: any) => any;
175
+ };
176
+ }
177
+ type UseOrderEntryOptions = {
178
+ commify?: boolean;
179
+ validate?: (data: OrderEntity) => {
180
+ [P in keyof OrderEntity]?: string;
181
+ } | null | undefined;
182
+ };
183
+ /**
184
+ * 创建订单
185
+ * @param symbol
186
+ * @returns
187
+ */
188
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
189
+
190
+ interface MarketInfo {
191
+ }
192
+ declare const useFetures: () => {
193
+ data: MarketInfo[] | undefined;
194
+ sortBy: (key: string) => void;
195
+ filterBy: (key: string) => void;
196
+ isLoading: boolean;
197
+ error: any;
198
+ };
199
+
200
+ declare const useSymbolsInfo: () => any;
201
+
202
+ declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
203
+
204
+ declare const useTokenInfo: () => any;
205
+
206
+ declare const useMarketsStream: () => {
207
+ data: WSMessage.Ticker[] | null;
208
+ };
209
+
210
+ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
211
+
212
+ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
213
+
214
+ declare const useLeverage: () => ({
215
+ update: (data: any) => any;
216
+ } | undefined)[];
217
+
218
+ declare const useTickerStream: (symbol: string) => any;
219
+
220
+ declare const useFundingRate: (symbol: string) => {
221
+ est_funding_rate: string;
222
+ countDown: string;
223
+ symbol?: string | undefined;
224
+ est_funding_rate_timestamp?: number | undefined;
225
+ last_funding_rate?: number | undefined;
226
+ last_funding_rate_timestamp?: number | undefined;
227
+ next_funding_time?: number | undefined;
228
+ sum_unitary_funding?: number | undefined;
229
+ };
230
+
231
+ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
232
+
233
+ declare enum OrderStatus {
234
+ FILLED = "FILLED",
235
+ PARTIAL_FILLED = "PARTIAL_FILLED",
236
+ CANCELED = "CANCELED",
237
+ NEW = "NEW",
238
+ COMPLETED = "COMPLETED"
239
+ }
240
+ declare const useOrderStream: ({ status, symbol, side, size, }?: {
241
+ symbol?: string | undefined;
242
+ status?: OrderStatus | undefined;
243
+ size?: number | undefined;
244
+ side?: OrderSide | undefined;
245
+ }) => (any[] | {
246
+ cancelAllOrders: () => void;
247
+ updateOrder: (orderId: string, order: OrderEntity) => any;
248
+ cancelOrder: (orderId: string, symbol?: string) => any;
249
+ } | null)[];
250
+
251
+ interface MarketTradeStreamOptions {
252
+ limit?: number;
253
+ }
254
+ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
255
+ data: API.Trade[];
256
+ isLoading: boolean;
257
+ };
258
+
259
+ type CollateralOutputs = {
260
+ totalCollateral: number;
261
+ freeCollateral: number;
262
+ totalValue: number;
263
+ availableBalance: number;
264
+ unsettledPnL: number;
265
+ };
266
+ /**
267
+ * 用户保证金
268
+ * @returns
269
+ */
270
+ type Options = {
271
+ dp: number;
272
+ };
273
+ declare const useCollateral: (options?: Options) => CollateralOutputs;
274
+
275
+ declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
276
+
277
+ declare const useMarginRatio: () => {
278
+ marginRatio: number;
279
+ currentLeverage: number;
280
+ };
281
+
282
+ type inputOptions = {
283
+ filter?: (item: API.Chain) => boolean;
284
+ pick?: "dexs" | "network_infos" | "token_infos";
285
+ crossEnabled?: boolean;
286
+ wooSwapEnabled?: boolean;
287
+ };
288
+ declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions & SWRConfiguration) => any[];
289
+
290
+ declare const useChain: (token: string) => {
291
+ chains: API.Chain | null;
292
+ isLoading: boolean;
293
+ };
294
+
295
+ declare const useWithdraw: () => {
296
+ withdraw: (inputs: {
297
+ chainId: number;
298
+ token: string;
299
+ amount: number;
300
+ }) => Promise<any>;
301
+ isLoading: boolean;
302
+ maxAmount: number;
303
+ availableBalance: number;
304
+ unsettledPnL: number;
305
+ };
306
+
307
+ type useDepositOptions = {
308
+ address?: string;
309
+ decimals?: number;
310
+ };
311
+ declare const useDeposit: (options?: useDepositOptions) => {
312
+ dst: {
313
+ symbol: string;
314
+ address: string;
315
+ decimals: number;
316
+ network: string;
317
+ chainId: number;
318
+ };
319
+ balance: string;
320
+ allowance: string;
321
+ isNativeToken: boolean;
322
+ balanceRevalidating: boolean;
323
+ allowanceRevalidating: boolean;
324
+ approve: (amount: string | undefined) => Promise<any>;
325
+ deposit: (amount: string) => Promise<any>;
326
+ fetchBalances: (tokens: API.TokenInfo[]) => Promise<void>;
327
+ fetchBalance: (address: string, decimals?: number) => Promise<string>;
328
+ };
329
+
330
+ declare const useHoldingStream: () => {
331
+ data: API.Holding[] | undefined;
332
+ usdc: API.Holding | undefined;
333
+ isLoading: boolean;
334
+ };
335
+
336
+ declare const useWalletSubscription: (options?: {
337
+ onMessage?: ((data: any) => void) | undefined;
338
+ } | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
339
+
340
+ declare const useBalance: () => any;
341
+
342
+ declare const usePrivateDataObserver: () => void;
343
+
344
+ declare const useExecutionReport: () => any;
345
+
346
+ interface Info {
347
+ symbol: string;
348
+ quote_min: number;
349
+ quote_max: number;
350
+ quote_tick: number;
351
+ base_min: number;
352
+ base_max: number;
353
+ base_tick: number;
354
+ min_notional: number;
355
+ price_range: number;
356
+ created_time: number;
357
+ updated_time: number;
358
+ }
359
+ /**
360
+ * useInfo
361
+ * @returns
362
+ */
363
+ declare const useInfo: () => swr__internal.SWRResponse<Info[], any, any>;
364
+
365
+ interface Token {
366
+ token: string;
367
+ token_account_id: string;
368
+ decimals: number;
369
+ minimum_increment: number;
370
+ }
371
+ /**
372
+ * useToken
373
+ * @description get token info
374
+ */
375
+ declare const useToken: () => swr__internal.SWRResponse<Token[], any, any>;
376
+
377
+ interface FundingRate {
378
+ symbol: string;
379
+ est_funding_rate: number;
380
+ est_funding_rate_timestamp: number;
381
+ last_funding_rate: number;
382
+ last_funding_rate_timestamp: number;
383
+ next_funding_time: number;
384
+ sum_unitary_funding: number;
385
+ }
386
+ /**
387
+ * FundingRate
388
+ * @param symbol
389
+ */
390
+ declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
391
+
392
+ declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
393
+ declare const index_useInfo: typeof useInfo;
394
+ declare const index_useToken: typeof useToken;
395
+ declare namespace index {
396
+ export {
397
+ index_useFundingRateBySymbol as useFundingRateBySymbol,
398
+ index_useInfo as useInfo,
399
+ index_useToken as useToken,
400
+ };
401
+ }
402
+
403
+ declare const useWooSwapQuery: () => {
404
+ query: (inputs: any) => Promise<any> | undefined;
405
+ loading: boolean;
406
+ };
407
+
408
+ declare const useWooCrossSwapQuery: () => {
409
+ query: (inputs: any) => Promise<any> | undefined;
410
+ loading: boolean;
411
+ };
412
+
413
+ declare enum MessageStatus {
414
+ INITIALIZING = "WAITTING",
415
+ INFLIGHT = "INFLIGHT",
416
+ DELIVERED = "DELIVERED",
417
+ FAILED = "FAILED"
418
+ }
419
+ declare const useCrossSwap: () => {
420
+ swap: (inputs: {
421
+ address: string;
422
+ src: {
423
+ fromToken: string;
424
+ fromAmount: string;
425
+ bridgeToken: string;
426
+ minBridgeAmount: string;
427
+ };
428
+ dst: {
429
+ chainId: string;
430
+ bridgedToken: string;
431
+ toToken: string;
432
+ minToAmount: string;
433
+ airdropNativeAmount: string;
434
+ };
435
+ }) => Promise<{} | undefined>;
436
+ loading: boolean;
437
+ status: MessageStatus;
438
+ message: any;
439
+ };
440
+
441
+ declare const useSwap: () => {
442
+ swap: (inputs: {
443
+ fromToken: string;
444
+ fromAmount: string;
445
+ toToken: string;
446
+ minToAmount: string;
447
+ }) => Promise<{} | undefined>;
448
+ loading: boolean;
449
+ };
450
+
451
+ 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, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };