@orderly.network/hooks 0.0.94 → 1.0.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.ts CHANGED
@@ -2,14 +2,15 @@ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
4
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
- import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
5
+ import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc } from '@orderly.network/core';
9
6
  export { default as useConstant } from 'use-constant';
10
7
  import { WS } from '@orderly.network/net';
8
+ import * as react from 'react';
9
+ import { FC, PropsWithChildren } from 'react';
10
+ import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
11
11
  import * as swr__internal from 'swr/_internal';
12
12
  import * as swr_subscription from 'swr/subscription';
13
+ import { Decimal } from '@orderly.network/utils';
13
14
  export * from 'use-debounce';
14
15
 
15
16
  type useQueryOptions<T> = SWRConfiguration & {
@@ -36,7 +37,12 @@ declare const useLazyQuery: <T, R = any>(query: Parameters<typeof useSWR>["0"],
36
37
  }) | undefined) => SWRMutationResponse;
37
38
 
38
39
  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
+ declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E> | undefined) => readonly [(data: any, params?: any) => Promise<any>, {
41
+ readonly data: any;
42
+ readonly error: E | undefined;
43
+ readonly reset: () => void;
44
+ readonly isMutating: boolean;
45
+ }];
40
46
 
41
47
  /**
42
48
  * usePrivateQuery
@@ -52,78 +58,52 @@ declare const useBoolean: (initialValue?: boolean) => [boolean, {
52
58
  toggle: () => void;
53
59
  }];
54
60
 
55
- declare const useTradingView: () => {};
56
-
57
- declare const useTopicObserve: <T>(topic: string) => {
58
- data: T | undefined;
59
- };
60
-
61
61
  declare const useAccount: () => {
62
- account: Account;
62
+ account: _orderly_network_core.Account;
63
63
  state: AccountState;
64
- createOrderlyKey: (remember: boolean) => Promise<string>;
65
- createAccount: () => Promise<string>;
66
- disconnect: () => Promise<void>;
67
- connect: () => Promise<any>;
68
- setChain: (chainId: number) => Promise<any>;
64
+ createOrderlyKey: (remember: boolean) => Promise<any>;
65
+ createAccount: () => Promise<any>;
69
66
  };
70
67
 
71
68
  declare const useAccountInstance: () => Account;
72
69
 
73
- interface OrderlyAppConfig {
74
- logoUrl: string;
75
- theme: any;
76
- }
77
- type AppStateErrors = {
78
- ChainNetworkNotSupport: boolean;
79
- IpNotSupport: boolean;
80
- NetworkError: boolean;
81
- };
82
- interface OrderlyContextState extends OrderlyAppConfig {
83
- fetcher?: (url: string, init: RequestInit) => Promise<any>;
84
- apiBaseUrl: string;
85
- klineDataUrl: string;
86
- configStore: ConfigStore;
87
- keyStore: OrderlyKeyStore;
88
- getWalletAdapter: getWalletAdapterFunc;
89
- contractManager: IContract;
90
- networkId: NetworkId;
91
- brokerId: string;
92
- onWalletConnect?: () => Promise<any>;
93
- onWalletDisconnect?: () => Promise<any>;
94
- onSetChain?: (chainId: number) => Promise<any>;
95
- errors: AppStateErrors;
96
- onlyTestnet: boolean;
97
- }
98
- declare const OrderlyContext: react.Context<OrderlyContextState>;
99
- declare const OrderlyProvider: react.Provider<OrderlyContextState>;
100
-
101
- declare const useAppState: () => {
102
- errors: AppStateErrors;
103
- };
104
-
105
70
  declare const usePreLoadData: () => {
106
71
  error: any;
107
72
  done: boolean;
108
73
  };
109
74
 
110
- declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
75
+ declare const useEventEmitter: () => EventEmitter<string | symbol, any>;
111
76
 
112
77
  declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
113
78
 
114
- declare function useLocalStorage<T>(key: string, initialValue: T): [T, any];
115
-
116
- type useRunOnceProps = {
117
- fn: () => any;
118
- sessionKey?: string;
119
- };
120
- declare const useRunOnce: react__default.FC<useRunOnceProps>;
121
-
122
- declare const DataSourceProvider: FC<PropsWithChildren>;
79
+ declare function useLocalStorage<T>(key: string, initialValue: T): [any, (value: T) => void];
123
80
 
124
81
  declare const useWS: () => WS;
125
82
 
126
- declare const useConfig: () => _orderly_network_core.ConfigStore;
83
+ declare const useConfig: <T>(key?: ConfigKey, defaultValue?: T | undefined) => ConfigStore | T;
84
+
85
+ interface OrderlyConfigContextState {
86
+ fetcher?: (url: string, init: RequestInit) => Promise<any>;
87
+ configStore: ConfigStore;
88
+ keyStore: OrderlyKeyStore;
89
+ getWalletAdapter: getWalletAdapterFunc;
90
+ networkId: NetworkId;
91
+ onlyTestnet?: boolean;
92
+ }
93
+ declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
94
+ declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
95
+
96
+ type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
97
+ [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
98
+ }[R];
99
+ interface ConfigProviderProps {
100
+ configStore?: ConfigStore;
101
+ keyStore?: OrderlyKeyStore;
102
+ getWalletAdapter?: getWalletAdapterFunc;
103
+ brokerId: string;
104
+ networkId: NetworkId;
105
+ }
106
+ declare const OrderlyConfigProvider: FC<PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>>;
127
107
 
128
108
  type OrderBookItem = number[];
129
109
  type OrderbookData = {
@@ -141,7 +121,7 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
141
121
  asks: OrderBookItem[];
142
122
  bids: OrderBookItem[];
143
123
  markPrice: any;
144
- middlePrice: any[];
124
+ middlePrice: number[];
145
125
  onDepthChange?: undefined;
146
126
  depth?: undefined;
147
127
  allDepths?: undefined;
@@ -159,17 +139,6 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
159
139
  middlePrice?: undefined;
160
140
  })[];
161
141
 
162
- interface OrderEntryReturn {
163
- onSubmit: (values: OrderEntity) => Promise<any>;
164
- maxQty: number;
165
- freeCollateral: number;
166
- markPrice: number;
167
- symbolConfig: API.SymbolExt;
168
- helper: {
169
- calculate: (values: any, field: string, value: any) => any;
170
- validator: (values: any) => any;
171
- };
172
- }
173
142
  type UseOrderEntryOptions = {
174
143
  commify?: boolean;
175
144
  validate?: (data: OrderEntity) => {
@@ -177,28 +146,26 @@ type UseOrderEntryOptions = {
177
146
  } | null | undefined;
178
147
  };
179
148
  /**
180
- * 创建订单
149
+ * Create Order
181
150
  * @param symbol
182
151
  * @returns
183
152
  */
184
- declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
185
-
186
- interface MarketInfo {
187
- }
188
- declare const useFetures: () => {
189
- data: MarketInfo[] | undefined;
190
- sortBy: (key: string) => void;
191
- filterBy: (key: string) => void;
192
- isLoading: boolean;
193
- error: any;
153
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => {
154
+ maxQty: number;
155
+ freeCollateral: number;
156
+ markPrice: any;
157
+ onSubmit: (values: OrderEntity) => Promise<any>;
158
+ helper: {
159
+ calculate: (values: any, field: string, value: any) => unknown;
160
+ validator: (values: any) => any;
161
+ };
162
+ symbolConfig: any;
194
163
  };
195
164
 
196
- declare const useSymbolsInfo: () => any;
165
+ declare const useSymbolsInfo: () => Record<string, any>;
197
166
 
198
167
  declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
199
168
 
200
- declare const useTokenInfo: () => any;
201
-
202
169
  declare const useMarketsStream: () => {
203
170
  data: WSMessage.Ticker[] | null;
204
171
  };
@@ -209,14 +176,12 @@ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscription
209
176
 
210
177
  declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
211
178
 
212
- declare const useOpenInterest: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
213
-
214
- declare const useLeverage: () => ({
215
- update: (data: any) => any;
216
- config: any;
217
- } | undefined)[];
179
+ declare const useLeverage: () => [number | undefined, {
180
+ update: (data: any) => Promise<unknown>;
181
+ config: number[];
182
+ }];
218
183
 
219
- declare const useTickerStream: (symbol: string) => any;
184
+ declare const useTickerStream: (symbol: string) => API.MarketInfo;
220
185
 
221
186
  declare const useFundingRate: (symbol: string) => {
222
187
  est_funding_rate: string;
@@ -229,14 +194,33 @@ declare const useFundingRate: (symbol: string) => {
229
194
  sum_unitary_funding?: number | undefined;
230
195
  };
231
196
 
232
- declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
197
+ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => readonly [{
198
+ readonly rows: API.PositionExt[] | null;
199
+ readonly aggregated: any;
200
+ readonly totalCollateral: Decimal;
201
+ readonly totalValue: Decimal;
202
+ readonly totalUnrealizedROI: number;
203
+ }, any, {
204
+ readonly loading: false;
205
+ readonly error: any;
206
+ readonly loadMore: () => void;
207
+ readonly refresh: () => void;
208
+ }];
233
209
 
234
- declare const useOrderStream: ({ status, symbol, side, size, }?: {
235
- symbol?: string | undefined;
236
- status?: OrderStatus | undefined;
237
- size?: number | undefined;
238
- side?: OrderSide | undefined;
239
- }) => any;
210
+ type Params = {
211
+ symbol?: string;
212
+ status?: OrderStatus;
213
+ size?: number;
214
+ side?: OrderSide;
215
+ };
216
+ declare const useOrderStream: (params: Params) => readonly [any[] | null, {
217
+ readonly total: any;
218
+ readonly isLoading: boolean;
219
+ readonly loadMore: () => void;
220
+ readonly cancelAllOrders: () => void;
221
+ readonly updateOrder: (orderId: string, order: OrderEntity) => Promise<any>;
222
+ readonly cancelOrder: (orderId: string, symbol?: string) => Promise<void>;
223
+ }];
240
224
 
241
225
  interface MarketTradeStreamOptions {
242
226
  limit?: number;
@@ -253,10 +237,6 @@ type CollateralOutputs = {
253
237
  availableBalance: number;
254
238
  unsettledPnL: number;
255
239
  };
256
- /**
257
- * 用户保证金
258
- * @returns
259
- */
260
240
  type Options = {
261
241
  dp: number;
262
242
  };
@@ -273,28 +253,35 @@ type inputOptions = {
273
253
  filter?: (item: API.Chain) => boolean;
274
254
  pick?: "dexs" | "network_infos" | "token_infos";
275
255
  crossEnabled?: boolean;
256
+ /** if true, use wooSwap api, else use orderly api only */
276
257
  wooSwapEnabled?: boolean;
277
258
  };
278
- declare const useChains: (networkId?: NetworkId, options?: inputOptions & SWRConfiguration) => any[];
259
+ declare const useChains: (networkId?: NetworkId, options?: inputOptions & SWRConfiguration) => readonly [API.Chain[] | {
260
+ testnet: API.Chain[];
261
+ mainnet: API.Chain[];
262
+ }, {
263
+ readonly findByChainId: (chainId: number, field?: string) => (API.Chain & {
264
+ nativeToken?: API.TokenInfo | undefined;
265
+ }) | undefined;
266
+ readonly error: any;
267
+ }];
279
268
 
280
269
  declare const useChain: (token: string) => {
281
270
  chains: API.Chain | null;
282
271
  isLoading: boolean;
283
272
  };
284
273
 
285
- type WithdrawInputs = {
286
- chainId: number;
287
- token: string;
288
- amount: number;
289
- };
290
- interface WithdrawReturns {
274
+ declare const useWithdraw: () => {
275
+ withdraw: (inputs: {
276
+ chainId: number;
277
+ token: string;
278
+ amount: number;
279
+ }) => Promise<any>;
280
+ isLoading: boolean;
291
281
  maxAmount: number;
292
282
  availableBalance: number;
293
283
  unsettledPnL: number;
294
- isLoading: boolean;
295
- withdraw: (inputs: WithdrawInputs) => Promise<any>;
296
- }
297
- declare const useWithdraw: () => WithdrawReturns;
284
+ };
298
285
 
299
286
  type useDepositOptions = {
300
287
  address?: string;
@@ -338,67 +325,8 @@ declare const useSettleSubscription: (options?: {
338
325
  onMessage?: ((data: any) => void) | undefined;
339
326
  } | undefined) => swr_subscription.SWRSubscriptionResponse<any, any>;
340
327
 
341
- declare const useBalance: () => any;
342
-
343
328
  declare const usePrivateDataObserver: () => void;
344
329
 
345
- interface Info {
346
- symbol: string;
347
- quote_min: number;
348
- quote_max: number;
349
- quote_tick: number;
350
- base_min: number;
351
- base_max: number;
352
- base_tick: number;
353
- min_notional: number;
354
- price_range: number;
355
- created_time: number;
356
- updated_time: number;
357
- }
358
- /**
359
- * useInfo
360
- * @returns
361
- */
362
- declare const useInfo: () => swr__internal.SWRResponse<Info[], any, any>;
363
-
364
- interface Token {
365
- token: string;
366
- token_account_id: string;
367
- decimals: number;
368
- minimum_increment: number;
369
- }
370
- /**
371
- * useToken
372
- * @description get token info
373
- */
374
- declare const useToken: () => swr__internal.SWRResponse<Token[], any, any>;
375
-
376
- interface FundingRate {
377
- symbol: string;
378
- est_funding_rate: number;
379
- est_funding_rate_timestamp: number;
380
- last_funding_rate: number;
381
- last_funding_rate_timestamp: number;
382
- next_funding_time: number;
383
- sum_unitary_funding: number;
384
- }
385
- /**
386
- * FundingRate
387
- * @param symbol
388
- */
389
- declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
390
-
391
- declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
392
- declare const index_useInfo: typeof useInfo;
393
- declare const index_useToken: typeof useToken;
394
- declare namespace index {
395
- export {
396
- index_useFundingRateBySymbol as useFundingRateBySymbol,
397
- index_useInfo as useInfo,
398
- index_useToken as useToken,
399
- };
400
- }
401
-
402
330
  declare const useWooSwapQuery: () => {
403
331
  query: (inputs: any) => Promise<any> | undefined;
404
332
  loading: boolean;
@@ -471,4 +399,4 @@ declare const useSwap: () => {
471
399
  status: WS_WalletStatusEnum;
472
400
  };
473
401
 
474
- export { AppStateErrors, DataSourceProvider, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
402
+ export { ConfigProviderProps, OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };