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