@orderly.network/hooks 0.0.8 → 0.0.10

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
@@ -2,13 +2,12 @@ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
4
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
- import { SystemStateEnum, ExchangeStatusEnum, OrderEntity, API, OrderSide } from '@orderly.network/types';
5
+ import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
6
  import { WebSocketClient, WS } from '@orderly.network/net';
7
7
  export { useEventCallback, useObservable } from 'rxjs-hooks';
8
8
  export { default as useConstant } from 'use-constant';
9
9
  import * as react from 'react';
10
10
  import { FC, PropsWithChildren } from 'react';
11
- import { FormikErrors, FormikState } from 'formik';
12
11
  import * as swr__internal from 'swr/_internal';
13
12
  import * as swr_subscription from 'swr/subscription';
14
13
 
@@ -24,13 +23,8 @@ type useQueryOptions<T> = SWRConfiguration & {
24
23
  */
25
24
  declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
26
25
 
27
- declare const useMutation: <T, E>(url: string, options?: SWRMutationConfiguration<T, E> | undefined) => {
28
- mutation: (data: any) => Promise<any>;
29
- data: any;
30
- error: E | undefined;
31
- reset: () => void;
32
- isMutating: boolean;
33
- };
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];
34
28
 
35
29
  /**
36
30
  * usePrivateQuery
@@ -54,6 +48,10 @@ declare const useAccount: () => {
54
48
  account: Account;
55
49
  state: AccountState;
56
50
  login: (address: string) => void;
51
+ createOrderlyKey: (remember: boolean) => Promise<string>;
52
+ createAccount: () => Promise<string>;
53
+ disconnect: () => Promise<void>;
54
+ connect: () => Promise<any>;
57
55
  };
58
56
 
59
57
  declare const useAppState: () => {
@@ -74,10 +72,16 @@ interface OrderlyAppConfig {
74
72
  interface OrderlyContextState extends OrderlyAppConfig {
75
73
  fetcher?: (url: string, init: RequestInit) => Promise<any>;
76
74
  apiBaseUrl: string;
75
+ klineDataUrl: string;
77
76
  configStore: ConfigStore;
78
77
  keyStore: OrderlyKeyStore;
79
- walletAdapter: WalletAdapter;
78
+ walletAdapter: {
79
+ new (options: any): WalletAdapter;
80
+ };
80
81
  networkId: string;
82
+ onWalletConnect?: () => Promise<any>;
83
+ onWalletDisconnect?: () => Promise<any>;
84
+ ready: boolean;
81
85
  }
82
86
  declare const OrderlyContext: react.Context<OrderlyContextState>;
83
87
  declare const OrderlyProvider: react.Provider<OrderlyContextState>;
@@ -91,38 +95,33 @@ type OrderbookOptions = {
91
95
  level?: number;
92
96
  };
93
97
  /**
94
- * @name useOrderbook
98
+ * @name useOrderbookStream
95
99
  * @description React hook that returns the current orderbook for a given market
96
100
  */
97
- declare const useOrderbook: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
98
- markPrice: number;
101
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
102
+ markPrice: any;
99
103
  middlePrice: any;
100
104
  asks: OrderBookItem[];
101
105
  bids: OrderBookItem[];
102
106
  onDepthChange?: undefined;
103
107
  depth?: undefined;
108
+ isLoading?: undefined;
104
109
  } | {
105
110
  onDepthChange: (depth: number) => void;
106
111
  depth: number;
112
+ isLoading: boolean;
107
113
  })[];
108
114
 
109
- type OrderEntityKey = keyof OrderEntity & string;
110
-
111
115
  interface OrderEntryReturn {
112
- onSubmit: (values?: OrderEntity) => Promise<any>;
113
- validateForm: (values?: any) => Promise<FormikErrors<OrderEntity>>;
114
- resetForm: (nextState?: Partial<FormikState<OrderEntity>>) => void;
115
- setValue: (field: OrderEntityKey, value: any) => void;
116
+ onSubmit: (values: OrderEntity) => Promise<any>;
116
117
  maxQty: number;
117
118
  freeCollateral: number;
118
- values: OrderEntity;
119
119
  markPrice: number;
120
- errors: Partial<Record<keyof OrderEntity, string>>;
121
120
  symbolConfig: API.SymbolExt;
122
- submitCount: number;
123
- isSubmitting: boolean;
124
- onFocus?: (field: keyof OrderEntity) => void;
125
- onBlur?: (field: keyof OrderEntity) => void;
121
+ helper: {
122
+ calculate: (values: any, field: string, value: any) => any;
123
+ validator: (values: any) => any;
124
+ };
126
125
  }
127
126
  type UseOrderEntryOptions = {
128
127
  commify?: boolean;
@@ -135,7 +134,7 @@ type UseOrderEntryOptions = {
135
134
  * @param symbol
136
135
  * @returns
137
136
  */
138
- declare const useOrderEntry: (symbol: string, initialValue?: Partial<OrderEntity>, options?: UseOrderEntryOptions) => OrderEntryReturn;
137
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
139
138
 
140
139
  interface MarketInfo {
141
140
  }
@@ -159,6 +158,8 @@ declare const useMarketsStream: () => {
159
158
 
160
159
  declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
161
160
 
161
+ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
162
+
162
163
  declare const useTickerStream: (symbol: string) => any;
163
164
 
164
165
  declare const useFundingRate$1: (symbol: string) => {
@@ -190,6 +191,11 @@ declare const useOrderStream: ({ status, symbol, }?: {
190
191
  cancelOrder: (id: string) => void;
191
192
  } | null)[];
192
193
 
194
+ declare const useTradeStream: (symbol: string) => {
195
+ data: API.Trade[] | undefined;
196
+ isLoading: boolean;
197
+ };
198
+
193
199
  type CollateralOutputs = {
194
200
  totalCollateral: number;
195
201
  freeCollateral: number;
@@ -199,10 +205,21 @@ type CollateralOutputs = {
199
205
  * 用户保证金
200
206
  * @returns
201
207
  */
202
- declare const useCollateral: (dp?: number) => CollateralOutputs;
208
+ type Options = {
209
+ dp: number;
210
+ };
211
+ declare const useCollateral: (options?: Options) => CollateralOutputs;
203
212
 
204
213
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
205
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
+
206
223
  interface Info {
207
224
  symbol: string;
208
225
  quote_min: number;
@@ -268,4 +285,4 @@ declare namespace index {
268
285
  };
269
286
  }
270
287
 
271
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbook, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWebSocketClient };
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 };
package/dist/index.d.ts CHANGED
@@ -2,13 +2,12 @@ import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
4
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
- import { SystemStateEnum, ExchangeStatusEnum, OrderEntity, API, OrderSide } from '@orderly.network/types';
5
+ import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
6
  import { WebSocketClient, WS } from '@orderly.network/net';
7
7
  export { useEventCallback, useObservable } from 'rxjs-hooks';
8
8
  export { default as useConstant } from 'use-constant';
9
9
  import * as react from 'react';
10
10
  import { FC, PropsWithChildren } from 'react';
11
- import { FormikErrors, FormikState } from 'formik';
12
11
  import * as swr__internal from 'swr/_internal';
13
12
  import * as swr_subscription from 'swr/subscription';
14
13
 
@@ -24,13 +23,8 @@ type useQueryOptions<T> = SWRConfiguration & {
24
23
  */
25
24
  declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
26
25
 
27
- declare const useMutation: <T, E>(url: string, options?: SWRMutationConfiguration<T, E> | undefined) => {
28
- mutation: (data: any) => Promise<any>;
29
- data: any;
30
- error: E | undefined;
31
- reset: () => void;
32
- isMutating: boolean;
33
- };
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];
34
28
 
35
29
  /**
36
30
  * usePrivateQuery
@@ -54,6 +48,10 @@ declare const useAccount: () => {
54
48
  account: Account;
55
49
  state: AccountState;
56
50
  login: (address: string) => void;
51
+ createOrderlyKey: (remember: boolean) => Promise<string>;
52
+ createAccount: () => Promise<string>;
53
+ disconnect: () => Promise<void>;
54
+ connect: () => Promise<any>;
57
55
  };
58
56
 
59
57
  declare const useAppState: () => {
@@ -74,10 +72,16 @@ interface OrderlyAppConfig {
74
72
  interface OrderlyContextState extends OrderlyAppConfig {
75
73
  fetcher?: (url: string, init: RequestInit) => Promise<any>;
76
74
  apiBaseUrl: string;
75
+ klineDataUrl: string;
77
76
  configStore: ConfigStore;
78
77
  keyStore: OrderlyKeyStore;
79
- walletAdapter: WalletAdapter;
78
+ walletAdapter: {
79
+ new (options: any): WalletAdapter;
80
+ };
80
81
  networkId: string;
82
+ onWalletConnect?: () => Promise<any>;
83
+ onWalletDisconnect?: () => Promise<any>;
84
+ ready: boolean;
81
85
  }
82
86
  declare const OrderlyContext: react.Context<OrderlyContextState>;
83
87
  declare const OrderlyProvider: react.Provider<OrderlyContextState>;
@@ -91,38 +95,33 @@ type OrderbookOptions = {
91
95
  level?: number;
92
96
  };
93
97
  /**
94
- * @name useOrderbook
98
+ * @name useOrderbookStream
95
99
  * @description React hook that returns the current orderbook for a given market
96
100
  */
97
- declare const useOrderbook: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
98
- markPrice: number;
101
+ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
102
+ markPrice: any;
99
103
  middlePrice: any;
100
104
  asks: OrderBookItem[];
101
105
  bids: OrderBookItem[];
102
106
  onDepthChange?: undefined;
103
107
  depth?: undefined;
108
+ isLoading?: undefined;
104
109
  } | {
105
110
  onDepthChange: (depth: number) => void;
106
111
  depth: number;
112
+ isLoading: boolean;
107
113
  })[];
108
114
 
109
- type OrderEntityKey = keyof OrderEntity & string;
110
-
111
115
  interface OrderEntryReturn {
112
- onSubmit: (values?: OrderEntity) => Promise<any>;
113
- validateForm: (values?: any) => Promise<FormikErrors<OrderEntity>>;
114
- resetForm: (nextState?: Partial<FormikState<OrderEntity>>) => void;
115
- setValue: (field: OrderEntityKey, value: any) => void;
116
+ onSubmit: (values: OrderEntity) => Promise<any>;
116
117
  maxQty: number;
117
118
  freeCollateral: number;
118
- values: OrderEntity;
119
119
  markPrice: number;
120
- errors: Partial<Record<keyof OrderEntity, string>>;
121
120
  symbolConfig: API.SymbolExt;
122
- submitCount: number;
123
- isSubmitting: boolean;
124
- onFocus?: (field: keyof OrderEntity) => void;
125
- onBlur?: (field: keyof OrderEntity) => void;
121
+ helper: {
122
+ calculate: (values: any, field: string, value: any) => any;
123
+ validator: (values: any) => any;
124
+ };
126
125
  }
127
126
  type UseOrderEntryOptions = {
128
127
  commify?: boolean;
@@ -135,7 +134,7 @@ type UseOrderEntryOptions = {
135
134
  * @param symbol
136
135
  * @returns
137
136
  */
138
- declare const useOrderEntry: (symbol: string, initialValue?: Partial<OrderEntity>, options?: UseOrderEntryOptions) => OrderEntryReturn;
137
+ declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
139
138
 
140
139
  interface MarketInfo {
141
140
  }
@@ -159,6 +158,8 @@ declare const useMarketsStream: () => {
159
158
 
160
159
  declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
161
160
 
161
+ declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
162
+
162
163
  declare const useTickerStream: (symbol: string) => any;
163
164
 
164
165
  declare const useFundingRate$1: (symbol: string) => {
@@ -190,6 +191,11 @@ declare const useOrderStream: ({ status, symbol, }?: {
190
191
  cancelOrder: (id: string) => void;
191
192
  } | null)[];
192
193
 
194
+ declare const useTradeStream: (symbol: string) => {
195
+ data: API.Trade[] | undefined;
196
+ isLoading: boolean;
197
+ };
198
+
193
199
  type CollateralOutputs = {
194
200
  totalCollateral: number;
195
201
  freeCollateral: number;
@@ -199,10 +205,21 @@ type CollateralOutputs = {
199
205
  * 用户保证金
200
206
  * @returns
201
207
  */
202
- declare const useCollateral: (dp?: number) => CollateralOutputs;
208
+ type Options = {
209
+ dp: number;
210
+ };
211
+ declare const useCollateral: (options?: Options) => CollateralOutputs;
203
212
 
204
213
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
205
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
+
206
223
  interface Info {
207
224
  symbol: string;
208
225
  quote_min: number;
@@ -268,4 +285,4 @@ declare namespace index {
268
285
  };
269
286
  }
270
287
 
271
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbook, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWebSocketClient };
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 };