@orderly.network/hooks 0.0.39 → 0.0.41
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 +340 -0
- package/dist/index.mjs +100 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/index.js +0 -2110
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
|
+
export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
|
|
3
|
+
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract, EventEmitter } from '@orderly.network/core';
|
|
5
|
+
import * as react from 'react';
|
|
6
|
+
import react__default, { FC, PropsWithChildren } from 'react';
|
|
7
|
+
export { default as useConstant } from 'use-constant';
|
|
8
|
+
import { WS } from '@orderly.network/net';
|
|
9
|
+
import { OrderSide, OrderEntity, API, WSMessage } from '@orderly.network/types';
|
|
10
|
+
import * as swr__internal from 'swr/_internal';
|
|
11
|
+
import * as swr_subscription from 'swr/subscription';
|
|
12
|
+
|
|
13
|
+
type useQueryOptions<T> = SWRConfiguration & {
|
|
14
|
+
formatter?: (data: any) => T;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* useQuery
|
|
19
|
+
* @description for public api
|
|
20
|
+
* @param query
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
declare const useQuery: <T>(query: Parameters<typeof useSWR>["0"], options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
|
|
24
|
+
|
|
25
|
+
type HTTP_METHOD = "POST" | "PUT" | "DELETE";
|
|
26
|
+
declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E> | undefined) => [any, any];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* usePrivateQuery
|
|
30
|
+
* @description for private api
|
|
31
|
+
* @param query
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
declare const usePrivateQuery: <T>(query: string, options?: useQueryOptions<T> | undefined) => SWRResponse<T, any, any>;
|
|
35
|
+
|
|
36
|
+
declare const useTradingView: () => {};
|
|
37
|
+
|
|
38
|
+
declare const usePrivateObserve: <T>() => {
|
|
39
|
+
data: T | undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
declare const useTopicObserve: <T>(topic: string) => {
|
|
43
|
+
data: T | undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
declare const useAccount: () => {
|
|
47
|
+
account: Account;
|
|
48
|
+
state: AccountState;
|
|
49
|
+
login: (address: string) => void;
|
|
50
|
+
createOrderlyKey: (remember: boolean) => Promise<string>;
|
|
51
|
+
createAccount: () => Promise<string>;
|
|
52
|
+
disconnect: () => Promise<void>;
|
|
53
|
+
connect: () => Promise<any>;
|
|
54
|
+
setChain: (chainId: number) => Promise<any>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
declare const useAccountInstance: () => Account;
|
|
58
|
+
|
|
59
|
+
interface OrderlyAppConfig {
|
|
60
|
+
logoUrl: string;
|
|
61
|
+
theme: any;
|
|
62
|
+
}
|
|
63
|
+
type AppStateErrors = {
|
|
64
|
+
ChainNetworkNotSupport: boolean;
|
|
65
|
+
IpNotSupport: boolean;
|
|
66
|
+
NetworkError: boolean;
|
|
67
|
+
};
|
|
68
|
+
interface OrderlyContextState extends OrderlyAppConfig {
|
|
69
|
+
fetcher?: (url: string, init: RequestInit) => Promise<any>;
|
|
70
|
+
apiBaseUrl: string;
|
|
71
|
+
klineDataUrl: string;
|
|
72
|
+
configStore: ConfigStore;
|
|
73
|
+
keyStore: OrderlyKeyStore;
|
|
74
|
+
getWalletAdapter: getWalletAdapterFunc;
|
|
75
|
+
contractManager: IContract;
|
|
76
|
+
networkId: string;
|
|
77
|
+
brokerId: string;
|
|
78
|
+
onWalletConnect?: () => Promise<any>;
|
|
79
|
+
onWalletDisconnect?: () => Promise<any>;
|
|
80
|
+
onSetChain?: (chainId: number) => Promise<any>;
|
|
81
|
+
ready: boolean;
|
|
82
|
+
onAppTestChange?: (name: string) => void;
|
|
83
|
+
errors: AppStateErrors;
|
|
84
|
+
}
|
|
85
|
+
declare const OrderlyContext: react.Context<OrderlyContextState>;
|
|
86
|
+
declare const OrderlyProvider: react.Provider<OrderlyContextState>;
|
|
87
|
+
|
|
88
|
+
declare const useAppState: () => {
|
|
89
|
+
errors: AppStateErrors;
|
|
90
|
+
ready: boolean;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
declare const usePreLoadData: (onSuccess: (name: string) => void) => void;
|
|
94
|
+
|
|
95
|
+
declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
|
|
96
|
+
|
|
97
|
+
declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
|
|
98
|
+
|
|
99
|
+
declare function useLocalStorage<T>(key: string, initialValue: T): [T, any];
|
|
100
|
+
|
|
101
|
+
type useRunOnceProps = {
|
|
102
|
+
fn: () => any;
|
|
103
|
+
sessionKey?: string;
|
|
104
|
+
};
|
|
105
|
+
declare const useRunOnce: react__default.FC<useRunOnceProps>;
|
|
106
|
+
|
|
107
|
+
declare const DataSourceProvider: FC<PropsWithChildren>;
|
|
108
|
+
|
|
109
|
+
declare const useWS: () => WS;
|
|
110
|
+
|
|
111
|
+
type OrderBookItem = number[];
|
|
112
|
+
type OrderbookData = {
|
|
113
|
+
asks: OrderBookItem[];
|
|
114
|
+
bids: OrderBookItem[];
|
|
115
|
+
};
|
|
116
|
+
type OrderbookOptions = {
|
|
117
|
+
level?: number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* @name useOrderbookStream
|
|
121
|
+
* @description React hook that returns the current orderbook for a given market
|
|
122
|
+
*/
|
|
123
|
+
declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, options?: OrderbookOptions) => ({
|
|
124
|
+
asks: OrderBookItem[];
|
|
125
|
+
bids: OrderBookItem[];
|
|
126
|
+
markPrice: any;
|
|
127
|
+
middlePrice: any[];
|
|
128
|
+
onDepthChange?: undefined;
|
|
129
|
+
depth?: undefined;
|
|
130
|
+
allDepths?: undefined;
|
|
131
|
+
isLoading?: undefined;
|
|
132
|
+
onItemClick?: undefined;
|
|
133
|
+
} | {
|
|
134
|
+
onDepthChange: (depth: number) => void;
|
|
135
|
+
depth: number | undefined;
|
|
136
|
+
allDepths: any[];
|
|
137
|
+
isLoading: boolean;
|
|
138
|
+
onItemClick: (item: OrderBookItem) => void;
|
|
139
|
+
asks?: undefined;
|
|
140
|
+
bids?: undefined;
|
|
141
|
+
markPrice?: undefined;
|
|
142
|
+
middlePrice?: undefined;
|
|
143
|
+
})[];
|
|
144
|
+
|
|
145
|
+
interface OrderEntryReturn {
|
|
146
|
+
onSubmit: (values: OrderEntity) => Promise<any>;
|
|
147
|
+
maxQty: number;
|
|
148
|
+
freeCollateral: number;
|
|
149
|
+
markPrice: number;
|
|
150
|
+
symbolConfig: API.SymbolExt;
|
|
151
|
+
helper: {
|
|
152
|
+
calculate: (values: any, field: string, value: any) => any;
|
|
153
|
+
validator: (values: any) => any;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
type UseOrderEntryOptions = {
|
|
157
|
+
commify?: boolean;
|
|
158
|
+
validate?: (data: OrderEntity) => {
|
|
159
|
+
[P in keyof OrderEntity]?: string;
|
|
160
|
+
} | null | undefined;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* 创建订单
|
|
164
|
+
* @param symbol
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
declare const useOrderEntry: (symbol: string, side: OrderSide, reduceOnly?: boolean, options?: UseOrderEntryOptions) => OrderEntryReturn;
|
|
168
|
+
|
|
169
|
+
interface MarketInfo {
|
|
170
|
+
}
|
|
171
|
+
declare const useFetures: () => {
|
|
172
|
+
data: MarketInfo[] | undefined;
|
|
173
|
+
sortBy: (key: string) => void;
|
|
174
|
+
filterBy: (key: string) => void;
|
|
175
|
+
isLoading: boolean;
|
|
176
|
+
error: any;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare const useSymbolsInfo: () => any;
|
|
180
|
+
|
|
181
|
+
declare const useAccountInfo: () => swr__internal.SWRResponse<API.AccountInfo, any, any>;
|
|
182
|
+
|
|
183
|
+
declare const useTokenInfo: () => any;
|
|
184
|
+
|
|
185
|
+
declare const useMarketsStream: () => {
|
|
186
|
+
data: WSMessage.Ticker[] | null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
190
|
+
|
|
191
|
+
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
192
|
+
|
|
193
|
+
declare const useLeverage: () => ({
|
|
194
|
+
update: (data: any) => any;
|
|
195
|
+
} | undefined)[];
|
|
196
|
+
|
|
197
|
+
declare const useTickerStream: (symbol: string) => any;
|
|
198
|
+
|
|
199
|
+
declare const useFundingRate: (symbol: string) => {
|
|
200
|
+
est_funding_rate: string;
|
|
201
|
+
countDown: string;
|
|
202
|
+
symbol?: string | undefined;
|
|
203
|
+
est_funding_rate_timestamp?: number | undefined;
|
|
204
|
+
last_funding_rate?: number | undefined;
|
|
205
|
+
last_funding_rate_timestamp?: number | undefined;
|
|
206
|
+
next_funding_time?: number | undefined;
|
|
207
|
+
sum_unitary_funding?: number | undefined;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
|
|
211
|
+
|
|
212
|
+
declare enum OrderStatus {
|
|
213
|
+
FILLED = "FILLED",
|
|
214
|
+
PARTIAL_FILLED = "PARTIAL_FILLED",
|
|
215
|
+
CANCELED = "CANCELED",
|
|
216
|
+
NEW = "NEW",
|
|
217
|
+
COMPLETED = "COMPLETED"
|
|
218
|
+
}
|
|
219
|
+
declare const useOrderStream: ({ status, symbol, side, size, }?: {
|
|
220
|
+
symbol?: string | undefined;
|
|
221
|
+
status?: OrderStatus | undefined;
|
|
222
|
+
size?: number | undefined;
|
|
223
|
+
side?: OrderSide | undefined;
|
|
224
|
+
}) => (any[] | {
|
|
225
|
+
cancelAllOrders: () => void;
|
|
226
|
+
updateOrder: (orderId: string, order: OrderEntity) => any;
|
|
227
|
+
cancelOrder: (orderId: string, symbol?: string) => any;
|
|
228
|
+
} | null)[];
|
|
229
|
+
|
|
230
|
+
interface MarketTradeStreamOptions {
|
|
231
|
+
limit?: number;
|
|
232
|
+
}
|
|
233
|
+
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
234
|
+
data: API.Trade[];
|
|
235
|
+
isLoading: boolean;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
type CollateralOutputs = {
|
|
239
|
+
totalCollateral: number;
|
|
240
|
+
freeCollateral: number;
|
|
241
|
+
totalValue: number;
|
|
242
|
+
availableBalance: number;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* 用户保证金
|
|
246
|
+
* @returns
|
|
247
|
+
*/
|
|
248
|
+
type Options = {
|
|
249
|
+
dp: number;
|
|
250
|
+
};
|
|
251
|
+
declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
252
|
+
|
|
253
|
+
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
254
|
+
|
|
255
|
+
declare const useMarginRatio: () => {
|
|
256
|
+
marginRatio: number;
|
|
257
|
+
currentLeverage: number;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
type inputOptions = {
|
|
261
|
+
filter?: (item: API.Chain) => boolean;
|
|
262
|
+
pick?: "dexs" | "network_infos" | "token_infos";
|
|
263
|
+
};
|
|
264
|
+
declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions & SWRConfiguration) => any[];
|
|
265
|
+
|
|
266
|
+
declare const useChain: (token: string) => {
|
|
267
|
+
chains: API.Chain | null;
|
|
268
|
+
isLoading: boolean;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
declare const useHolding: () => {
|
|
272
|
+
data: API.Holding[] | undefined;
|
|
273
|
+
usdc: API.Holding | undefined;
|
|
274
|
+
isLoading: boolean;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
declare const useBalance: () => any;
|
|
278
|
+
|
|
279
|
+
declare const usePrivateDataObserver: () => void;
|
|
280
|
+
|
|
281
|
+
declare const useExecutionReport: () => any;
|
|
282
|
+
|
|
283
|
+
interface Info {
|
|
284
|
+
symbol: string;
|
|
285
|
+
quote_min: number;
|
|
286
|
+
quote_max: number;
|
|
287
|
+
quote_tick: number;
|
|
288
|
+
base_min: number;
|
|
289
|
+
base_max: number;
|
|
290
|
+
base_tick: number;
|
|
291
|
+
min_notional: number;
|
|
292
|
+
price_range: number;
|
|
293
|
+
created_time: number;
|
|
294
|
+
updated_time: number;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* useInfo
|
|
298
|
+
* @returns
|
|
299
|
+
*/
|
|
300
|
+
declare const useInfo: () => swr__internal.SWRResponse<Info[], any, any>;
|
|
301
|
+
|
|
302
|
+
interface Token {
|
|
303
|
+
token: string;
|
|
304
|
+
token_account_id: string;
|
|
305
|
+
decimals: number;
|
|
306
|
+
minimum_increment: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* useToken
|
|
310
|
+
* @description get token info
|
|
311
|
+
*/
|
|
312
|
+
declare const useToken: () => swr__internal.SWRResponse<Token[], any, any>;
|
|
313
|
+
|
|
314
|
+
interface FundingRate {
|
|
315
|
+
symbol: string;
|
|
316
|
+
est_funding_rate: number;
|
|
317
|
+
est_funding_rate_timestamp: number;
|
|
318
|
+
last_funding_rate: number;
|
|
319
|
+
last_funding_rate_timestamp: number;
|
|
320
|
+
next_funding_time: number;
|
|
321
|
+
sum_unitary_funding: number;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* FundingRate
|
|
325
|
+
* @param symbol
|
|
326
|
+
*/
|
|
327
|
+
declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
|
|
328
|
+
|
|
329
|
+
declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
|
|
330
|
+
declare const index_useInfo: typeof useInfo;
|
|
331
|
+
declare const index_useToken: typeof useToken;
|
|
332
|
+
declare namespace index {
|
|
333
|
+
export {
|
|
334
|
+
index_useFundingRateBySymbol as useFundingRateBySymbol,
|
|
335
|
+
index_useInfo as useInfo,
|
|
336
|
+
index_useToken as useToken,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChain, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import useSWRMutation from 'swr/mutation';
|
|
|
6
6
|
import useConstant from 'use-constant';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { SimpleDI, Account, EventEmitter } from '@orderly.network/core';
|
|
9
|
-
import { AccountStatusEnum, OrderSide, OrderType } from '@orderly.network/types';
|
|
9
|
+
import { AccountStatusEnum, OrderSide, chainsMap, OrderStatus as OrderStatus$1, OrderType } from '@orderly.network/types';
|
|
10
10
|
import useSWRSubscription from 'swr/subscription';
|
|
11
11
|
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
12
12
|
import { pathOr, propOr, compose, head, prop } from 'ramda';
|
|
@@ -84,7 +84,9 @@ var useQuery = (query, options) => {
|
|
|
84
84
|
return useSWR(
|
|
85
85
|
// `${apiBaseUrl}${query}`,
|
|
86
86
|
query,
|
|
87
|
-
(url, init) => fetcher(`${apiBaseUrl}${url}`, init, {
|
|
87
|
+
(url, init) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init, {
|
|
88
|
+
formatter
|
|
89
|
+
}),
|
|
88
90
|
swrOptions
|
|
89
91
|
);
|
|
90
92
|
};
|
|
@@ -205,8 +207,6 @@ var useAccount = () => {
|
|
|
205
207
|
const {
|
|
206
208
|
configStore,
|
|
207
209
|
keyStore,
|
|
208
|
-
walletAdapter,
|
|
209
|
-
contractManager,
|
|
210
210
|
onWalletConnect,
|
|
211
211
|
onWalletDisconnect,
|
|
212
212
|
onSetChain
|
|
@@ -657,9 +657,6 @@ var reduceItems = (depth, level, data, asks = false) => {
|
|
|
657
657
|
continue;
|
|
658
658
|
const newQuantity = new Decimal(quantity).add(result.length > 0 ? result[result.length - 1][2] : 0).toNumber();
|
|
659
659
|
result.push([price, quantity, newQuantity]);
|
|
660
|
-
if (i + 1 >= level) {
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
660
|
}
|
|
664
661
|
return result;
|
|
665
662
|
};
|
|
@@ -779,6 +776,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
779
776
|
const onDepthChange = useCallback((depth2) => {
|
|
780
777
|
setDepth(() => depth2);
|
|
781
778
|
}, []);
|
|
779
|
+
const prevMiddlePrice = useRef(0);
|
|
782
780
|
const middlePrice = useMemo(() => {
|
|
783
781
|
let asksFrist = 0, bidsFirst = 0;
|
|
784
782
|
if (data.asks.length > 0) {
|
|
@@ -791,35 +789,19 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
791
789
|
return 0;
|
|
792
790
|
return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
|
|
793
791
|
}, [ticker, data]);
|
|
792
|
+
useEffect(() => {
|
|
793
|
+
prevMiddlePrice.current = middlePrice;
|
|
794
|
+
}, [middlePrice]);
|
|
794
795
|
return [
|
|
795
|
-
|
|
796
|
+
{
|
|
797
|
+
asks: data.asks.slice(-level),
|
|
798
|
+
bids: data.bids.slice(0, level),
|
|
799
|
+
markPrice,
|
|
800
|
+
middlePrice: [prevMiddlePrice.current, middlePrice]
|
|
801
|
+
},
|
|
796
802
|
{ onDepthChange, depth, allDepths: depths, isLoading, onItemClick }
|
|
797
803
|
];
|
|
798
804
|
};
|
|
799
|
-
|
|
800
|
-
// src/orderly/useTokenInfo.ts
|
|
801
|
-
var useTokenInfo = () => {
|
|
802
|
-
const { data = {} } = useQuery(
|
|
803
|
-
"/v1/public/token",
|
|
804
|
-
{
|
|
805
|
-
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
806
|
-
revalidateOnFocus: false,
|
|
807
|
-
formatter(data2) {
|
|
808
|
-
var _a;
|
|
809
|
-
if (!(data2 == null ? void 0 : data2.rows) || !((_a = data2 == null ? void 0 : data2.rows) == null ? void 0 : _a.length)) {
|
|
810
|
-
return {};
|
|
811
|
-
}
|
|
812
|
-
const obj = /* @__PURE__ */ Object.create(null);
|
|
813
|
-
for (let index = 0; index < data2.rows.length; index++) {
|
|
814
|
-
const item = data2.rows[index];
|
|
815
|
-
obj[item.token] = item;
|
|
816
|
-
}
|
|
817
|
-
return obj;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
);
|
|
821
|
-
return createGetter(data);
|
|
822
|
-
};
|
|
823
805
|
var needNumberOnlyFields = ["order_quantity", "order_price", "total"];
|
|
824
806
|
function baseInputHandle(inputs) {
|
|
825
807
|
let [values, input, value, markPrice, config] = inputs;
|
|
@@ -1196,7 +1178,9 @@ var unsettledPnL = pathOr(0, [0, "aggregated", "unsettledPnL"]);
|
|
|
1196
1178
|
var useCollateral = (options = { dp: 6 }) => {
|
|
1197
1179
|
const { dp } = options;
|
|
1198
1180
|
const positions2 = usePositionStream();
|
|
1199
|
-
const { data: orders } = usePrivateQuery(
|
|
1181
|
+
const { data: orders } = usePrivateQuery(
|
|
1182
|
+
`/v1/orders?status=NEW`
|
|
1183
|
+
);
|
|
1200
1184
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1201
1185
|
const symbolInfo = useSymbolsInfo();
|
|
1202
1186
|
const { data: markPrices } = useMarkPricesStream();
|
|
@@ -1482,14 +1466,13 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1482
1466
|
const [doCreateOrder] = useMutation("/v1/order");
|
|
1483
1467
|
const { freeCollateral } = useCollateral();
|
|
1484
1468
|
const symbolInfo = useSymbolsInfo();
|
|
1485
|
-
const tokenInfo = useTokenInfo();
|
|
1486
1469
|
const baseDP = useMemo(
|
|
1487
1470
|
() => getPrecisionByNumber(symbolInfo[symbol]("base_tick", 0)),
|
|
1488
1471
|
[symbolInfo]
|
|
1489
1472
|
);
|
|
1490
1473
|
const quoteDP = useMemo(() => {
|
|
1491
|
-
return
|
|
1492
|
-
}, [
|
|
1474
|
+
return getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
|
|
1475
|
+
}, [symbolInfo]);
|
|
1493
1476
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
1494
1477
|
const maxQty = useMaxQty(
|
|
1495
1478
|
symbol,
|
|
@@ -1509,7 +1492,7 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1509
1492
|
}
|
|
1510
1493
|
return orderCreator == null ? void 0 : orderCreator.validate(values, {
|
|
1511
1494
|
symbol: symbolInfo[symbol](),
|
|
1512
|
-
token: tokenInfo[symbol](),
|
|
1495
|
+
// token: tokenInfo[symbol](),
|
|
1513
1496
|
maxQty,
|
|
1514
1497
|
markPrice
|
|
1515
1498
|
}).then(() => {
|
|
@@ -1543,7 +1526,7 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1543
1526
|
const creator = OrderFactory.create(values.order_type);
|
|
1544
1527
|
return creator == null ? void 0 : creator.validate(values, {
|
|
1545
1528
|
symbol: symbolInfo[symbol](),
|
|
1546
|
-
token: tokenInfo[symbol](),
|
|
1529
|
+
// token: tokenInfo[symbol](),
|
|
1547
1530
|
maxQty,
|
|
1548
1531
|
markPrice
|
|
1549
1532
|
});
|
|
@@ -1597,6 +1580,30 @@ var useFetures = () => {
|
|
|
1597
1580
|
var useAccountInfo = () => {
|
|
1598
1581
|
return usePrivateQuery("/v1/client/info");
|
|
1599
1582
|
};
|
|
1583
|
+
|
|
1584
|
+
// src/orderly/useTokenInfo.ts
|
|
1585
|
+
var useTokenInfo = () => {
|
|
1586
|
+
const { data = {} } = useQuery(
|
|
1587
|
+
"/v1/public/token",
|
|
1588
|
+
{
|
|
1589
|
+
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
1590
|
+
revalidateOnFocus: false,
|
|
1591
|
+
formatter(data2) {
|
|
1592
|
+
var _a;
|
|
1593
|
+
if (!(data2 == null ? void 0 : data2.rows) || !((_a = data2 == null ? void 0 : data2.rows) == null ? void 0 : _a.length)) {
|
|
1594
|
+
return {};
|
|
1595
|
+
}
|
|
1596
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
1597
|
+
for (let index = 0; index < data2.rows.length; index++) {
|
|
1598
|
+
const item = data2.rows[index];
|
|
1599
|
+
obj[item.token] = item;
|
|
1600
|
+
}
|
|
1601
|
+
return obj;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
);
|
|
1605
|
+
return createGetter(data);
|
|
1606
|
+
};
|
|
1600
1607
|
var useMarketsStream = () => {
|
|
1601
1608
|
const ws = useWS();
|
|
1602
1609
|
const { data: futures } = useQuery(`/v1/public/futures`, {
|
|
@@ -1709,13 +1716,13 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
1709
1716
|
);
|
|
1710
1717
|
return result;
|
|
1711
1718
|
};
|
|
1712
|
-
var OrderStatus = /* @__PURE__ */ ((
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
return
|
|
1719
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus3) => {
|
|
1720
|
+
OrderStatus3["FILLED"] = "FILLED";
|
|
1721
|
+
OrderStatus3["PARTIAL_FILLED"] = "PARTIAL_FILLED";
|
|
1722
|
+
OrderStatus3["CANCELED"] = "CANCELED";
|
|
1723
|
+
OrderStatus3["NEW"] = "NEW";
|
|
1724
|
+
OrderStatus3["COMPLETED"] = "COMPLETED";
|
|
1725
|
+
return OrderStatus3;
|
|
1719
1726
|
})(OrderStatus || {});
|
|
1720
1727
|
var useOrderStream = ({
|
|
1721
1728
|
status,
|
|
@@ -1923,6 +1930,25 @@ var useChains = (networkId, options = {}) => {
|
|
|
1923
1930
|
);
|
|
1924
1931
|
return [chains, { findByChainId }];
|
|
1925
1932
|
};
|
|
1933
|
+
var useChain = (token) => {
|
|
1934
|
+
const { data, isLoading } = useQuery("/v1/public/token");
|
|
1935
|
+
const chains = useMemo(() => {
|
|
1936
|
+
if (!data)
|
|
1937
|
+
return null;
|
|
1938
|
+
let item = data.find((chain) => chain.token === token);
|
|
1939
|
+
if (item) {
|
|
1940
|
+
item.chain_details = item.chain_details.map((d) => {
|
|
1941
|
+
var _a;
|
|
1942
|
+
const chain = chainsMap.get(Number(d.chain_id));
|
|
1943
|
+
return __spreadProps(__spreadValues({}, d), {
|
|
1944
|
+
chain_name: (_a = chain == null ? void 0 : chain.chainName) != null ? _a : "--"
|
|
1945
|
+
});
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
return item || null;
|
|
1949
|
+
}, [data, token]);
|
|
1950
|
+
return { chains, isLoading };
|
|
1951
|
+
};
|
|
1926
1952
|
var useBalance = () => {
|
|
1927
1953
|
const ws = useWS();
|
|
1928
1954
|
const { data } = useSWRSubscription("balance", (_, { next }) => {
|
|
@@ -1941,14 +1967,40 @@ var usePrivateDataObserver = () => {
|
|
|
1941
1967
|
const ee = useEventEmitter();
|
|
1942
1968
|
const { state } = useAccount();
|
|
1943
1969
|
useEffect(() => {
|
|
1944
|
-
console.log("subscribe: executionreport");
|
|
1945
1970
|
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
1946
1971
|
onMessage: (data) => {
|
|
1972
|
+
const key = ["/v1/orders?status=NEW", state.accountId];
|
|
1973
|
+
mutate2(key, (orders) => {
|
|
1974
|
+
return Promise.resolve().then(() => {
|
|
1975
|
+
if (!orders) {
|
|
1976
|
+
return orders;
|
|
1977
|
+
}
|
|
1978
|
+
if (data.status === OrderStatus$1.NEW) {
|
|
1979
|
+
return [
|
|
1980
|
+
__spreadProps(__spreadValues({}, data), {
|
|
1981
|
+
// average_executed_price:data.ava
|
|
1982
|
+
created_time: data.timestamp,
|
|
1983
|
+
order_id: data.orderId
|
|
1984
|
+
// reduce_only
|
|
1985
|
+
}),
|
|
1986
|
+
...orders
|
|
1987
|
+
];
|
|
1988
|
+
}
|
|
1989
|
+
if (data.status === OrderStatus$1.CANCELLED) {
|
|
1990
|
+
return orders.filter(
|
|
1991
|
+
(order2) => order2.order_id !== data.orderId
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
return orders;
|
|
1995
|
+
}).catch((error) => {
|
|
1996
|
+
console.log("error", error, error.stack);
|
|
1997
|
+
});
|
|
1998
|
+
});
|
|
1947
1999
|
ee.emit("orders:changed");
|
|
1948
2000
|
}
|
|
1949
2001
|
});
|
|
1950
2002
|
return () => unsubscribe == null ? void 0 : unsubscribe();
|
|
1951
|
-
}, []);
|
|
2003
|
+
}, [state.accountId]);
|
|
1952
2004
|
useEffect(() => {
|
|
1953
2005
|
console.log("subscribe: position: %s", state.accountId);
|
|
1954
2006
|
if (!state.accountId)
|
|
@@ -1957,9 +2009,7 @@ var usePrivateDataObserver = () => {
|
|
|
1957
2009
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
1958
2010
|
onMessage: (data) => {
|
|
1959
2011
|
const { positions: nextPostions } = data;
|
|
1960
|
-
console.info("refresh positions:", nextPostions, state.accountId);
|
|
1961
2012
|
mutate2(key, (prevPositions) => {
|
|
1962
|
-
console.log("prevPositions:::::", prevPositions);
|
|
1963
2013
|
if (!!prevPositions) {
|
|
1964
2014
|
return __spreadProps(__spreadValues({}, prevPositions), {
|
|
1965
2015
|
rows: prevPositions.rows.map((row) => {
|
|
@@ -2042,6 +2092,6 @@ var useFundingRateBySymbol = (symbol) => {
|
|
|
2042
2092
|
return useQuery(`/public/funding_rate/${symbol}`);
|
|
2043
2093
|
};
|
|
2044
2094
|
|
|
2045
|
-
export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, 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 };
|
|
2095
|
+
export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChain, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, 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 };
|
|
2046
2096
|
//# sourceMappingURL=out.js.map
|
|
2047
2097
|
//# sourceMappingURL=index.mjs.map
|