@orderly.network/hooks 1.0.29 → 1.1.1

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 CHANGED
@@ -1,16 +1,18 @@
1
1
  import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
3
- import * as swr__internal from 'swr/_internal';
4
3
  import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
5
4
  import * as swr_infinite from 'swr/infinite';
6
5
  import { SWRInfiniteKeyLoader, SWRInfiniteConfiguration } from 'swr/infinite';
6
+ import * as swr__internal from 'swr/_internal';
7
7
  import * as _orderly_network_core from '@orderly.network/core';
8
8
  import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract } from '@orderly.network/core';
9
+ export { WalletAdapter } from '@orderly.network/core';
9
10
  export { default as useConstant } from 'use-constant';
10
11
  import { WS } from '@orderly.network/net';
11
12
  import * as react from 'react';
12
13
  import { PropsWithChildren } from 'react';
13
- import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus } from '@orderly.network/types';
14
+ import * as _orderly_network_types from '@orderly.network/types';
15
+ import { NetworkId, OrderEntity, OrderSide, API, WSMessage, OrderStatus } from '@orderly.network/types';
14
16
  import * as react_jsx_runtime from 'react/jsx-runtime';
15
17
  import * as swr_subscription from 'swr/subscription';
16
18
  import { Decimal } from '@orderly.network/utils';
@@ -23,9 +25,9 @@ declare global {
23
25
  };
24
26
  }
25
27
  }
26
- declare const _default: "1.0.29";
28
+ declare const _default: "1.1.1";
27
29
 
28
- declare type useQueryOptions<T> = SWRConfiguration & {
30
+ type useQueryOptions<T> = SWRConfiguration & {
29
31
  formatter?: (data: any) => T;
30
32
  };
31
33
 
@@ -43,13 +45,13 @@ declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: use
43
45
  * @param query
44
46
  * @param options
45
47
  */
46
- declare const useLazyQuery: <T, R = any>(query: Parameters<typeof useSWR>["0"], options?: (SWRMutationConfiguration<any, any, swr__internal.Key, any, any> & {
48
+ declare const useLazyQuery: <T, R = any>(query: Parameters<typeof useSWR>["0"], options?: (SWRMutationConfiguration<any, any> & {
47
49
  formatter?: ((data: any) => R) | undefined;
48
50
  init?: RequestInit | undefined;
49
51
  }) | undefined) => SWRMutationResponse;
50
52
 
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
+ type HTTP_METHOD = "POST" | "PUT" | "DELETE";
54
+ declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E> | undefined) => readonly [(data: any, params?: any, options?: any) => Promise<any>, {
53
55
  readonly data: any;
54
56
  readonly error: E | undefined;
55
57
  readonly reset: () => void;
@@ -96,7 +98,7 @@ declare function useLocalStorage<T>(key: string, initialValue: T): [any, (value:
96
98
 
97
99
  declare const useWS: () => WS;
98
100
 
99
- declare const useConfig: <T>(key?: ConfigKey | undefined, defaultValue?: T | undefined) => ConfigStore | T;
101
+ declare const useConfig: <T>(key?: ConfigKey, defaultValue?: T | undefined) => ConfigStore | T;
100
102
 
101
103
  interface OrderlyConfigContextState {
102
104
  fetcher?: (url: string, init: RequestInit) => Promise<any>;
@@ -116,7 +118,7 @@ interface OrderlyConfigContextState {
116
118
  declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
117
119
  declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
118
120
 
119
- declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
121
+ type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
120
122
  [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
121
123
  }[R];
122
124
  interface ConfigProviderProps {
@@ -130,14 +132,27 @@ interface ConfigProviderProps {
130
132
  }
131
133
  declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
132
134
 
133
- declare type ConnectedChain = {
134
- id: string;
135
+ type ConnectedChain = {
136
+ id: number | string;
135
137
  };
138
+ type WalletAccount = {
139
+ address: string;
140
+ };
141
+ interface WalletState {
142
+ label: string;
143
+ icon: string;
144
+ provider: any;
145
+ accounts: WalletAccount[];
146
+ chains: ConnectedChain[];
147
+ instance?: unknown;
148
+ }
136
149
  interface WalletConnectorContextState {
137
- connect: () => Promise<any[]>;
150
+ connect: () => Promise<WalletState[]>;
138
151
  disconnect: (options: any) => Promise<any[]>;
139
152
  connecting: boolean;
140
- setChain: (options: any) => Promise<any>;
153
+ setChain: (options: {
154
+ chainId: string | number;
155
+ }) => Promise<any>;
141
156
  chains: any[];
142
157
  wallet: any;
143
158
  connectedChain: ConnectedChain | null;
@@ -146,19 +161,19 @@ interface WalletConnectorContextState {
146
161
  declare const WalletConnectorContext: react.Context<WalletConnectorContextState>;
147
162
  declare const useWalletConnector: () => WalletConnectorContextState;
148
163
 
149
- declare type OrderBookItem = number[];
150
- declare type OrderbookData = {
164
+ type OrderBookItem = number[];
165
+ type OrderbookData = {
151
166
  asks: OrderBookItem[];
152
167
  bids: OrderBookItem[];
153
168
  };
154
- declare type OrderbookOptions = {
169
+ type OrderbookOptions = {
155
170
  level?: number;
156
171
  };
157
172
  /**
158
173
  * @name useOrderbookStream
159
174
  * @description React hook that returns the current orderbook for a given market
160
175
  */
161
- declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions | undefined) => ({
176
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
162
177
  asks: OrderBookItem[];
163
178
  bids: OrderBookItem[];
164
179
  markPrice: any;
@@ -180,29 +195,58 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
180
195
  middlePrice?: undefined;
181
196
  })[];
182
197
 
183
- declare type UseOrderEntryOptions = {
198
+ type UseOrderEntryOptions = {
184
199
  commify?: boolean;
200
+ watchOrderbook?: boolean;
185
201
  validate?: (data: OrderEntity) => {
186
202
  [P in keyof OrderEntity]?: string;
187
203
  } | null | undefined;
188
204
  };
189
- /**
190
- * Create Order
191
- * @param symbol
192
- * @returns
193
- */
194
- declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions | undefined) => {
205
+ type UseOrderEntryMetaState = {
206
+ errors: {
207
+ [P in keyof OrderEntity]?: {
208
+ type: string;
209
+ message: string;
210
+ };
211
+ } | null | undefined;
212
+ dirty: {
213
+ [P in keyof OrderEntity]?: boolean;
214
+ } | null | undefined;
215
+ submitted: boolean;
216
+ };
217
+ type UseOrderEntryReturn = {
195
218
  maxQty: number;
196
219
  freeCollateral: number;
197
- markPrice: any;
198
- onSubmit: (values: OrderEntity) => Promise<any>;
220
+ markPrice: number;
221
+ estLiqPrice?: number | null;
222
+ estLeverage?: number | null;
223
+ onSubmit: (order: OrderEntity) => Promise<any>;
224
+ submit: () => Promise<OrderEntity>;
199
225
  submitting: boolean;
226
+ formattedOrder: Partial<OrderEntity>;
200
227
  helper: {
201
- calculate: (values: any, field: string, value: any) => unknown;
202
- validator: (values: any) => any;
228
+ calculate: (values: Partial<OrderEntity>, field: keyof OrderEntity, value: any) => Partial<OrderEntity>;
229
+ validator: (values: Partial<OrderEntity>) => any;
203
230
  };
204
- symbolConfig: any;
231
+ metaState: UseOrderEntryMetaState;
232
+ symbolConfig: API.SymbolExt;
205
233
  };
234
+ type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">>;
235
+ /**
236
+ * Create Order
237
+ * @example
238
+ * ```tsx
239
+ * const { formattedOrder, onSubmit, helper } = useOrderEntry({
240
+ * symbol: "PERP_ETH_USDC",
241
+ * side: OrderSide.BUY,
242
+ * order_type: OrderType.LIMIT,
243
+ * order_price: 10000,
244
+ * order_quantity: 1,
245
+ * });
246
+ * ```
247
+ */
248
+ declare function useOrderEntry(order: OrderParams, options?: UseOrderEntryOptions): UseOrderEntryReturn;
249
+ declare function useOrderEntry(symbol: string, side: OrderSide, reduceOnly: boolean): UseOrderEntryReturn;
206
250
 
207
251
  declare const useSymbolsInfo: () => Record<string, any>;
208
252
 
@@ -212,6 +256,41 @@ declare const useMarketsStream: () => {
212
256
  data: WSMessage.Ticker[] | null;
213
257
  };
214
258
 
259
+ declare enum MarketsType {
260
+ FAVORITES = 0,
261
+ RECENT = 1,
262
+ ALL = 2
263
+ }
264
+ interface FavoriteTab {
265
+ name: string;
266
+ id: number;
267
+ }
268
+ interface Favorite {
269
+ name: string;
270
+ tabs: FavoriteTab[];
271
+ }
272
+ interface Recent {
273
+ name: string;
274
+ }
275
+ declare const useMarkets: (type: MarketsType) => readonly [_orderly_network_types.WSMessage.Ticker[], {
276
+ readonly favoriteTabs: FavoriteTab[];
277
+ readonly favorites: {
278
+ tabs: FavoriteTab[];
279
+ name: string;
280
+ }[];
281
+ readonly recent: Recent[];
282
+ readonly addToHistory: (symbol: API.MarketInfoExt) => void;
283
+ readonly updateFavoriteTabs: (tab: FavoriteTab | FavoriteTab[], operator?: {
284
+ add?: boolean;
285
+ update?: boolean;
286
+ delete?: boolean;
287
+ }) => void;
288
+ readonly updateSymbolFavoriteState: (symbol: API.MarketInfoExt, tab: FavoriteTab | FavoriteTab[], del?: boolean) => void;
289
+ readonly pinToTop: (symbol: API.MarketInfoExt) => void;
290
+ readonly getLastSelFavTab: () => FavoriteTab;
291
+ readonly updateSelectedFavoriteTab: (tab: FavoriteTab) => void;
292
+ }];
293
+
215
294
  declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
216
295
 
217
296
  declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
@@ -233,7 +312,10 @@ declare const useFundingRate: (symbol: string) => {
233
312
  sum_unitary_funding?: number | undefined;
234
313
  };
235
314
 
236
- declare const usePositionStream: (symbol?: string | undefined, options?: Partial<swr__internal.PublicConfiguration<any, any, swr__internal.BareFetcher<any>>> | undefined) => readonly [{
315
+ type PriceMode = "markPrice" | "lastPrice";
316
+ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration & {
317
+ calcMode?: PriceMode;
318
+ }) => readonly [{
237
319
  readonly rows: API.PositionExt[] | null;
238
320
  readonly aggregated: any;
239
321
  readonly totalCollateral: Decimal;
@@ -242,11 +324,10 @@ declare const usePositionStream: (symbol?: string | undefined, options?: Partial
242
324
  }, any, {
243
325
  readonly loading: false;
244
326
  readonly error: any;
245
- readonly loadMore: () => void;
246
- readonly refresh: () => void;
327
+ readonly refresh: swr__internal.KeyedMutator<API.PositionInfo>;
247
328
  }];
248
329
 
249
- declare type Params = {
330
+ type Params = {
250
331
  symbol?: string;
251
332
  status?: OrderStatus;
252
333
  size?: number;
@@ -255,17 +336,24 @@ declare type Params = {
255
336
  declare const useOrderStream: (params: Params) => readonly [any[] | null, {
256
337
  readonly total: any;
257
338
  readonly isLoading: boolean;
339
+ readonly refresh: swr__internal.KeyedMutator<any[]>;
258
340
  readonly loadMore: () => void;
259
341
  readonly cancelAllOrders: () => void;
260
342
  readonly updateOrder: (orderId: string, order: OrderEntity) => Promise<any>;
261
- readonly cancelOrder: (orderId: string, symbol?: string | undefined) => Promise<any>;
343
+ readonly cancelOrder: (orderId: number, symbol?: string) => Promise<any>;
344
+ readonly updateAlgoOrder: (orderId: string, order: OrderEntity) => Promise<any>;
345
+ readonly cancelAlgoOrder: (orderId: number, symbol?: string) => Promise<any>;
262
346
  readonly errors: {
263
347
  readonly cancelOrder: unknown;
264
348
  readonly updateOrder: unknown;
349
+ readonly cancelAlgoOrder: unknown;
350
+ readonly updateAlgoOrder: unknown;
265
351
  };
266
352
  readonly submitting: {
267
353
  readonly cancelOrder: boolean;
268
354
  readonly updateOrder: boolean;
355
+ readonly cancelAlgoOrder: boolean;
356
+ readonly updateAlglOrder: boolean;
269
357
  };
270
358
  }];
271
359
 
@@ -277,37 +365,41 @@ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStream
277
365
  isLoading: boolean;
278
366
  };
279
367
 
280
- declare type CollateralOutputs = {
368
+ type CollateralOutputs = {
281
369
  totalCollateral: number;
282
370
  freeCollateral: number;
283
371
  totalValue: number;
284
372
  availableBalance: number;
285
373
  unsettledPnL: number;
374
+ positions: API.Position[];
375
+ accountInfo?: API.AccountInfo;
286
376
  };
287
- declare type Options = {
377
+ type Options = {
288
378
  dp: number;
289
379
  };
290
380
  declare const useCollateral: (options?: Options) => CollateralOutputs;
291
381
 
292
382
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
293
383
 
294
- declare const useMarginRatio: () => {
384
+ type MarginRatioReturn = {
295
385
  marginRatio: number;
296
386
  currentLeverage: number;
387
+ mmr: number | null;
297
388
  };
389
+ declare const useMarginRatio: () => MarginRatioReturn;
298
390
 
299
- declare type inputOptions = {
391
+ type inputOptions = {
300
392
  filter?: (item: API.Chain) => boolean;
301
393
  pick?: "dexs" | "network_infos" | "token_infos";
302
394
  crossEnabled?: boolean;
303
395
  /** if true, use wooSwap api, else use orderly api only */
304
396
  wooSwapEnabled?: boolean;
305
397
  };
306
- declare const useChains: (networkId?: NetworkId | undefined, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
398
+ declare const useChains: (networkId?: NetworkId, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
307
399
  testnet: API.Chain[];
308
400
  mainnet: API.Chain[];
309
401
  }, {
310
- readonly findByChainId: (chainId: number, field?: string | undefined) => (API.Chain & {
402
+ readonly findByChainId: (chainId: number, field?: string) => (API.Chain & {
311
403
  nativeToken?: API.TokenInfo | undefined;
312
404
  }) | (<K extends never>(prop: K) => ((API.Chain & {
313
405
  nativeToken?: API.TokenInfo | undefined;
@@ -324,16 +416,17 @@ declare const useWithdraw: () => {
324
416
  withdraw: (inputs: {
325
417
  chainId: number;
326
418
  token: string;
327
- amount: number;
419
+ amount: string;
328
420
  allowCrossChainWithdraw: boolean;
329
421
  }) => Promise<any>;
330
422
  isLoading: boolean;
331
423
  maxAmount: number;
332
424
  availableBalance: number;
425
+ availableWithdraw: number;
333
426
  unsettledPnL: number;
334
427
  };
335
428
 
336
- declare type useDepositOptions = {
429
+ type useDepositOptions = {
337
430
  address?: string;
338
431
  decimals?: number;
339
432
  crossChainRouteAddress?: string;
@@ -341,12 +434,14 @@ declare type useDepositOptions = {
341
434
  networkId?: NetworkId;
342
435
  srcChainId?: number;
343
436
  srcToken?: string;
437
+ quantity?: string;
344
438
  /**
345
439
  * @hidden
346
440
  */
347
441
  wooSwapEnabled?: boolean;
348
442
  };
349
- declare const useDeposit: (options?: useDepositOptions | undefined) => {
443
+ declare const useDeposit: (options?: useDepositOptions) => {
444
+ /** orderly support chain dst */
350
445
  dst: {
351
446
  symbol: string;
352
447
  address: string | undefined;
@@ -359,10 +454,18 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
359
454
  isNativeToken: boolean;
360
455
  balanceRevalidating: boolean;
361
456
  allowanceRevalidating: boolean;
362
- approve: (amount: string | undefined) => Promise<any>;
363
- deposit: (amount: string) => Promise<any>;
457
+ /** input quantiy */
458
+ quantity: string;
459
+ /** orderly deposit fee, unit: wei */
460
+ depositFee: bigint;
461
+ /** enquiring depositFee status on chain */
462
+ depositFeeRevalidating: boolean;
463
+ approve: (amount?: string) => Promise<any>;
464
+ deposit: () => Promise<any>;
364
465
  fetchBalances: (tokens: API.TokenInfo[]) => Promise<void>;
365
- fetchBalance: (address: string, decimals?: number | undefined) => Promise<string>;
466
+ fetchBalance: (address: string, decimals?: number) => Promise<string>;
467
+ /** set input quantity */
468
+ setQuantity: react.Dispatch<react.SetStateAction<string>>;
366
469
  };
367
470
 
368
471
  declare const useHoldingStream: () => {
@@ -379,7 +482,24 @@ declare const useSettleSubscription: (options?: {
379
482
  onMessage?: ((data: any) => void) | undefined;
380
483
  } | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
381
484
 
382
- declare const usePrivateDataObserver: () => void;
485
+ type getKeyFunction = (index: number, prevData: any) => string | null;
486
+
487
+ declare const usePrivateDataObserver: (options: {
488
+ getKeysMap: (type: string) => Map<string, getKeyFunction>;
489
+ }) => void;
490
+
491
+ type PriceRange = {
492
+ min: number;
493
+ max: number;
494
+ };
495
+ /**
496
+ * Get the price range for the specified symbol with an optional price
497
+ *
498
+ * @param symbol - The symbol to get the price range for
499
+ * @param price - Optional parameter to set the price
500
+ * @returns PriceRange | undefined - Returns the PriceRange representing the price range or undefined
501
+ */
502
+ declare const useSymbolPriceRange: (symbol: string, side: "BUY" | "SELL", price?: number) => PriceRange | undefined;
383
503
 
384
504
  declare function useMediaQuery(query: string): boolean;
385
505
 
@@ -408,4 +528,4 @@ declare const useCrossSwap: () => any;
408
528
  /** @hidden */
409
529
  declare const useSwap: () => any;
410
530
 
411
- 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 };
531
+ export { ConfigProviderProps, Favorite, FavoriteTab, MarketsType, OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, Recent, UseOrderEntryMetaState, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarkets, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolPriceRange, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery, _default as version };