@orderly.network/hooks 1.0.29 → 1.1.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 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.0";
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,22 @@ 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 | OrderEntity, symbol?: string) => Promise<any>;
262
344
  readonly errors: {
263
345
  readonly cancelOrder: unknown;
264
346
  readonly updateOrder: unknown;
347
+ readonly cancelAlgoOrder: unknown;
348
+ readonly updateAlgoOrder: unknown;
265
349
  };
266
350
  readonly submitting: {
267
351
  readonly cancelOrder: boolean;
268
352
  readonly updateOrder: boolean;
353
+ readonly cancelAlgoOrder: boolean;
354
+ readonly updateAlglOrder: boolean;
269
355
  };
270
356
  }];
271
357
 
@@ -277,37 +363,41 @@ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStream
277
363
  isLoading: boolean;
278
364
  };
279
365
 
280
- declare type CollateralOutputs = {
366
+ type CollateralOutputs = {
281
367
  totalCollateral: number;
282
368
  freeCollateral: number;
283
369
  totalValue: number;
284
370
  availableBalance: number;
285
371
  unsettledPnL: number;
372
+ positions: API.Position[];
373
+ accountInfo?: API.AccountInfo;
286
374
  };
287
- declare type Options = {
375
+ type Options = {
288
376
  dp: number;
289
377
  };
290
378
  declare const useCollateral: (options?: Options) => CollateralOutputs;
291
379
 
292
380
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
293
381
 
294
- declare const useMarginRatio: () => {
382
+ type MarginRatioReturn = {
295
383
  marginRatio: number;
296
384
  currentLeverage: number;
385
+ mmr: number | null;
297
386
  };
387
+ declare const useMarginRatio: () => MarginRatioReturn;
298
388
 
299
- declare type inputOptions = {
389
+ type inputOptions = {
300
390
  filter?: (item: API.Chain) => boolean;
301
391
  pick?: "dexs" | "network_infos" | "token_infos";
302
392
  crossEnabled?: boolean;
303
393
  /** if true, use wooSwap api, else use orderly api only */
304
394
  wooSwapEnabled?: boolean;
305
395
  };
306
- declare const useChains: (networkId?: NetworkId | undefined, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
396
+ declare const useChains: (networkId?: NetworkId, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
307
397
  testnet: API.Chain[];
308
398
  mainnet: API.Chain[];
309
399
  }, {
310
- readonly findByChainId: (chainId: number, field?: string | undefined) => (API.Chain & {
400
+ readonly findByChainId: (chainId: number, field?: string) => (API.Chain & {
311
401
  nativeToken?: API.TokenInfo | undefined;
312
402
  }) | (<K extends never>(prop: K) => ((API.Chain & {
313
403
  nativeToken?: API.TokenInfo | undefined;
@@ -324,16 +414,17 @@ declare const useWithdraw: () => {
324
414
  withdraw: (inputs: {
325
415
  chainId: number;
326
416
  token: string;
327
- amount: number;
417
+ amount: string;
328
418
  allowCrossChainWithdraw: boolean;
329
419
  }) => Promise<any>;
330
420
  isLoading: boolean;
331
421
  maxAmount: number;
332
422
  availableBalance: number;
423
+ availableWithdraw: number;
333
424
  unsettledPnL: number;
334
425
  };
335
426
 
336
- declare type useDepositOptions = {
427
+ type useDepositOptions = {
337
428
  address?: string;
338
429
  decimals?: number;
339
430
  crossChainRouteAddress?: string;
@@ -341,12 +432,14 @@ declare type useDepositOptions = {
341
432
  networkId?: NetworkId;
342
433
  srcChainId?: number;
343
434
  srcToken?: string;
435
+ quantity?: string;
344
436
  /**
345
437
  * @hidden
346
438
  */
347
439
  wooSwapEnabled?: boolean;
348
440
  };
349
- declare const useDeposit: (options?: useDepositOptions | undefined) => {
441
+ declare const useDeposit: (options?: useDepositOptions) => {
442
+ /** orderly support chain dst */
350
443
  dst: {
351
444
  symbol: string;
352
445
  address: string | undefined;
@@ -359,10 +452,18 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
359
452
  isNativeToken: boolean;
360
453
  balanceRevalidating: boolean;
361
454
  allowanceRevalidating: boolean;
362
- approve: (amount: string | undefined) => Promise<any>;
363
- deposit: (amount: string) => Promise<any>;
455
+ /** input quantiy */
456
+ quantity: string;
457
+ /** orderly deposit fee, unit: wei */
458
+ depositFee: bigint;
459
+ /** enquiring depositFee status on chain */
460
+ depositFeeRevalidating: boolean;
461
+ approve: (amount?: string) => Promise<any>;
462
+ deposit: () => Promise<any>;
364
463
  fetchBalances: (tokens: API.TokenInfo[]) => Promise<void>;
365
- fetchBalance: (address: string, decimals?: number | undefined) => Promise<string>;
464
+ fetchBalance: (address: string, decimals?: number) => Promise<string>;
465
+ /** set input quantity */
466
+ setQuantity: react.Dispatch<react.SetStateAction<string>>;
366
467
  };
367
468
 
368
469
  declare const useHoldingStream: () => {
@@ -379,7 +480,24 @@ declare const useSettleSubscription: (options?: {
379
480
  onMessage?: ((data: any) => void) | undefined;
380
481
  } | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
381
482
 
382
- declare const usePrivateDataObserver: () => void;
483
+ type getKeyFunction = (index: number, prevData: any) => string | null;
484
+
485
+ declare const usePrivateDataObserver: (options: {
486
+ getKeysMap: (type: string) => Map<string, getKeyFunction>;
487
+ }) => void;
488
+
489
+ type PriceRange = {
490
+ min: number;
491
+ max: number;
492
+ };
493
+ /**
494
+ * Get the price range for the specified symbol with an optional price
495
+ *
496
+ * @param symbol - The symbol to get the price range for
497
+ * @param price - Optional parameter to set the price
498
+ * @returns PriceRange | undefined - Returns the PriceRange representing the price range or undefined
499
+ */
500
+ declare const useSymbolPriceRange: (symbol: string, side: "BUY" | "SELL", price?: number) => PriceRange | undefined;
383
501
 
384
502
  declare function useMediaQuery(query: string): boolean;
385
503
 
@@ -408,4 +526,4 @@ declare const useCrossSwap: () => any;
408
526
  /** @hidden */
409
527
  declare const useSwap: () => any;
410
528
 
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 };
529
+ 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 };