@orderly.network/hooks 2.0.0 → 2.0.1-alpha.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.mts +416 -149
- package/dist/index.d.ts +416 -149
- package/dist/index.js +6010 -3982
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6008 -3983
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -14
package/dist/index.d.mts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
|
-
export {
|
|
2
|
+
export { SWRConfiguration, unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration, SWRMutationResponse } from 'swr/mutation';
|
|
4
4
|
import * as swr_infinite from 'swr/infinite';
|
|
5
5
|
import { SWRInfiniteKeyLoader, SWRInfiniteConfiguration } from 'swr/infinite';
|
|
6
6
|
import * as swr__internal from 'swr/_internal';
|
|
7
7
|
import * as _orderly_network_core from '@orderly.network/core';
|
|
8
|
-
import { AccountState, Account, EventEmitter, ConfigStore, ConfigKey, SimpleDI, OrderlyKeyStore,
|
|
8
|
+
import { AccountState, Account, EventEmitter, ConfigStore, ConfigKey, SimpleDI, OrderlyKeyStore, WalletAdapter, IContract, DefaultConfigStore } from '@orderly.network/core';
|
|
9
9
|
export { WalletAdapter } from '@orderly.network/core';
|
|
10
10
|
export { default as useConstant } from 'use-constant';
|
|
11
11
|
import { WS } from '@orderly.network/net';
|
|
12
12
|
import * as react from 'react';
|
|
13
|
-
import { PropsWithChildren } from 'react';
|
|
13
|
+
import { PropsWithChildren, FC } from 'react';
|
|
14
14
|
import * as _orderly_network_types from '@orderly.network/types';
|
|
15
|
-
import { API, NetworkId, Chain as Chain$1, ChainNamespace,
|
|
16
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
15
|
+
import { API, NetworkId, Chain as Chain$1, ChainNamespace, WSMessage, OrderStatus, OrderSide, AlgoOrderRootType, OrderEntity, AlgoOrderEntity, OrderlyOrder, AlgoOrderType, RequireKeys, OrderType } from '@orderly.network/types';
|
|
17
16
|
import { EIP1193Provider } from '@web3-onboard/common';
|
|
18
17
|
import * as swr_subscription from 'swr/subscription';
|
|
19
|
-
import
|
|
18
|
+
import * as _orderly_network_utils from '@orderly.network/utils';
|
|
20
19
|
export * from 'use-debounce';
|
|
20
|
+
import * as immer from 'immer';
|
|
21
|
+
import * as zustand from 'zustand';
|
|
21
22
|
|
|
22
23
|
declare global {
|
|
23
24
|
interface Window {
|
|
@@ -26,7 +27,7 @@ declare global {
|
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
declare const _default: "2.0.0";
|
|
30
|
+
declare const _default: "2.0.1-alpha.0";
|
|
30
31
|
|
|
31
32
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
32
33
|
formatter?: (data: any) => T;
|
|
@@ -151,7 +152,6 @@ interface OrderlyConfigContextState {
|
|
|
151
152
|
fetcher?: (url: string, init: RequestInit) => Promise<any>;
|
|
152
153
|
configStore: ConfigStore;
|
|
153
154
|
keyStore: OrderlyKeyStore;
|
|
154
|
-
getWalletAdapter: getWalletAdapterFunc;
|
|
155
155
|
walletAdapters: WalletAdapter[];
|
|
156
156
|
networkId: NetworkId;
|
|
157
157
|
/**
|
|
@@ -177,27 +177,37 @@ interface StatusContextState {
|
|
|
177
177
|
declare const StatusContext: react.Context<StatusContextState>;
|
|
178
178
|
declare const StatusProvider: React.FC<PropsWithChildren>;
|
|
179
179
|
|
|
180
|
-
type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
|
|
181
|
-
[K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
|
|
182
|
-
}[R];
|
|
183
180
|
type filteredChains = {
|
|
184
181
|
mainnet?: Chain$1[];
|
|
185
182
|
testnet?: Chain$1[];
|
|
186
183
|
};
|
|
187
184
|
type filterChainsFunc = (config: ConfigStore) => filteredChains;
|
|
188
|
-
|
|
189
|
-
configStore?: ConfigStore;
|
|
185
|
+
type BaseConfigProviderProps = {
|
|
190
186
|
keyStore?: OrderlyKeyStore;
|
|
191
187
|
contracts?: IContract;
|
|
192
|
-
|
|
193
|
-
walletAdapters: WalletAdapter[];
|
|
194
|
-
brokerId: string;
|
|
195
|
-
brokerName: string;
|
|
196
|
-
networkId: NetworkId;
|
|
188
|
+
walletAdapters?: WalletAdapter[];
|
|
197
189
|
chainFilter?: filteredChains | filterChainsFunc;
|
|
198
190
|
customChains?: Chains<undefined, undefined>;
|
|
191
|
+
};
|
|
192
|
+
type ConfigProviderExclusionProps = {
|
|
193
|
+
brokerId: string;
|
|
194
|
+
brokerName?: string;
|
|
195
|
+
networkId: NetworkId;
|
|
196
|
+
configStore?: never;
|
|
197
|
+
} | {
|
|
198
|
+
brokerId?: never;
|
|
199
|
+
brokerName?: never;
|
|
200
|
+
networkId?: never;
|
|
201
|
+
configStore: ConfigStore;
|
|
202
|
+
};
|
|
203
|
+
type ConfigProviderProps = BaseConfigProviderProps & ConfigProviderExclusionProps;
|
|
204
|
+
declare const OrderlyConfigProvider: FC<PropsWithChildren<ConfigProviderProps>>;
|
|
205
|
+
|
|
206
|
+
declare class ExtendedConfigStore extends DefaultConfigStore {
|
|
207
|
+
constructor(init: Partial<Record<ConfigKey, any>>);
|
|
208
|
+
get<T>(key: ConfigKey): T;
|
|
209
|
+
set<T>(key: ConfigKey, value: T): void;
|
|
199
210
|
}
|
|
200
|
-
declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
|
|
201
211
|
|
|
202
212
|
type ConnectedChain = {
|
|
203
213
|
id: number | string;
|
|
@@ -209,7 +219,7 @@ type WalletAccount = {
|
|
|
209
219
|
interface WalletState {
|
|
210
220
|
label: string;
|
|
211
221
|
icon: string;
|
|
212
|
-
provider: EIP1193Provider;
|
|
222
|
+
provider: EIP1193Provider | any;
|
|
213
223
|
accounts: WalletAccount[];
|
|
214
224
|
chains: ConnectedChain[];
|
|
215
225
|
instance?: unknown;
|
|
@@ -225,6 +235,7 @@ interface WalletConnectorContextState {
|
|
|
225
235
|
wallet: WalletState;
|
|
226
236
|
connectedChain: ConnectedChain | null;
|
|
227
237
|
settingChain: boolean;
|
|
238
|
+
namespace: ChainNamespace | null;
|
|
228
239
|
}
|
|
229
240
|
declare const WalletConnectorContext: react.Context<WalletConnectorContextState>;
|
|
230
241
|
declare const useWalletConnector: () => WalletConnectorContextState;
|
|
@@ -269,68 +280,6 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
|
|
|
269
280
|
middlePrice?: undefined;
|
|
270
281
|
})[];
|
|
271
282
|
|
|
272
|
-
type UseOrderEntryOptions = {
|
|
273
|
-
commify?: boolean;
|
|
274
|
-
watchOrderbook?: boolean;
|
|
275
|
-
validate?: (data: OrderEntity) => {
|
|
276
|
-
[P in keyof OrderEntity]?: string;
|
|
277
|
-
} | null | undefined;
|
|
278
|
-
};
|
|
279
|
-
type UseOrderEntryMetaState = {
|
|
280
|
-
errors: {
|
|
281
|
-
[P in keyof OrderEntity]?: {
|
|
282
|
-
type: string;
|
|
283
|
-
message: string;
|
|
284
|
-
};
|
|
285
|
-
} | null | undefined;
|
|
286
|
-
dirty: {
|
|
287
|
-
[P in keyof OrderEntity]?: boolean;
|
|
288
|
-
} | null | undefined;
|
|
289
|
-
submitted: boolean;
|
|
290
|
-
};
|
|
291
|
-
type UseOrderEntryReturn = {
|
|
292
|
-
maxQty: number;
|
|
293
|
-
freeCollateral: number;
|
|
294
|
-
markPrice: number;
|
|
295
|
-
estLiqPrice?: number | null;
|
|
296
|
-
estLeverage?: number | null;
|
|
297
|
-
onSubmit: (order: OrderEntity) => Promise<any>;
|
|
298
|
-
submit: () => Promise<OrderEntity>;
|
|
299
|
-
submitting: boolean;
|
|
300
|
-
formattedOrder: Partial<OrderEntity>;
|
|
301
|
-
helper: {
|
|
302
|
-
calculate: (values: Partial<OrderEntity>, field: keyof OrderEntity, value: any) => Partial<OrderEntity>;
|
|
303
|
-
validator: (values: Partial<OrderEntity>) => any;
|
|
304
|
-
};
|
|
305
|
-
metaState: UseOrderEntryMetaState;
|
|
306
|
-
symbolConfig: API.SymbolExt;
|
|
307
|
-
};
|
|
308
|
-
type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">>;
|
|
309
|
-
/**
|
|
310
|
-
* Create Order
|
|
311
|
-
* @example
|
|
312
|
-
* ```tsx
|
|
313
|
-
* import { useOrderEntry } from "@orderly.network/hooks";
|
|
314
|
-
* import {OrderSide, OrderType} from '@orderly.network/types';
|
|
315
|
-
*
|
|
316
|
-
* const { formattedOrder, onSubmit, helper } = useOrderEntry({
|
|
317
|
-
* symbol: "PERP_ETH_USDC",
|
|
318
|
-
* side: OrderSide.BUY,
|
|
319
|
-
* order_type: OrderType.LIMIT,
|
|
320
|
-
* order_price: 10000,
|
|
321
|
-
* order_quantity: 1,
|
|
322
|
-
* },{
|
|
323
|
-
* // **Note:** it's required
|
|
324
|
-
* watchOrderbook: true,
|
|
325
|
-
* });
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
declare function useOrderEntry(order: OrderParams, options?: UseOrderEntryOptions): UseOrderEntryReturn;
|
|
329
|
-
/**
|
|
330
|
-
* @deprecated
|
|
331
|
-
*/
|
|
332
|
-
declare function useOrderEntry(symbol: string, side: OrderSide, reduceOnly: boolean): UseOrderEntryReturn;
|
|
333
|
-
|
|
334
283
|
type ValueOf<T> = T[keyof T];
|
|
335
284
|
|
|
336
285
|
type SymbolInfo = ReturnType<typeof useSymbolsInfo>;
|
|
@@ -355,7 +304,7 @@ interface FavoriteTab$1 {
|
|
|
355
304
|
name: string;
|
|
356
305
|
id: number;
|
|
357
306
|
}
|
|
358
|
-
interface Favorite {
|
|
307
|
+
interface Favorite$1 {
|
|
359
308
|
name: string;
|
|
360
309
|
tabs: FavoriteTab$1[];
|
|
361
310
|
}
|
|
@@ -366,16 +315,17 @@ interface TabSort$1 {
|
|
|
366
315
|
sortKey: string;
|
|
367
316
|
sortOrder: string;
|
|
368
317
|
}
|
|
369
|
-
|
|
318
|
+
/** @deprecated use useMarkets instead */
|
|
319
|
+
declare const useMarket: (type: MarketsType$1) => readonly [any[], {
|
|
370
320
|
readonly favoriteTabs: {
|
|
371
321
|
name: string;
|
|
372
322
|
id: number;
|
|
373
323
|
}[];
|
|
374
|
-
readonly favorites: Favorite[];
|
|
324
|
+
readonly favorites: Favorite$1[];
|
|
375
325
|
readonly recent: Recent$1[];
|
|
376
326
|
readonly tabSort: Record<string, TabSort$1>;
|
|
377
327
|
readonly addToHistory: (symbol: API.MarketInfoExt) => void;
|
|
378
|
-
readonly updateFavorites: (favorites: Favorite[]) => void;
|
|
328
|
+
readonly updateFavorites: (favorites: Favorite$1[]) => void;
|
|
379
329
|
readonly updateFavoriteTabs: (tab: FavoriteTab$1 | FavoriteTab$1[], operator?: {
|
|
380
330
|
add?: boolean;
|
|
381
331
|
update?: boolean;
|
|
@@ -397,6 +347,10 @@ interface FavoriteTab {
|
|
|
397
347
|
name: string;
|
|
398
348
|
id: number;
|
|
399
349
|
}
|
|
350
|
+
interface Favorite {
|
|
351
|
+
name: string;
|
|
352
|
+
tabs: FavoriteTab[];
|
|
353
|
+
}
|
|
400
354
|
interface Recent {
|
|
401
355
|
name: string;
|
|
402
356
|
}
|
|
@@ -428,33 +382,59 @@ type MarketsItem = {
|
|
|
428
382
|
isFavorite: boolean;
|
|
429
383
|
leverage?: number;
|
|
430
384
|
};
|
|
431
|
-
declare const MarketsStorageKey = "
|
|
432
|
-
declare const
|
|
433
|
-
|
|
434
|
-
|
|
385
|
+
declare const MarketsStorageKey = "orderly_markets";
|
|
386
|
+
declare const useMarketsStore: () => {
|
|
387
|
+
favoriteTabs: FavoriteTab[];
|
|
388
|
+
favorites: {
|
|
435
389
|
tabs: FavoriteTab[];
|
|
436
390
|
name: string;
|
|
437
391
|
}[];
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
392
|
+
recent: Recent[];
|
|
393
|
+
tabSort: TabSort;
|
|
394
|
+
selectedFavoriteTab: FavoriteTab;
|
|
395
|
+
updateFavorites: react.Dispatch<react.SetStateAction<{
|
|
442
396
|
tabs: FavoriteTab[];
|
|
443
397
|
name: string;
|
|
444
398
|
}[]>>;
|
|
445
|
-
|
|
399
|
+
updateFavoriteTabs: (tab: FavoriteTab | FavoriteTab[], operator?: {
|
|
446
400
|
add?: boolean;
|
|
447
401
|
update?: boolean;
|
|
448
402
|
delete?: boolean;
|
|
449
403
|
}) => void;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
404
|
+
updateSymbolFavoriteState: (symbol: API.MarketInfoExt, tab: FavoriteTab | FavoriteTab[], remove?: boolean) => void;
|
|
405
|
+
pinToTop: (symbol: API.MarketInfoExt) => void;
|
|
406
|
+
addToHistory: (symbol: API.MarketInfoExt) => void;
|
|
407
|
+
updateSelectedFavoriteTab: (tab: FavoriteTab) => void;
|
|
408
|
+
updateTabsSortState: (tabId: string, sortKey: string, sortOrder: "desc" | "asc") => void;
|
|
409
|
+
};
|
|
410
|
+
declare const useMarkets: (type?: MarketsType) => readonly [MarketsItem[], {
|
|
411
|
+
favoriteTabs: FavoriteTab[];
|
|
412
|
+
favorites: {
|
|
413
|
+
tabs: FavoriteTab[];
|
|
414
|
+
name: string;
|
|
415
|
+
}[];
|
|
416
|
+
recent: Recent[];
|
|
417
|
+
tabSort: TabSort;
|
|
418
|
+
selectedFavoriteTab: FavoriteTab;
|
|
419
|
+
updateFavorites: react.Dispatch<react.SetStateAction<{
|
|
420
|
+
tabs: FavoriteTab[];
|
|
421
|
+
name: string;
|
|
422
|
+
}[]>>;
|
|
423
|
+
updateFavoriteTabs: (tab: FavoriteTab | FavoriteTab[], operator?: {
|
|
424
|
+
add?: boolean;
|
|
425
|
+
update?: boolean;
|
|
426
|
+
delete?: boolean;
|
|
427
|
+
}) => void;
|
|
428
|
+
updateSymbolFavoriteState: (symbol: API.MarketInfoExt, tab: FavoriteTab | FavoriteTab[], remove?: boolean) => void;
|
|
429
|
+
pinToTop: (symbol: API.MarketInfoExt) => void;
|
|
430
|
+
addToHistory: (symbol: API.MarketInfoExt) => void;
|
|
431
|
+
updateSelectedFavoriteTab: (tab: FavoriteTab) => void;
|
|
432
|
+
updateTabsSortState: (tabId: string, sortKey: string, sortOrder: "desc" | "asc") => void;
|
|
455
433
|
}];
|
|
456
434
|
|
|
457
|
-
declare const useMarkPricesStream: () =>
|
|
435
|
+
declare const useMarkPricesStream: () => {
|
|
436
|
+
data: Record<string, number>;
|
|
437
|
+
};
|
|
458
438
|
|
|
459
439
|
declare const useMarkPrice: (symbol: string) => {
|
|
460
440
|
data: number;
|
|
@@ -465,8 +445,8 @@ declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptio
|
|
|
465
445
|
declare const useLeverage: () => any;
|
|
466
446
|
|
|
467
447
|
declare const useTickerStream: (symbol: string) => API.MarketInfo & {
|
|
468
|
-
change?:
|
|
469
|
-
"24h_change"?:
|
|
448
|
+
change?: number | undefined;
|
|
449
|
+
"24h_change"?: number | undefined;
|
|
470
450
|
};
|
|
471
451
|
|
|
472
452
|
declare const useFundingRate: (symbol: string) => {
|
|
@@ -494,22 +474,30 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
|
|
|
494
474
|
*/
|
|
495
475
|
includedPendingOrder?: boolean;
|
|
496
476
|
}) => readonly [{
|
|
497
|
-
readonly rows: API.PositionTPSLExt[]
|
|
498
|
-
readonly aggregated:
|
|
499
|
-
readonly totalCollateral: Decimal;
|
|
500
|
-
readonly totalValue: Decimal;
|
|
477
|
+
readonly rows: API.PositionTPSLExt[];
|
|
478
|
+
readonly aggregated: Omit<API.PositionsTPSLExt, "rows">;
|
|
479
|
+
readonly totalCollateral: _orderly_network_utils.Decimal;
|
|
480
|
+
readonly totalValue: _orderly_network_utils.Decimal | null;
|
|
501
481
|
readonly totalUnrealizedROI: number;
|
|
502
482
|
}, {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
483
|
+
unsettledPnL: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
484
|
+
margin_ratio: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
485
|
+
initial_margin_ratio: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
486
|
+
maintenance_margin_ratio: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
487
|
+
open_margin_ratio: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
488
|
+
current_margin_ratio_with_orders: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
489
|
+
initial_margin_ratio_with_orders: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
490
|
+
maintenance_margin_ratio_with_orders: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
491
|
+
total_collateral_value: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
492
|
+
free_collateral: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
493
|
+
total_pnl_24_h: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
494
|
+
unrealPnL: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
495
|
+
total_unreal_pnl: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
496
|
+
total_unreal_pnl_index: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
497
|
+
total_unsettled_pnl: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
498
|
+
notional: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
499
|
+
unrealPnlROI: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
500
|
+
unrealPnlROI_index: (key?: "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | undefined, defaultValue?: ValueOf<Omit<API.PositionInfo, "rows">>) => any;
|
|
513
501
|
} & {
|
|
514
502
|
isNil: boolean;
|
|
515
503
|
}, {
|
|
@@ -518,9 +506,6 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
|
|
|
518
506
|
*/
|
|
519
507
|
readonly loading: boolean;
|
|
520
508
|
readonly isLoading: boolean;
|
|
521
|
-
readonly isValidating: boolean;
|
|
522
|
-
readonly error: any;
|
|
523
|
-
readonly refresh: swr__internal.KeyedMutator<API.PositionInfo>;
|
|
524
509
|
}];
|
|
525
510
|
|
|
526
511
|
type CombineOrderType = AlgoOrderRootType | "ALL";
|
|
@@ -593,10 +578,9 @@ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStream
|
|
|
593
578
|
type CollateralOutputs = {
|
|
594
579
|
totalCollateral: number;
|
|
595
580
|
freeCollateral: number;
|
|
596
|
-
totalValue: number;
|
|
581
|
+
totalValue: number | null;
|
|
597
582
|
availableBalance: number;
|
|
598
583
|
unsettledPnL: number;
|
|
599
|
-
positions: API.Position[];
|
|
600
584
|
accountInfo?: API.AccountInfo;
|
|
601
585
|
};
|
|
602
586
|
declare const useCollateral: (options?: {
|
|
@@ -614,7 +598,7 @@ declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean)
|
|
|
614
598
|
|
|
615
599
|
type MarginRatioReturn = {
|
|
616
600
|
marginRatio: number;
|
|
617
|
-
currentLeverage: number;
|
|
601
|
+
currentLeverage: number | null;
|
|
618
602
|
mmr: number | null;
|
|
619
603
|
};
|
|
620
604
|
declare const useMarginRatio: () => MarginRatioReturn;
|
|
@@ -717,7 +701,7 @@ type PriceRange = {
|
|
|
717
701
|
*/
|
|
718
702
|
declare const useSymbolPriceRange: (symbol: string, side: "BUY" | "SELL", price?: number) => PriceRange | undefined;
|
|
719
703
|
|
|
720
|
-
type
|
|
704
|
+
type TPSLComputedData = {
|
|
721
705
|
/**
|
|
722
706
|
* Computed take profit
|
|
723
707
|
*/
|
|
@@ -730,7 +714,8 @@ type ComputedAlgoOrder = Partial<AlgoOrderEntity<AlgoOrderRootType.TP_SL> & {
|
|
|
730
714
|
sl_pnl: number;
|
|
731
715
|
sl_offset: number;
|
|
732
716
|
sl_offset_percentage: number;
|
|
733
|
-
}
|
|
717
|
+
};
|
|
718
|
+
type ComputedAlgoOrder = Partial<AlgoOrderEntity<AlgoOrderRootType.TP_SL> & TPSLComputedData>;
|
|
734
719
|
type ValidateError = {
|
|
735
720
|
[P in keyof ComputedAlgoOrder]?: {
|
|
736
721
|
type: string;
|
|
@@ -744,27 +729,16 @@ declare const useTPSLOrder: (position: Partial<API.PositionTPSLExt> & Pick<API.P
|
|
|
744
729
|
* it is usually used when editing order
|
|
745
730
|
*/
|
|
746
731
|
defaultOrder?: API.AlgoOrder;
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
tp_offset: number;
|
|
750
|
-
tp_offset_percentage: number;
|
|
751
|
-
sl_pnl: number;
|
|
752
|
-
sl_offset: number;
|
|
753
|
-
sl_offset_percentage: number;
|
|
754
|
-
}>, {
|
|
732
|
+
isEditing?: boolean;
|
|
733
|
+
}) => [Partial<Omit<_orderly_network_types.BaseAlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL>, "type" | "side" | "trigger_price" | "order_type"> & Partial<Pick<_orderly_network_types.BaseAlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL>, "type" | "side" | "trigger_price" | "order_type">> & TPSLComputedData>, {
|
|
755
734
|
setValue: (key: string, value: string | number) => void;
|
|
756
|
-
setValues: (values: Partial<Partial<Omit<_orderly_network_types.BaseAlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL>, "type" | "side" | "
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
tp_offset_percentage: number;
|
|
760
|
-
sl_pnl: number;
|
|
761
|
-
sl_offset: number;
|
|
762
|
-
sl_offset_percentage: number;
|
|
763
|
-
}>>) => void;
|
|
764
|
-
submit: () => Promise<void>;
|
|
735
|
+
setValues: (values: Partial<Partial<Omit<_orderly_network_types.BaseAlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL>, "type" | "side" | "trigger_price" | "order_type"> & Partial<Pick<_orderly_network_types.BaseAlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL>, "type" | "side" | "trigger_price" | "order_type">> & TPSLComputedData>>) => void;
|
|
736
|
+
submit: () => Promise<any>;
|
|
737
|
+
deleteOrder: (orderId: number, symbol: string) => Promise<any>;
|
|
765
738
|
errors: ValidateError | null;
|
|
766
739
|
validate: () => Promise<_orderly_network_types.AlgoOrderEntity<_orderly_network_types.AlgoOrderRootType.TP_SL | _orderly_network_types.AlgoOrderRootType.POSITIONAL_TP_SL>>;
|
|
767
740
|
isCreateMutating: boolean;
|
|
741
|
+
isUpdateMutating: boolean;
|
|
768
742
|
}];
|
|
769
743
|
|
|
770
744
|
declare const useSymbolLeverage: (symbol: string) => number | "-";
|
|
@@ -857,6 +831,76 @@ declare function useMaintenanceStatus(): {
|
|
|
857
831
|
endTime: number | undefined;
|
|
858
832
|
};
|
|
859
833
|
|
|
834
|
+
declare const useMarkPriceBySymbol: (symbol: string) => number;
|
|
835
|
+
|
|
836
|
+
type PositionActions = {
|
|
837
|
+
setPositions: (key: string, positions: API.PositionsTPSLExt) => void;
|
|
838
|
+
clearAll: () => void;
|
|
839
|
+
};
|
|
840
|
+
declare const usePositionActions: () => PositionActions;
|
|
841
|
+
|
|
842
|
+
type UseOrderEntryOptions = {
|
|
843
|
+
commify?: boolean;
|
|
844
|
+
watchOrderbook?: boolean;
|
|
845
|
+
validate?: (data: OrderEntity) => {
|
|
846
|
+
[P in keyof OrderEntity]?: string;
|
|
847
|
+
} | null | undefined;
|
|
848
|
+
};
|
|
849
|
+
type UseOrderEntryMetaState = {
|
|
850
|
+
errors: {
|
|
851
|
+
[P in keyof OrderEntity]?: {
|
|
852
|
+
type: string;
|
|
853
|
+
message: string;
|
|
854
|
+
};
|
|
855
|
+
} | null | undefined;
|
|
856
|
+
dirty: {
|
|
857
|
+
[P in keyof OrderEntity]?: boolean;
|
|
858
|
+
} | null | undefined;
|
|
859
|
+
submitted: boolean;
|
|
860
|
+
};
|
|
861
|
+
type UseOrderEntryReturn = {
|
|
862
|
+
maxQty: number;
|
|
863
|
+
freeCollateral: number;
|
|
864
|
+
markPrice: number;
|
|
865
|
+
estLiqPrice?: number | null;
|
|
866
|
+
estLeverage?: number | null;
|
|
867
|
+
onSubmit: (order: OrderEntity) => Promise<any>;
|
|
868
|
+
submit: () => Promise<OrderEntity>;
|
|
869
|
+
submitting: boolean;
|
|
870
|
+
formattedOrder: Partial<OrderEntity>;
|
|
871
|
+
helper: {
|
|
872
|
+
calculate: (values: Partial<OrderlyOrder>, field: keyof OrderEntity, value: any) => Partial<OrderEntity>;
|
|
873
|
+
validator: (values: Partial<OrderEntity>) => any;
|
|
874
|
+
};
|
|
875
|
+
metaState: UseOrderEntryMetaState;
|
|
876
|
+
symbolConfig: API.SymbolExt;
|
|
877
|
+
};
|
|
878
|
+
type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">>;
|
|
879
|
+
/**
|
|
880
|
+
* Create Order
|
|
881
|
+
* @example
|
|
882
|
+
* ```tsx
|
|
883
|
+
* import { useOrderEntry } from "@orderly.network/hooks";
|
|
884
|
+
* import {OrderSide, OrderType} from '@orderly.network/types';
|
|
885
|
+
*
|
|
886
|
+
* const { formattedOrder, onSubmit, helper } = useOrderEntry({
|
|
887
|
+
* symbol: "PERP_ETH_USDC",
|
|
888
|
+
* side: OrderSide.BUY,
|
|
889
|
+
* order_type: OrderType.LIMIT,
|
|
890
|
+
* order_price: 10000,
|
|
891
|
+
* order_quantity: 1,
|
|
892
|
+
* },{
|
|
893
|
+
* // **Note:** it's required
|
|
894
|
+
* watchOrderbook: true,
|
|
895
|
+
* });
|
|
896
|
+
* ```
|
|
897
|
+
*/
|
|
898
|
+
declare function useOrderEntry$1(order: OrderParams, options?: UseOrderEntryOptions): UseOrderEntryReturn;
|
|
899
|
+
/**
|
|
900
|
+
* @deprecated
|
|
901
|
+
*/
|
|
902
|
+
declare function useOrderEntry$1(symbol: string, side: OrderSide, reduceOnly: boolean): UseOrderEntryReturn;
|
|
903
|
+
|
|
860
904
|
declare function useMediaQuery(query: string): boolean;
|
|
861
905
|
|
|
862
906
|
type posterDataSource = {
|
|
@@ -1017,6 +1061,8 @@ declare function getPositionBySymbol(symbol: string): void;
|
|
|
1017
1061
|
|
|
1018
1062
|
/**
|
|
1019
1063
|
* TP/SL price -> pnl
|
|
1064
|
+
* @price trigger_price
|
|
1065
|
+
* @entryPrice calculate price, maybe markPrice/limitPrice/order.price
|
|
1020
1066
|
*/
|
|
1021
1067
|
declare function priceToPnl(inputs: {
|
|
1022
1068
|
qty: number;
|
|
@@ -1025,10 +1071,16 @@ declare function priceToPnl(inputs: {
|
|
|
1025
1071
|
orderSide: OrderSide;
|
|
1026
1072
|
orderType: AlgoOrderType;
|
|
1027
1073
|
}, options?: {
|
|
1028
|
-
symbol?: API.SymbolExt
|
|
1074
|
+
symbol?: Pick<API.SymbolExt, "quote_dp">;
|
|
1029
1075
|
}): number;
|
|
1076
|
+
declare function calcTPSL_ROI(inputs: {
|
|
1077
|
+
pnl: number | string;
|
|
1078
|
+
qty: number | string;
|
|
1079
|
+
price: number | string;
|
|
1080
|
+
}): string;
|
|
1030
1081
|
|
|
1031
1082
|
type index_ValueOf<T> = ValueOf<T>;
|
|
1083
|
+
declare const index_calcTPSL_ROI: typeof calcTPSL_ROI;
|
|
1032
1084
|
declare const index_cleanStringStyle: typeof cleanStringStyle;
|
|
1033
1085
|
declare const index_findPositionTPSLFromOrders: typeof findPositionTPSLFromOrders;
|
|
1034
1086
|
declare const index_findTPSLFromOrder: typeof findTPSLFromOrder;
|
|
@@ -1037,7 +1089,7 @@ declare const index_formatNumber: typeof formatNumber;
|
|
|
1037
1089
|
declare const index_getPositionBySymbol: typeof getPositionBySymbol;
|
|
1038
1090
|
declare const index_priceToPnl: typeof priceToPnl;
|
|
1039
1091
|
declare namespace index {
|
|
1040
|
-
export { type index_ValueOf as ValueOf, index_cleanStringStyle as cleanStringStyle, index_findPositionTPSLFromOrders as findPositionTPSLFromOrders, index_findTPSLFromOrder as findTPSLFromOrder, index_findTPSLFromOrders as findTPSLFromOrders, index_formatNumber as formatNumber, index_getPositionBySymbol as getPositionBySymbol, index_priceToPnl as priceToPnl };
|
|
1092
|
+
export { type index_ValueOf as ValueOf, index_calcTPSL_ROI as calcTPSL_ROI, index_cleanStringStyle as cleanStringStyle, index_findPositionTPSLFromOrders as findPositionTPSLFromOrders, index_findTPSLFromOrder as findTPSLFromOrder, index_findTPSLFromOrders as findTPSLFromOrders, index_formatNumber as formatNumber, index_getPositionBySymbol as getPositionBySymbol, index_priceToPnl as priceToPnl };
|
|
1041
1093
|
}
|
|
1042
1094
|
|
|
1043
1095
|
declare const useCommission: (options?: {
|
|
@@ -1250,7 +1302,7 @@ type EpochInfoType = [
|
|
|
1250
1302
|
{
|
|
1251
1303
|
isLoading: boolean;
|
|
1252
1304
|
curEpochInfo: EpochInfoItem | undefined;
|
|
1253
|
-
|
|
1305
|
+
isNotStared: boolean;
|
|
1254
1306
|
refresh: () => void;
|
|
1255
1307
|
}
|
|
1256
1308
|
];
|
|
@@ -1259,6 +1311,7 @@ declare const useEpochInfo: (type: TWType) => EpochInfoType;
|
|
|
1259
1311
|
type Brokers = {
|
|
1260
1312
|
[key: string]: string;
|
|
1261
1313
|
};
|
|
1314
|
+
/** get all brokers, will be callback a list */
|
|
1262
1315
|
declare const useAllBrokers: () => readonly [Brokers | undefined];
|
|
1263
1316
|
|
|
1264
1317
|
type CurrentEpochEstimateRow = {
|
|
@@ -1318,14 +1371,14 @@ type WalletRewards = {
|
|
|
1318
1371
|
wallet_lifetime_trading_rewards_escrow: string;
|
|
1319
1372
|
rows: WalletRewardsItem[];
|
|
1320
1373
|
};
|
|
1321
|
-
type
|
|
1374
|
+
type WalletRewardsHistoryReturns = [
|
|
1322
1375
|
WalletRewards | undefined,
|
|
1323
1376
|
{
|
|
1324
1377
|
refresh: () => void;
|
|
1325
1378
|
error?: any;
|
|
1326
1379
|
}
|
|
1327
1380
|
];
|
|
1328
|
-
declare const useWalletRewardsHistory: (type: TWType) =>
|
|
1381
|
+
declare const useWalletRewardsHistory: (type: TWType) => WalletRewardsHistoryReturns;
|
|
1329
1382
|
|
|
1330
1383
|
declare enum ENVType {
|
|
1331
1384
|
prod = "prod",
|
|
@@ -1364,8 +1417,222 @@ declare const useApiKeyManager: (queryParams?: {
|
|
|
1364
1417
|
secretKey: string;
|
|
1365
1418
|
}>;
|
|
1366
1419
|
readonly setIPRestriction: (orderly_key: string, ip_restriction_list: string) => Promise<any>;
|
|
1367
|
-
readonly
|
|
1420
|
+
readonly removeOrderlyKey: (orderly_key: string) => Promise<any>;
|
|
1368
1421
|
readonly resetOrderlyKeyIPRestriction: (orderlyKey: string, mode: "ALLOW_ALL_IPS" | "DISALLOW_ALL_IPS") => Promise<any>;
|
|
1369
1422
|
}];
|
|
1370
1423
|
|
|
1371
|
-
|
|
1424
|
+
type FullOrderState = OrderlyOrder;
|
|
1425
|
+
type OrderEntryStateEntity = RequireKeys<FullOrderState, "side" | "order_type" | "symbol">;
|
|
1426
|
+
type OrderEntryState = {
|
|
1427
|
+
entry: OrderEntryStateEntity;
|
|
1428
|
+
estLeverage: number | null;
|
|
1429
|
+
estLiquidationPrice: number | null;
|
|
1430
|
+
errors: Partial<Record<keyof FullOrderState, string>>;
|
|
1431
|
+
};
|
|
1432
|
+
type OrderEntryActions = {
|
|
1433
|
+
updateOrder: (order: Partial<FullOrderState>) => void;
|
|
1434
|
+
updateOrderByKey: <K extends keyof FullOrderState>(key: K, value: FullOrderState[K]) => void;
|
|
1435
|
+
restoreOrder: (order?: Partial<FullOrderState>) => void;
|
|
1436
|
+
updateOrderComputed: (data: {
|
|
1437
|
+
estLeverage: number | null;
|
|
1438
|
+
estLiquidationPrice: number | null;
|
|
1439
|
+
}) => void;
|
|
1440
|
+
resetOrder: (order?: Partial<FullOrderState>) => void;
|
|
1441
|
+
hasTP_SL: () => boolean;
|
|
1442
|
+
};
|
|
1443
|
+
declare const useOrderStore: zustand.UseBoundStore<Omit<zustand.StoreApi<OrderEntryState & {
|
|
1444
|
+
actions: OrderEntryActions;
|
|
1445
|
+
}>, "setState"> & {
|
|
1446
|
+
setState(nextStateOrUpdater: (OrderEntryState & {
|
|
1447
|
+
actions: OrderEntryActions;
|
|
1448
|
+
}) | Partial<OrderEntryState & {
|
|
1449
|
+
actions: OrderEntryActions;
|
|
1450
|
+
}> | ((state: immer.WritableDraft<OrderEntryState & {
|
|
1451
|
+
actions: OrderEntryActions;
|
|
1452
|
+
}>) => void), shouldReplace?: boolean | undefined): void;
|
|
1453
|
+
}>;
|
|
1454
|
+
|
|
1455
|
+
type VerifyResult = {
|
|
1456
|
+
[P in keyof OrderlyOrder]?: {
|
|
1457
|
+
type: string;
|
|
1458
|
+
message: string;
|
|
1459
|
+
};
|
|
1460
|
+
};
|
|
1461
|
+
type ValuesDepConfig = {
|
|
1462
|
+
symbol: API.SymbolExt;
|
|
1463
|
+
maxQty: number;
|
|
1464
|
+
markPrice: number;
|
|
1465
|
+
};
|
|
1466
|
+
interface OrderCreator<T> {
|
|
1467
|
+
create: (values: T, configs: ValuesDepConfig) => T;
|
|
1468
|
+
validate: (values: T, configs: ValuesDepConfig) => Promise<{
|
|
1469
|
+
[P in keyof T]?: {
|
|
1470
|
+
type: string;
|
|
1471
|
+
message: string;
|
|
1472
|
+
};
|
|
1473
|
+
}>;
|
|
1474
|
+
get type(): OrderType;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
declare const useOrderEntryNextInternal: (symbol: string, options?: {
|
|
1478
|
+
/**
|
|
1479
|
+
* initial order state, default is buy limit order
|
|
1480
|
+
*
|
|
1481
|
+
*/
|
|
1482
|
+
initialOrder?: Omit<Partial<FullOrderState>, "symbol">;
|
|
1483
|
+
symbolInfo?: API.SymbolExt;
|
|
1484
|
+
}) => {
|
|
1485
|
+
readonly formattedOrder: Required<Pick<OrderlyOrder, "symbol" | "side" | "order_type">> & Partial<Omit<OrderlyOrder, "symbol" | "side" | "order_type">>;
|
|
1486
|
+
readonly setValue: (key: keyof FullOrderState, value: any, additional?: {
|
|
1487
|
+
markPrice: number;
|
|
1488
|
+
}) => Partial<OrderlyOrder> | undefined;
|
|
1489
|
+
readonly setValues: (values: Partial<FullOrderState>, additional?: {
|
|
1490
|
+
markPrice: number;
|
|
1491
|
+
}) => Partial<OrderlyOrder> | undefined;
|
|
1492
|
+
readonly submit: () => void;
|
|
1493
|
+
readonly reset: (order?: Partial<OrderlyOrder>) => void;
|
|
1494
|
+
readonly generateOrder: (creator: OrderCreator<any>, options: {
|
|
1495
|
+
maxQty: number;
|
|
1496
|
+
markPrice: number;
|
|
1497
|
+
}) => any;
|
|
1498
|
+
readonly validate: (order: Partial<OrderlyOrder>, creator: OrderCreator<any>, options: {
|
|
1499
|
+
maxQty: number;
|
|
1500
|
+
markPrice: number;
|
|
1501
|
+
}) => Promise<{
|
|
1502
|
+
[x: string]: {
|
|
1503
|
+
type: string;
|
|
1504
|
+
message: string;
|
|
1505
|
+
} | undefined;
|
|
1506
|
+
}>;
|
|
1507
|
+
readonly onMarkPriceChange: (markPrice: number, baseOn?: "total" | "order_quantity") => void;
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
type OrderEntryParameters = Parameters<typeof useOrderEntryNextInternal>;
|
|
1511
|
+
type Options = Omit<OrderEntryParameters["1"], "symbolInfo">;
|
|
1512
|
+
type OrderEntryReturn = {
|
|
1513
|
+
submit: (options?: {
|
|
1514
|
+
resetOnSuccess?: boolean;
|
|
1515
|
+
}) => Promise<void>;
|
|
1516
|
+
reset: () => void;
|
|
1517
|
+
resetErrors: () => void;
|
|
1518
|
+
resetMetaState: () => void;
|
|
1519
|
+
formattedOrder: Partial<FullOrderState>;
|
|
1520
|
+
maxQty: number;
|
|
1521
|
+
/**
|
|
1522
|
+
* The estimated liquidation price.
|
|
1523
|
+
*/
|
|
1524
|
+
estLiqPrice: number | null;
|
|
1525
|
+
/**
|
|
1526
|
+
* The estimated leverage after order creation.
|
|
1527
|
+
*/
|
|
1528
|
+
estLeverage: number | null;
|
|
1529
|
+
helper: {
|
|
1530
|
+
/**
|
|
1531
|
+
* @deprecated Use `validate` instead.
|
|
1532
|
+
*/
|
|
1533
|
+
validator: () => Promise<VerifyResult | null>;
|
|
1534
|
+
/**
|
|
1535
|
+
* Function to validate the order.
|
|
1536
|
+
* @returns {Promise<VerifyResult | null>} The validation result.
|
|
1537
|
+
*/
|
|
1538
|
+
validate: () => Promise<VerifyResult | null>;
|
|
1539
|
+
};
|
|
1540
|
+
freeCollateral: number;
|
|
1541
|
+
/**
|
|
1542
|
+
* set a single value to the order data;
|
|
1543
|
+
* @param key
|
|
1544
|
+
* @param value
|
|
1545
|
+
* @returns
|
|
1546
|
+
*/
|
|
1547
|
+
setValue: (key: keyof FullOrderState, value: any, options?: {
|
|
1548
|
+
shouldUpdateLastChangedField?: boolean;
|
|
1549
|
+
}) => void;
|
|
1550
|
+
setValues: (values: Partial<FullOrderState>) => void;
|
|
1551
|
+
symbolInfo: API.SymbolExt;
|
|
1552
|
+
/**
|
|
1553
|
+
* Meta state including validation and submission status.
|
|
1554
|
+
*/
|
|
1555
|
+
metaState: {
|
|
1556
|
+
dirty: {
|
|
1557
|
+
[K in keyof OrderlyOrder]?: boolean;
|
|
1558
|
+
};
|
|
1559
|
+
submitted: boolean;
|
|
1560
|
+
validated: boolean;
|
|
1561
|
+
errors: VerifyResult | null;
|
|
1562
|
+
};
|
|
1563
|
+
/**
|
|
1564
|
+
* Indicates if a mutation (order creation) is in progress.
|
|
1565
|
+
*/
|
|
1566
|
+
isMutating: boolean;
|
|
1567
|
+
markPrice: number | undefined;
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Custom hook for managing order entry in the Orderly application.
|
|
1571
|
+
*
|
|
1572
|
+
* @param {string} symbol - The symbol for which the order is being created. This parameter is required.
|
|
1573
|
+
*
|
|
1574
|
+
* @param {Options} options - Additional options for configuring the order entry.
|
|
1575
|
+
*
|
|
1576
|
+
* @returns {OrderEntryReturn} An object containing various actions and state related to order entry.
|
|
1577
|
+
*
|
|
1578
|
+
* @throws {Error} Throws an error if the symbol is not provided or is not a string.
|
|
1579
|
+
*
|
|
1580
|
+
* @example
|
|
1581
|
+
* ```typescript
|
|
1582
|
+
* const {
|
|
1583
|
+
* submit,
|
|
1584
|
+
* formattedOrder, //
|
|
1585
|
+
* setValue,
|
|
1586
|
+
* setValues,
|
|
1587
|
+
* symbolInfo,
|
|
1588
|
+
* metaState,
|
|
1589
|
+
* isMutating,
|
|
1590
|
+
* // maxQty, freeCollateral ... same as v1
|
|
1591
|
+
* } = useOrderEntry('BTC_USDC_PERP', options);
|
|
1592
|
+
*
|
|
1593
|
+
* // update the order type
|
|
1594
|
+
* setValue('order_type', OrderType.LIMIT);
|
|
1595
|
+
* // update the order price
|
|
1596
|
+
* setValue('order_price', '70000');
|
|
1597
|
+
* // update the order quantity
|
|
1598
|
+
* setValue('order_quantity', 1);
|
|
1599
|
+
*
|
|
1600
|
+
* // how to set TP/SL
|
|
1601
|
+
* setValue('tp_trigger_price', '71000'); // directly set TP trigger price
|
|
1602
|
+
* // or set the tp pnl, the TP trigger price will be calculated based on the current order price
|
|
1603
|
+
* // setValue('tp_pnl', '300'); // you can also set tp_offset or tp_offset_percentage, same as the usage of useTPSL hook;
|
|
1604
|
+
* // SL is similar to TP setting
|
|
1605
|
+
* setValue('sl_price', '69000');
|
|
1606
|
+
*
|
|
1607
|
+
* // Submit the order data to the backend, and reset the hook state after the order is successfully created.
|
|
1608
|
+
* // Note: If the order data is invalid, an error will be thrown.
|
|
1609
|
+
* // If you want to retain the current order data after a successful order creation,
|
|
1610
|
+
* // you can pass {resetOnSuccess: false} to `submit` function to prevent the hook from automatically resetting the order status.
|
|
1611
|
+
* // Of course, you can also call `reset()` to manually reset the order status and use `resetMetaState()` to clear the error state.
|
|
1612
|
+
* await submit();
|
|
1613
|
+
* ```
|
|
1614
|
+
*/
|
|
1615
|
+
declare const useOrderEntry: (symbol: string, options: Options) => OrderEntryReturn;
|
|
1616
|
+
|
|
1617
|
+
declare const useOrderEntity: (order: {
|
|
1618
|
+
[key: string]: any;
|
|
1619
|
+
symbol: string;
|
|
1620
|
+
side: OrderSide;
|
|
1621
|
+
reduce_only?: boolean | undefined;
|
|
1622
|
+
}, options?: {
|
|
1623
|
+
maxQty?: number;
|
|
1624
|
+
}) => {
|
|
1625
|
+
validate: () => Promise<VerifyResult | null>;
|
|
1626
|
+
errors: Partial<Record<string | number, {
|
|
1627
|
+
type: string;
|
|
1628
|
+
message: string;
|
|
1629
|
+
}>> | undefined;
|
|
1630
|
+
markPrice: number;
|
|
1631
|
+
symbolInfo: {
|
|
1632
|
+
[x: string]: (key?: keyof _orderly_network_types.API.SymbolExt | undefined, defaultValue?: ValueOf<_orderly_network_types.API.SymbolExt> | undefined) => any;
|
|
1633
|
+
} & {
|
|
1634
|
+
isNil: boolean;
|
|
1635
|
+
};
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1638
|
+
export { type APIKeyItem, type AccountRewardsHistory, type AccountRewardsHistoryRow, AssetHistoryStatusEnum, type Brokers, type Chain, type Chains, type CheckReferralCodeReturns, type CollateralOutputs, type ComputedAlgoOrder, type ConfigProviderExclusionProps, type ConfigProviderProps, type ConnectedChain, type CurrentEpochEstimate, DefaultLayoutConfig, DistributionId, type DrawOptions, ENVType, type EpochInfoItem, type EpochInfoType, ExtendedConfigStore, type Favorite, type FavoriteTab, MarketsStorageKey, MarketsType, type OrderBookItem, type OrderParams, type OrderbookData, type OrderbookOptions, type OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, type PosterLayoutConfig, type PriceMode, type Recent, RefferalAPI, ScopeType, StatusContext, type StatusContextState, StatusProvider, type SymbolInfo, TWType, type UseChainsOptions, type UseChainsReturnObject, type UseOrderEntryMetaState, WalletConnectorContext, type WalletRewards, type WalletRewardsHistoryReturns, type WalletRewardsItem, type WalletState, WsNetworkStatus, type chainFilter, type chainFilterFunc, checkNotional, cleanStringStyle, type filteredChains$1 as filteredChains, parseJSON, useAccount, useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAssetsHistory, useBoolean, useChain, useChains, useCheckReferralCode, useCollateral, useCommission, useConfig, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEventEmitter, useFundingFeeHistory, useFundingRate, useFundingRates, useGetClaimed, useGetEnv, useGetReferralCode, useHoldingStream, useIndexPrice, useKeyStore, useLazyQuery, useLeverage, useLocalStorage, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useOrderEntity, useOrderEntry, useOrderEntry$1 as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, usePositionActions, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useTPSLOrder, useTickerStream, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWithdraw, useWsStatus, index as utils, _default as version };
|