@orderly.network/hooks 0.0.9 → 0.0.11

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,288 @@
1
+ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
+ export { SWRConfiguration, default as useSWR } from 'swr';
3
+ import { SWRMutationConfiguration } from 'swr/mutation';
4
+ import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
+ import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
+ import { WebSocketClient, WS } from '@orderly.network/net';
7
+ export { useEventCallback, useObservable } from 'rxjs-hooks';
8
+ export { default as useConstant } from 'use-constant';
9
+ import * as react from 'react';
10
+ import { FC, PropsWithChildren } from 'react';
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" | "GET";
27
+ declare const useMutation: <T, E>(url: string, options?: SWRMutationConfiguration<T, E> | undefined, method?: HTTP_METHOD) => [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
+ };
56
+
57
+ declare const useAppState: () => {
58
+ systemState: SystemStateEnum;
59
+ exchangeState: ExchangeStatusEnum;
60
+ };
61
+
62
+ declare const useWebSocketClient: () => WebSocketClient;
63
+
64
+ declare const DataSourceProvider: FC<PropsWithChildren>;
65
+
66
+ declare const useWS: () => WS;
67
+
68
+ interface OrderlyAppConfig {
69
+ logoUrl: string;
70
+ theme: any;
71
+ }
72
+ interface OrderlyContextState extends OrderlyAppConfig {
73
+ fetcher?: (url: string, init: RequestInit) => Promise<any>;
74
+ apiBaseUrl: string;
75
+ klineDataUrl: string;
76
+ configStore: ConfigStore;
77
+ keyStore: OrderlyKeyStore;
78
+ walletAdapter: {
79
+ new (options: any): WalletAdapter;
80
+ };
81
+ networkId: string;
82
+ onWalletConnect?: () => Promise<any>;
83
+ onWalletDisconnect?: () => Promise<any>;
84
+ ready: boolean;
85
+ }
86
+ declare const OrderlyContext: react.Context<OrderlyContextState>;
87
+ declare const OrderlyProvider: react.Provider<OrderlyContextState>;
88
+
89
+ type OrderBookItem = number[];
90
+ type OrderbookData = {
91
+ asks: OrderBookItem[];
92
+ bids: OrderBookItem[];
93
+ };
94
+ type OrderbookOptions = {
95
+ level?: number;
96
+ };
97
+ /**
98
+ * @name useOrderbookStream
99
+ * @description React hook that returns the current orderbook for a given market
100
+ */
101
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
102
+ markPrice: any;
103
+ middlePrice: any;
104
+ asks: OrderBookItem[];
105
+ bids: OrderBookItem[];
106
+ onDepthChange?: undefined;
107
+ depth?: undefined;
108
+ isLoading?: undefined;
109
+ } | {
110
+ onDepthChange: (depth: number) => void;
111
+ depth: number;
112
+ isLoading: boolean;
113
+ })[];
114
+
115
+ interface OrderEntryReturn {
116
+ onSubmit: (values: OrderEntity) => Promise<any>;
117
+ maxQty: number;
118
+ freeCollateral: number;
119
+ markPrice: number;
120
+ symbolConfig: API.SymbolExt;
121
+ helper: {
122
+ calculate: (values: any, field: string, value: any) => any;
123
+ validator: (values: any) => any;
124
+ };
125
+ }
126
+ type UseOrderEntryOptions = {
127
+ commify?: boolean;
128
+ validate?: (data: OrderEntity) => {
129
+ [P in keyof OrderEntity]?: string;
130
+ } | null | undefined;
131
+ };
132
+ /**
133
+ * 创建订单
134
+ * @param symbol
135
+ * @returns
136
+ */
137
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
138
+
139
+ interface MarketInfo {
140
+ }
141
+ declare const useFetures: () => {
142
+ data: MarketInfo[] | undefined;
143
+ sortBy: (key: string) => void;
144
+ filterBy: (key: string) => void;
145
+ isLoading: boolean;
146
+ error: any;
147
+ };
148
+
149
+ declare const useSymbolsInfo: () => any;
150
+
151
+ declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
152
+
153
+ declare const useTokenInfo: () => any;
154
+
155
+ declare const useMarketsStream: () => {
156
+ data: WSMessage.Ticker[] | null;
157
+ };
158
+
159
+ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
160
+
161
+ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
162
+
163
+ declare const useTickerStream: (symbol: string) => any;
164
+
165
+ declare const useFundingRate$1: (symbol: string) => {
166
+ countDown: string;
167
+ symbol?: string | undefined;
168
+ est_funding_rate?: number | undefined;
169
+ est_funding_rate_timestamp?: number | undefined;
170
+ last_funding_rate?: number | undefined;
171
+ last_funding_rate_timestamp?: number | undefined;
172
+ next_funding_time?: number | undefined;
173
+ sum_unitary_funding?: number | undefined;
174
+ };
175
+
176
+ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
177
+
178
+ declare enum OrderStatus {
179
+ FILLED = "FILLED",
180
+ PARTIAL_FILLED = "PARTIAL_FILLED",
181
+ CANCELED = "CANCELED",
182
+ NEW = "NEW",
183
+ COMPLETED = "COMPLETED"
184
+ }
185
+ declare const useOrderStream: ({ status, symbol, }?: {
186
+ symbol?: string | undefined;
187
+ status?: OrderStatus | undefined;
188
+ }) => (any[] | {
189
+ cancelAllOrders: () => void;
190
+ updateOrder: (id: string, data: any) => void;
191
+ cancelOrder: (id: string) => void;
192
+ } | null)[];
193
+
194
+ declare const useTradeStream: (symbol: string) => {
195
+ data: API.Trade[] | undefined;
196
+ isLoading: boolean;
197
+ };
198
+
199
+ type CollateralOutputs = {
200
+ totalCollateral: number;
201
+ freeCollateral: number;
202
+ totalValue: number;
203
+ };
204
+ /**
205
+ * 用户保证金
206
+ * @returns
207
+ */
208
+ type Options = {
209
+ dp: number;
210
+ };
211
+ declare const useCollateral: (options?: Options) => CollateralOutputs;
212
+
213
+ declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
214
+
215
+ declare const useMarginRatio: () => number;
216
+
217
+ type inputOptions = {
218
+ filter?: (item: API.Chain) => boolean;
219
+ pick?: "dexs" | "network_infos" | "token_infos";
220
+ };
221
+ declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
222
+
223
+ interface Info {
224
+ symbol: string;
225
+ quote_min: number;
226
+ quote_max: number;
227
+ quote_tick: number;
228
+ base_min: number;
229
+ base_max: number;
230
+ base_tick: number;
231
+ min_notional: number;
232
+ price_range: number;
233
+ created_time: number;
234
+ updated_time: number;
235
+ }
236
+ /**
237
+ * useInfo
238
+ * @returns
239
+ */
240
+ declare const useInfo: () => swr__internal.SWRResponse<Info[], any, any>;
241
+
242
+ interface Token {
243
+ token: string;
244
+ token_account_id: string;
245
+ decimals: number;
246
+ minimum_increment: number;
247
+ }
248
+ /**
249
+ * useToken
250
+ * @description get token info
251
+ */
252
+ declare const useToken: () => swr__internal.SWRResponse<Token[], any, any>;
253
+
254
+ interface FundingRate {
255
+ symbol: string;
256
+ est_funding_rate: number;
257
+ est_funding_rate_timestamp: number;
258
+ last_funding_rate: number;
259
+ last_funding_rate_timestamp: number;
260
+ next_funding_time: number;
261
+ sum_unitary_funding: number;
262
+ }
263
+ /**
264
+ * FundingRate
265
+ * @param symbol
266
+ */
267
+ declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
268
+
269
+ /**
270
+ * FundingRate
271
+ * @param symbol
272
+ */
273
+ declare const useFundingRate: (symbol?: string) => swr__internal.SWRResponse<FundingRate, any, any>;
274
+
275
+ declare const index_useFundingRate: typeof useFundingRate;
276
+ declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
277
+ declare const index_useInfo: typeof useInfo;
278
+ declare const index_useToken: typeof useToken;
279
+ declare namespace index {
280
+ export {
281
+ index_useFundingRate as useFundingRate,
282
+ index_useFundingRateBySymbol as useFundingRateBySymbol,
283
+ index_useInfo as useInfo,
284
+ index_useToken as useToken,
285
+ };
286
+ }
287
+
288
+ export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS, useWebSocketClient };
@@ -0,0 +1,288 @@
1
+ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
+ export { SWRConfiguration, default as useSWR } from 'swr';
3
+ import { SWRMutationConfiguration } from 'swr/mutation';
4
+ import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
+ import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
+ import { WebSocketClient, WS } from '@orderly.network/net';
7
+ export { useEventCallback, useObservable } from 'rxjs-hooks';
8
+ export { default as useConstant } from 'use-constant';
9
+ import * as react from 'react';
10
+ import { FC, PropsWithChildren } from 'react';
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" | "GET";
27
+ declare const useMutation: <T, E>(url: string, options?: SWRMutationConfiguration<T, E> | undefined, method?: HTTP_METHOD) => [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
+ };
56
+
57
+ declare const useAppState: () => {
58
+ systemState: SystemStateEnum;
59
+ exchangeState: ExchangeStatusEnum;
60
+ };
61
+
62
+ declare const useWebSocketClient: () => WebSocketClient;
63
+
64
+ declare const DataSourceProvider: FC<PropsWithChildren>;
65
+
66
+ declare const useWS: () => WS;
67
+
68
+ interface OrderlyAppConfig {
69
+ logoUrl: string;
70
+ theme: any;
71
+ }
72
+ interface OrderlyContextState extends OrderlyAppConfig {
73
+ fetcher?: (url: string, init: RequestInit) => Promise<any>;
74
+ apiBaseUrl: string;
75
+ klineDataUrl: string;
76
+ configStore: ConfigStore;
77
+ keyStore: OrderlyKeyStore;
78
+ walletAdapter: {
79
+ new (options: any): WalletAdapter;
80
+ };
81
+ networkId: string;
82
+ onWalletConnect?: () => Promise<any>;
83
+ onWalletDisconnect?: () => Promise<any>;
84
+ ready: boolean;
85
+ }
86
+ declare const OrderlyContext: react.Context<OrderlyContextState>;
87
+ declare const OrderlyProvider: react.Provider<OrderlyContextState>;
88
+
89
+ type OrderBookItem = number[];
90
+ type OrderbookData = {
91
+ asks: OrderBookItem[];
92
+ bids: OrderBookItem[];
93
+ };
94
+ type OrderbookOptions = {
95
+ level?: number;
96
+ };
97
+ /**
98
+ * @name useOrderbookStream
99
+ * @description React hook that returns the current orderbook for a given market
100
+ */
101
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
102
+ markPrice: any;
103
+ middlePrice: any;
104
+ asks: OrderBookItem[];
105
+ bids: OrderBookItem[];
106
+ onDepthChange?: undefined;
107
+ depth?: undefined;
108
+ isLoading?: undefined;
109
+ } | {
110
+ onDepthChange: (depth: number) => void;
111
+ depth: number;
112
+ isLoading: boolean;
113
+ })[];
114
+
115
+ interface OrderEntryReturn {
116
+ onSubmit: (values: OrderEntity) => Promise<any>;
117
+ maxQty: number;
118
+ freeCollateral: number;
119
+ markPrice: number;
120
+ symbolConfig: API.SymbolExt;
121
+ helper: {
122
+ calculate: (values: any, field: string, value: any) => any;
123
+ validator: (values: any) => any;
124
+ };
125
+ }
126
+ type UseOrderEntryOptions = {
127
+ commify?: boolean;
128
+ validate?: (data: OrderEntity) => {
129
+ [P in keyof OrderEntity]?: string;
130
+ } | null | undefined;
131
+ };
132
+ /**
133
+ * 创建订单
134
+ * @param symbol
135
+ * @returns
136
+ */
137
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
138
+
139
+ interface MarketInfo {
140
+ }
141
+ declare const useFetures: () => {
142
+ data: MarketInfo[] | undefined;
143
+ sortBy: (key: string) => void;
144
+ filterBy: (key: string) => void;
145
+ isLoading: boolean;
146
+ error: any;
147
+ };
148
+
149
+ declare const useSymbolsInfo: () => any;
150
+
151
+ declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
152
+
153
+ declare const useTokenInfo: () => any;
154
+
155
+ declare const useMarketsStream: () => {
156
+ data: WSMessage.Ticker[] | null;
157
+ };
158
+
159
+ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
160
+
161
+ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
162
+
163
+ declare const useTickerStream: (symbol: string) => any;
164
+
165
+ declare const useFundingRate$1: (symbol: string) => {
166
+ countDown: string;
167
+ symbol?: string | undefined;
168
+ est_funding_rate?: number | undefined;
169
+ est_funding_rate_timestamp?: number | undefined;
170
+ last_funding_rate?: number | undefined;
171
+ last_funding_rate_timestamp?: number | undefined;
172
+ next_funding_time?: number | undefined;
173
+ sum_unitary_funding?: number | undefined;
174
+ };
175
+
176
+ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
177
+
178
+ declare enum OrderStatus {
179
+ FILLED = "FILLED",
180
+ PARTIAL_FILLED = "PARTIAL_FILLED",
181
+ CANCELED = "CANCELED",
182
+ NEW = "NEW",
183
+ COMPLETED = "COMPLETED"
184
+ }
185
+ declare const useOrderStream: ({ status, symbol, }?: {
186
+ symbol?: string | undefined;
187
+ status?: OrderStatus | undefined;
188
+ }) => (any[] | {
189
+ cancelAllOrders: () => void;
190
+ updateOrder: (id: string, data: any) => void;
191
+ cancelOrder: (id: string) => void;
192
+ } | null)[];
193
+
194
+ declare const useTradeStream: (symbol: string) => {
195
+ data: API.Trade[] | undefined;
196
+ isLoading: boolean;
197
+ };
198
+
199
+ type CollateralOutputs = {
200
+ totalCollateral: number;
201
+ freeCollateral: number;
202
+ totalValue: number;
203
+ };
204
+ /**
205
+ * 用户保证金
206
+ * @returns
207
+ */
208
+ type Options = {
209
+ dp: number;
210
+ };
211
+ declare const useCollateral: (options?: Options) => CollateralOutputs;
212
+
213
+ declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
214
+
215
+ declare const useMarginRatio: () => number;
216
+
217
+ type inputOptions = {
218
+ filter?: (item: API.Chain) => boolean;
219
+ pick?: "dexs" | "network_infos" | "token_infos";
220
+ };
221
+ declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
222
+
223
+ interface Info {
224
+ symbol: string;
225
+ quote_min: number;
226
+ quote_max: number;
227
+ quote_tick: number;
228
+ base_min: number;
229
+ base_max: number;
230
+ base_tick: number;
231
+ min_notional: number;
232
+ price_range: number;
233
+ created_time: number;
234
+ updated_time: number;
235
+ }
236
+ /**
237
+ * useInfo
238
+ * @returns
239
+ */
240
+ declare const useInfo: () => swr__internal.SWRResponse<Info[], any, any>;
241
+
242
+ interface Token {
243
+ token: string;
244
+ token_account_id: string;
245
+ decimals: number;
246
+ minimum_increment: number;
247
+ }
248
+ /**
249
+ * useToken
250
+ * @description get token info
251
+ */
252
+ declare const useToken: () => swr__internal.SWRResponse<Token[], any, any>;
253
+
254
+ interface FundingRate {
255
+ symbol: string;
256
+ est_funding_rate: number;
257
+ est_funding_rate_timestamp: number;
258
+ last_funding_rate: number;
259
+ last_funding_rate_timestamp: number;
260
+ next_funding_time: number;
261
+ sum_unitary_funding: number;
262
+ }
263
+ /**
264
+ * FundingRate
265
+ * @param symbol
266
+ */
267
+ declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
268
+
269
+ /**
270
+ * FundingRate
271
+ * @param symbol
272
+ */
273
+ declare const useFundingRate: (symbol?: string) => swr__internal.SWRResponse<FundingRate, any, any>;
274
+
275
+ declare const index_useFundingRate: typeof useFundingRate;
276
+ declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
277
+ declare const index_useInfo: typeof useInfo;
278
+ declare const index_useToken: typeof useToken;
279
+ declare namespace index {
280
+ export {
281
+ index_useFundingRate as useFundingRate,
282
+ index_useFundingRateBySymbol as useFundingRateBySymbol,
283
+ index_useInfo as useInfo,
284
+ index_useToken as useToken,
285
+ };
286
+ }
287
+
288
+ export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS, useWebSocketClient };