@orderly.network/hooks 2.8.1 → 2.8.2-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 +330 -16
- package/dist/index.d.ts +330 -16
- package/dist/index.js +999 -463
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +988 -464
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as swr from 'swr';
|
|
2
|
-
import { SWRConfiguration, SWRHook, SWRResponse } from 'swr';
|
|
2
|
+
import { SWRConfiguration, SWRHook, SWRResponse, Middleware } from 'swr';
|
|
3
3
|
export { swr };
|
|
4
4
|
export { KeyedMutator, Middleware, SWRConfiguration, SWRHook, SWRResponse, unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
|
|
5
5
|
import * as swr_mutation from 'swr/mutation';
|
|
@@ -22,9 +22,12 @@ import { SolanaWalletProvider } from '@orderly.network/default-solana-adapter';
|
|
|
22
22
|
import * as swr_subscription from 'swr/subscription';
|
|
23
23
|
import * as _orderly_network_utils from '@orderly.network/utils';
|
|
24
24
|
import { Decimal } from '@orderly.network/utils';
|
|
25
|
-
export * from 'use-debounce';
|
|
26
25
|
import * as immer from 'immer';
|
|
27
26
|
import * as zustand from 'zustand';
|
|
27
|
+
import { StoreMutatorIdentifier, StateCreator } from 'zustand';
|
|
28
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
29
|
+
import { PersistOptions } from 'zustand/middleware';
|
|
30
|
+
export * from 'use-debounce';
|
|
28
31
|
|
|
29
32
|
declare global {
|
|
30
33
|
interface Window {
|
|
@@ -33,7 +36,7 @@ declare global {
|
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
declare const _default: "2.8.
|
|
39
|
+
declare const _default: "2.8.2-alpha.0";
|
|
37
40
|
|
|
38
41
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
39
42
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -49,6 +52,16 @@ declare const noCacheConfig: SWRConfiguration;
|
|
|
49
52
|
*/
|
|
50
53
|
declare const useQuery: <T>(query: Parameters<SWRHook>[0], options?: useQueryOptions<T>) => SWRResponse<T>;
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* SWR middleware that waits for __ORDERLY_timestamp_offset to be initialized
|
|
57
|
+
* before allowing requests to proceed.
|
|
58
|
+
*/
|
|
59
|
+
declare const timestampWaitingMiddleware: Middleware;
|
|
60
|
+
/**
|
|
61
|
+
* Reset timestamp state (for testing or re-initialization)
|
|
62
|
+
*/
|
|
63
|
+
declare function resetTimestampOffsetState(): void;
|
|
64
|
+
|
|
52
65
|
/**
|
|
53
66
|
* useQuery
|
|
54
67
|
* @description for public api
|
|
@@ -356,7 +369,7 @@ declare const useAccount: () => {
|
|
|
356
369
|
declare const useAccountInstance: () => Account;
|
|
357
370
|
|
|
358
371
|
declare const usePreLoadData: () => {
|
|
359
|
-
error:
|
|
372
|
+
error: null;
|
|
360
373
|
done: boolean;
|
|
361
374
|
};
|
|
362
375
|
|
|
@@ -480,7 +493,7 @@ interface OrderlyConfigContextState {
|
|
|
480
493
|
customChains?: Chains<undefined, undefined>;
|
|
481
494
|
chainTransformer?: (params: {
|
|
482
495
|
chains: API.Chain[];
|
|
483
|
-
tokenChains: API.
|
|
496
|
+
tokenChains: API.Token[];
|
|
484
497
|
chainInfos: any[];
|
|
485
498
|
swapChains: any[];
|
|
486
499
|
mainnet: boolean;
|
|
@@ -926,16 +939,89 @@ declare const useFundingRateHistory: () => {
|
|
|
926
939
|
getPositiveRates: (data: ReadonlyArray<API.FundingHistory> | API.FundingHistory[], period: PeriodKey) => Record<string, number>;
|
|
927
940
|
};
|
|
928
941
|
|
|
942
|
+
/**
|
|
943
|
+
* Price mode for PnL calculations in position streams
|
|
944
|
+
* @typedef {("markPrice" | "lastPrice")} PriceMode
|
|
945
|
+
* - markPrice: Uses mark price for unrealized PnL calculations (default)
|
|
946
|
+
* - lastPrice: Uses last traded price (index price) for unrealized PnL calculations
|
|
947
|
+
*/
|
|
929
948
|
type PriceMode = "markPrice" | "lastPrice";
|
|
930
|
-
declare const usePositionStream: (
|
|
931
949
|
/**
|
|
932
|
-
*
|
|
950
|
+
* Real-time position stream hook with WebSocket integration
|
|
951
|
+
*
|
|
952
|
+
* Subscribes to position updates via WebSocket and provides real-time position data with automatic
|
|
953
|
+
* calculations for unrealized PnL, ROI, and aggregated portfolio metrics. Integrates TP/SL orders
|
|
954
|
+
* and supports both full portfolio view and single symbol tracking.
|
|
955
|
+
*
|
|
956
|
+
* **Key Features:**
|
|
957
|
+
* - Real-time WebSocket updates for positions
|
|
958
|
+
* - Automatic integration of TP/SL (take-profit/stop-loss) orders
|
|
959
|
+
* - Dual price mode support (mark price vs last price)
|
|
960
|
+
* - Optional pending order inclusion
|
|
961
|
+
* - Calculator service integration for real-time PnL updates
|
|
962
|
+
* - Aggregated portfolio metrics (total collateral, value, ROI)
|
|
963
|
+
*
|
|
964
|
+
* **Price Calculation Modes:**
|
|
965
|
+
* - markPrice (default): Uses mark price for unrealized PnL - recommended for margin calculations
|
|
966
|
+
* - lastPrice: Uses last traded price (index price) - useful for more conservative PnL views
|
|
967
|
+
*
|
|
968
|
+
* **Data Flow:**
|
|
969
|
+
* 1. Subscribes to position store (WebSocket-driven)
|
|
970
|
+
* 2. Fetches related TP/SL orders via useOrderStream
|
|
971
|
+
* 3. Registers calculator for real-time price updates (single symbol only)
|
|
972
|
+
* 4. Merges position data with TP/SL information
|
|
973
|
+
* 5. Applies price mode transformations
|
|
974
|
+
* 6. Filters positions based on includedPendingOrder flag
|
|
975
|
+
*
|
|
976
|
+
* @param {string} [symbol="all"] - Trading symbol to filter positions, or "all" for entire portfolio
|
|
977
|
+
* - "all": Returns all positions across all symbols (calculator not registered)
|
|
978
|
+
* - "BTC-PERP": Returns only BTC-PERP position (calculator registered for real-time updates)
|
|
979
|
+
*
|
|
980
|
+
* @param {Object} [options] - Configuration options extending SWR configuration
|
|
981
|
+
* @param {PriceMode} [options.calcMode] - Price calculation mode: "markPrice" or "lastPrice"
|
|
982
|
+
* - markPrice: Uses mark_price field for unrealized_pnl (default, matches exchange calculations)
|
|
983
|
+
* - lastPrice: Uses unrealized_pnl_index field based on last traded price
|
|
984
|
+
* @param {boolean} [options.includedPendingOrder=false] - Include positions with only pending orders
|
|
985
|
+
* - false: Only returns positions with non-zero position_qty
|
|
986
|
+
* - true: Returns positions with position_qty !== 0 OR pending_long_qty/pending_short_qty !== 0
|
|
987
|
+
*
|
|
988
|
+
* @returns {readonly [PositionData, PositionInfoGetter, LoadingState]} Tuple containing:
|
|
989
|
+
* - [0] PositionData object:
|
|
990
|
+
* - rows: Array of position objects with TP/SL information
|
|
991
|
+
* - aggregated: Aggregated metrics (total unrealized PnL, ROI, etc.)
|
|
992
|
+
* - totalCollateral: Total collateral across all positions
|
|
993
|
+
* - totalValue: Total portfolio value
|
|
994
|
+
* - totalUnrealizedROI: Total unrealized ROI percentage
|
|
995
|
+
* - [1] PositionInfoGetter: Memoized getter function for aggregated data access
|
|
996
|
+
* - [2] LoadingState object:
|
|
997
|
+
* - loading: Loading status (deprecated, use isLoading)
|
|
998
|
+
* - isLoading: Current loading state of position data
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* // Get all positions with mark price calculation
|
|
1002
|
+
* const [{ rows, aggregated, totalCollateral }] = usePositionStream();
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* // Get single symbol position with last price calculation
|
|
1006
|
+
* const [{ rows }] = usePositionStream("BTC-PERP", {
|
|
1007
|
+
* calcMode: "lastPrice"
|
|
1008
|
+
* });
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* // Include pending orders in results
|
|
1012
|
+
* const [{ rows }, getter, { isLoading }] = usePositionStream("all", {
|
|
1013
|
+
* includedPendingOrder: true
|
|
1014
|
+
* });
|
|
1015
|
+
*
|
|
1016
|
+
* @example
|
|
1017
|
+
* // Access specific position with TP/SL data
|
|
1018
|
+
* const [{ rows }] = usePositionStream("ETH-PERP");
|
|
1019
|
+
* const position = rows[0];
|
|
1020
|
+
* console.log(position.full_tp_sl.tp_trigger_price); // Full position TP price
|
|
1021
|
+
* console.log(position.partial_tp_sl.order_num); // Number of partial TP/SL orders
|
|
933
1022
|
*/
|
|
934
|
-
symbol?: string, options?: SWRConfiguration & {
|
|
1023
|
+
declare const usePositionStream: (symbol?: string, options?: SWRConfiguration & {
|
|
935
1024
|
calcMode?: PriceMode;
|
|
936
|
-
/**
|
|
937
|
-
* If true, the pending order will be included in the result.
|
|
938
|
-
*/
|
|
939
1025
|
includedPendingOrder?: boolean;
|
|
940
1026
|
}) => readonly [{
|
|
941
1027
|
readonly rows: API.PositionTPSLExt[];
|
|
@@ -1239,8 +1325,8 @@ declare const useDeposit: (options: DepositOptions) => {
|
|
|
1239
1325
|
depositFeeRevalidating: boolean;
|
|
1240
1326
|
approve: (amount?: string) => Promise<void | undefined>;
|
|
1241
1327
|
deposit: () => Promise<any>;
|
|
1242
|
-
fetchBalance: (address: string, decimals?: number) => Promise<string>;
|
|
1243
|
-
fetchBalances: (tokens: API.TokenInfo[]) => Promise<string
|
|
1328
|
+
fetchBalance: (address: string, decimals?: number, token?: string) => Promise<string>;
|
|
1329
|
+
fetchBalances: (tokens: API.TokenInfo[]) => Promise<Record<string, string>>;
|
|
1244
1330
|
/** set input quantity */
|
|
1245
1331
|
setQuantity: react.Dispatch<react.SetStateAction<string>>;
|
|
1246
1332
|
};
|
|
@@ -1653,11 +1739,11 @@ declare const useStorageLedgerAddress: () => {
|
|
|
1653
1739
|
/**
|
|
1654
1740
|
* return all tokens info
|
|
1655
1741
|
*/
|
|
1656
|
-
declare const useTokensInfo: () => API.
|
|
1742
|
+
declare const useTokensInfo: () => _orderly_network_types.API.Token[] | undefined;
|
|
1657
1743
|
/**
|
|
1658
1744
|
* return token info by specify token
|
|
1659
1745
|
*/
|
|
1660
|
-
declare const useTokenInfo: (token: string) => API.
|
|
1746
|
+
declare const useTokenInfo: (token: string) => _orderly_network_types.API.Token | undefined;
|
|
1661
1747
|
|
|
1662
1748
|
/**
|
|
1663
1749
|
* Check if currently trading based on next_open/next_close timestamps
|
|
@@ -1755,6 +1841,12 @@ declare const useGetRwaSymbolOpenTimeInterval: (symbol: string, thresholdMinutes
|
|
|
1755
1841
|
nextOpen?: number;
|
|
1756
1842
|
};
|
|
1757
1843
|
|
|
1844
|
+
type AppStatus = {
|
|
1845
|
+
positionsLoading: boolean;
|
|
1846
|
+
ordersLoading: boolean;
|
|
1847
|
+
fundingRatesLoading: boolean;
|
|
1848
|
+
ready: boolean;
|
|
1849
|
+
};
|
|
1758
1850
|
type Portfolio$1 = {
|
|
1759
1851
|
holding?: API.Holding[];
|
|
1760
1852
|
totalCollateral: Decimal;
|
|
@@ -1764,9 +1856,143 @@ type Portfolio$1 = {
|
|
|
1764
1856
|
unsettledPnL: number;
|
|
1765
1857
|
totalUnrealizedROI: number;
|
|
1766
1858
|
};
|
|
1859
|
+
type AppState = {
|
|
1860
|
+
accountInfo?: API.AccountInfo;
|
|
1861
|
+
symbolsInfo?: Record<string, API.SymbolExt>;
|
|
1862
|
+
tokensInfo?: API.Token[];
|
|
1863
|
+
rwaSymbolsInfo?: Record<string, API.RwaSymbol>;
|
|
1864
|
+
fundingRates?: Record<string, API.FundingRate>;
|
|
1865
|
+
portfolio: Portfolio$1;
|
|
1866
|
+
appState: AppStatus;
|
|
1867
|
+
};
|
|
1868
|
+
type AppActions = {
|
|
1869
|
+
cleanAll: () => void;
|
|
1870
|
+
setAccountInfo: (accountInfo: API.AccountInfo) => void;
|
|
1871
|
+
setTokensInfo: (tokensInfo: API.Token[]) => void;
|
|
1872
|
+
setSymbolsInfo: (symbolsInfo: Record<string, API.SymbolExt>) => void;
|
|
1873
|
+
setRwaSymbolsInfo: (rwaSymbolsInfo: Record<string, API.RwaSymbol>) => void;
|
|
1874
|
+
setFundingRates: (fundingRates: Record<string, API.FundingRate>) => void;
|
|
1875
|
+
updateAppStatus: (key: keyof AppStatus, value: boolean) => void;
|
|
1876
|
+
updatePortfolio: (key: keyof Omit<Portfolio$1, "usdc" | "holding">, value: number | Decimal) => void;
|
|
1877
|
+
batchUpdateForPortfolio: (data: Partial<Portfolio$1>) => void;
|
|
1878
|
+
restoreHolding: (holding: API.Holding[]) => void;
|
|
1879
|
+
updateHolding: (msg: Record<string, WSMessage.Holding>) => void;
|
|
1880
|
+
};
|
|
1881
|
+
/**
|
|
1882
|
+
* @warning This store should be used with caution. It contains sensitive account and portfolio data.
|
|
1883
|
+
* Please ensure you have proper authorization and follow security best practices when using this store.
|
|
1884
|
+
*
|
|
1885
|
+
* @example
|
|
1886
|
+
* // Correct usage:
|
|
1887
|
+
* const accountInfo = useAppStore(state => state.accountInfo);
|
|
1888
|
+
*
|
|
1889
|
+
* // Avoid direct store manipulation:
|
|
1890
|
+
* const store = useAppStore.getState(); // Not recommended
|
|
1891
|
+
*/
|
|
1892
|
+
declare const useAppStore: zustand.UseBoundStore<Omit<zustand.StoreApi<AppState & {
|
|
1893
|
+
actions: AppActions;
|
|
1894
|
+
}>, "setState"> & {
|
|
1895
|
+
setState(nextStateOrUpdater: (AppState & {
|
|
1896
|
+
actions: AppActions;
|
|
1897
|
+
}) | Partial<AppState & {
|
|
1898
|
+
actions: AppActions;
|
|
1899
|
+
}> | ((state: immer.WritableDraft<AppState & {
|
|
1900
|
+
actions: AppActions;
|
|
1901
|
+
}>) => void), shouldReplace?: boolean | undefined): void;
|
|
1902
|
+
}>;
|
|
1767
1903
|
declare const usePortfolio: () => Portfolio$1;
|
|
1768
1904
|
declare const useFundingRateBySymbol: (symbol: string) => API.FundingRate | undefined;
|
|
1769
1905
|
|
|
1906
|
+
/**
|
|
1907
|
+
* Generic store state for data fetching
|
|
1908
|
+
*/
|
|
1909
|
+
interface DataStoreState<T> {
|
|
1910
|
+
data: T[] | null;
|
|
1911
|
+
loading: boolean;
|
|
1912
|
+
error: Error | null;
|
|
1913
|
+
name: string;
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Generic store actions for data fetching
|
|
1917
|
+
*/
|
|
1918
|
+
interface DataStoreActions<T> {
|
|
1919
|
+
fetchData: (baseUrl?: string, options?: {
|
|
1920
|
+
brokerId?: string;
|
|
1921
|
+
}) => Promise<T[]>;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
declare const useMainnetChainsStore: zustand.UseBoundStore<Omit<zustand.StoreApi<DataStoreState<API.Chain> & DataStoreActions<API.Chain>>, "persist"> & {
|
|
1925
|
+
persist: {
|
|
1926
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<DataStoreState<API.Chain> & DataStoreActions<API.Chain>, T>>) => void;
|
|
1927
|
+
clearStorage: () => void;
|
|
1928
|
+
rehydrate: () => Promise<void> | void;
|
|
1929
|
+
hasHydrated: () => boolean;
|
|
1930
|
+
onHydrate: (fn: (state: DataStoreState<API.Chain> & DataStoreActions<API.Chain>) => void) => () => void;
|
|
1931
|
+
onFinishHydration: (fn: (state: DataStoreState<API.Chain> & DataStoreActions<API.Chain>) => void) => () => void;
|
|
1932
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<DataStoreState<API.Chain> & DataStoreActions<API.Chain>, T>>;
|
|
1933
|
+
};
|
|
1934
|
+
}>;
|
|
1935
|
+
|
|
1936
|
+
declare const useTestnetChainsStore: zustand.UseBoundStore<Omit<zustand.StoreApi<DataStoreState<API.Chain> & DataStoreActions<API.Chain>>, "persist"> & {
|
|
1937
|
+
persist: {
|
|
1938
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<DataStoreState<API.Chain> & DataStoreActions<API.Chain>, T>>) => void;
|
|
1939
|
+
clearStorage: () => void;
|
|
1940
|
+
rehydrate: () => Promise<void> | void;
|
|
1941
|
+
hasHydrated: () => boolean;
|
|
1942
|
+
onHydrate: (fn: (state: DataStoreState<API.Chain> & DataStoreActions<API.Chain>) => void) => () => void;
|
|
1943
|
+
onFinishHydration: (fn: (state: DataStoreState<API.Chain> & DataStoreActions<API.Chain>) => void) => () => void;
|
|
1944
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<DataStoreState<API.Chain> & DataStoreActions<API.Chain>, T>>;
|
|
1945
|
+
};
|
|
1946
|
+
}>;
|
|
1947
|
+
|
|
1948
|
+
declare const useMainTokenStore: zustand.UseBoundStore<Omit<zustand.StoreApi<DataStoreState<API.Token> & DataStoreActions<API.Token>>, "persist"> & {
|
|
1949
|
+
persist: {
|
|
1950
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<DataStoreState<API.Token> & DataStoreActions<API.Token>, T>>) => void;
|
|
1951
|
+
clearStorage: () => void;
|
|
1952
|
+
rehydrate: () => Promise<void> | void;
|
|
1953
|
+
hasHydrated: () => boolean;
|
|
1954
|
+
onHydrate: (fn: (state: DataStoreState<API.Token> & DataStoreActions<API.Token>) => void) => () => void;
|
|
1955
|
+
onFinishHydration: (fn: (state: DataStoreState<API.Token> & DataStoreActions<API.Token>) => void) => () => void;
|
|
1956
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<DataStoreState<API.Token> & DataStoreActions<API.Token>, T>>;
|
|
1957
|
+
};
|
|
1958
|
+
}>;
|
|
1959
|
+
|
|
1960
|
+
declare const useTestTokenStore: zustand.UseBoundStore<Omit<zustand.StoreApi<DataStoreState<API.Token> & DataStoreActions<API.Token>>, "persist"> & {
|
|
1961
|
+
persist: {
|
|
1962
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<DataStoreState<API.Token> & DataStoreActions<API.Token>, T>>) => void;
|
|
1963
|
+
clearStorage: () => void;
|
|
1964
|
+
rehydrate: () => Promise<void> | void;
|
|
1965
|
+
hasHydrated: () => boolean;
|
|
1966
|
+
onHydrate: (fn: (state: DataStoreState<API.Token> & DataStoreActions<API.Token>) => void) => () => void;
|
|
1967
|
+
onFinishHydration: (fn: (state: DataStoreState<API.Token> & DataStoreActions<API.Token>) => void) => () => void;
|
|
1968
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<DataStoreState<API.Token> & DataStoreActions<API.Token>, T>>;
|
|
1969
|
+
};
|
|
1970
|
+
}>;
|
|
1971
|
+
|
|
1972
|
+
type SwapSupport = {
|
|
1973
|
+
data: Record<string, any> | null;
|
|
1974
|
+
loading: boolean;
|
|
1975
|
+
error: Error | null;
|
|
1976
|
+
};
|
|
1977
|
+
type SwapSupportActions = {
|
|
1978
|
+
fetchData: () => Promise<Record<string, any> | null>;
|
|
1979
|
+
};
|
|
1980
|
+
declare const useSwapSupportStore: zustand.UseBoundStore<Omit<zustand.StoreApi<SwapSupport & SwapSupportActions>, "persist"> & {
|
|
1981
|
+
persist: {
|
|
1982
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<SwapSupport & SwapSupportActions, {
|
|
1983
|
+
data: Record<string, any> | null;
|
|
1984
|
+
}>>) => void;
|
|
1985
|
+
clearStorage: () => void;
|
|
1986
|
+
rehydrate: () => Promise<void> | void;
|
|
1987
|
+
hasHydrated: () => boolean;
|
|
1988
|
+
onHydrate: (fn: (state: SwapSupport & SwapSupportActions) => void) => () => void;
|
|
1989
|
+
onFinishHydration: (fn: (state: SwapSupport & SwapSupportActions) => void) => () => void;
|
|
1990
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<SwapSupport & SwapSupportActions, {
|
|
1991
|
+
data: Record<string, any> | null;
|
|
1992
|
+
}>>;
|
|
1993
|
+
};
|
|
1994
|
+
}>;
|
|
1995
|
+
|
|
1770
1996
|
type UseOrderEntryOptions = {
|
|
1771
1997
|
commify?: boolean;
|
|
1772
1998
|
watchOrderbook?: boolean;
|
|
@@ -2220,6 +2446,94 @@ declare const useApiKeyManager: (queryParams?: {
|
|
|
2220
2446
|
readonly resetOrderlyKeyIPRestriction: (orderlyKey: string, mode: "ALLOW_ALL_IPS" | "DISALLOW_ALL_IPS") => Promise<any>;
|
|
2221
2447
|
}];
|
|
2222
2448
|
|
|
2449
|
+
interface StoreConfig {
|
|
2450
|
+
name: string;
|
|
2451
|
+
keyPath?: string;
|
|
2452
|
+
autoIncrement?: boolean;
|
|
2453
|
+
}
|
|
2454
|
+
interface DatabaseConfig {
|
|
2455
|
+
name: string;
|
|
2456
|
+
version: number;
|
|
2457
|
+
stores: StoreConfig[];
|
|
2458
|
+
}
|
|
2459
|
+
declare class IndexedDBManager {
|
|
2460
|
+
private static instance;
|
|
2461
|
+
private connections;
|
|
2462
|
+
private databaseConfig;
|
|
2463
|
+
/** Promise that resolves when database initialization is complete */
|
|
2464
|
+
private initializationPromise;
|
|
2465
|
+
static getInstance(): IndexedDBManager;
|
|
2466
|
+
initializeDatabase(config: DatabaseConfig): Promise<void>;
|
|
2467
|
+
/**
|
|
2468
|
+
* Performs the actual database initialization
|
|
2469
|
+
* Now keeps the connection open for better performance
|
|
2470
|
+
*/
|
|
2471
|
+
private _performInitialization;
|
|
2472
|
+
/**
|
|
2473
|
+
* Handles initialization errors consistently
|
|
2474
|
+
*/
|
|
2475
|
+
private _handleInitializationError;
|
|
2476
|
+
getConnection(dbName: string, storeName: string): Promise<IDBDatabase>;
|
|
2477
|
+
/**
|
|
2478
|
+
* Ensures database is initialized, initializes if not already done
|
|
2479
|
+
*/
|
|
2480
|
+
private ensureInitialized;
|
|
2481
|
+
/**
|
|
2482
|
+
* Creates a new database connection
|
|
2483
|
+
*/
|
|
2484
|
+
private createConnection;
|
|
2485
|
+
/**
|
|
2486
|
+
* Checks if database and all required stores exist
|
|
2487
|
+
*/
|
|
2488
|
+
private _checkDatabaseExists;
|
|
2489
|
+
}
|
|
2490
|
+
declare const indexedDBManager: IndexedDBManager;
|
|
2491
|
+
declare const initializeAppDatabase: (config: DatabaseConfig) => Promise<void>;
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Configuration for IndexedDB storage
|
|
2495
|
+
*/
|
|
2496
|
+
interface IndexedDBStorageConfig {
|
|
2497
|
+
/** Database name */
|
|
2498
|
+
dbName: string;
|
|
2499
|
+
/** Object store name */
|
|
2500
|
+
storeName: string;
|
|
2501
|
+
}
|
|
2502
|
+
/**
|
|
2503
|
+
* Configuration options for IndexedDB persistence middleware
|
|
2504
|
+
*/
|
|
2505
|
+
type IndexedDBPersistOptions<T, U = T> = Omit<PersistOptions<T, U>, "storage"> & {
|
|
2506
|
+
/** IndexedDB configuration */
|
|
2507
|
+
indexedDBConfig: IndexedDBStorageConfig;
|
|
2508
|
+
};
|
|
2509
|
+
/**
|
|
2510
|
+
* Creates a Zustand store with IndexedDB persistence
|
|
2511
|
+
*
|
|
2512
|
+
* @param initializer - The state creator function
|
|
2513
|
+
* @param options - Persistence options including IndexedDB configuration
|
|
2514
|
+
* @returns A state creator with IndexedDB persistence middleware applied
|
|
2515
|
+
*
|
|
2516
|
+
* @example
|
|
2517
|
+
* ```typescript
|
|
2518
|
+
* const useStore = create(
|
|
2519
|
+
* persistIndexedDB(
|
|
2520
|
+
* (set) => ({
|
|
2521
|
+
* items: [],
|
|
2522
|
+
* addItem: (item) => set((state) => ({ items: [...state.items, item] })),
|
|
2523
|
+
* }),
|
|
2524
|
+
* {
|
|
2525
|
+
* name: 'my-store',
|
|
2526
|
+
* indexedDBConfig: {
|
|
2527
|
+
* dbName: 'ORDERLY_STORE',
|
|
2528
|
+
* storeName: 'ITEMS_STORE',
|
|
2529
|
+
* },
|
|
2530
|
+
* }
|
|
2531
|
+
* )
|
|
2532
|
+
* );
|
|
2533
|
+
* ```
|
|
2534
|
+
*/
|
|
2535
|
+
declare const persistIndexedDB: <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], U = T>(initializer: StateCreator<T, [...Mps, ["zustand/persist", unknown]], Mcs>, options: IndexedDBPersistOptions<T, U>) => StateCreator<T, Mps, [["zustand/persist", U], ...Mcs]>;
|
|
2536
|
+
|
|
2223
2537
|
type FullOrderState = OrderlyOrder;
|
|
2224
2538
|
type OrderEntryStateEntity = RequireKeys<FullOrderState, "side" | "order_type" | "symbol">;
|
|
2225
2539
|
type OrderEntryState = {
|
|
@@ -2529,4 +2843,4 @@ declare const usePositionClose: (options: PositionCloseOptions) => {
|
|
|
2529
2843
|
declare const useMarketList: () => API.MarketInfoExt[];
|
|
2530
2844
|
declare const useMarketMap: () => Record<string, API.MarketInfoExt> | null;
|
|
2531
2845
|
|
|
2532
|
-
export { type APIKeyItem, type AccountRewardsHistory, type AccountRewardsHistoryRow, type Brokers, type Chain, type ChainFilter, type Chains, type CheckReferralCodeReturns, type CollateralOutputs, type ComputedAlgoOrder, type ConfigProviderProps, type ConnectedChain, type CurrentEpochEstimate, DefaultLayoutConfig, DistributionId, type DrawOptions, ENVType, type EpochInfoItem, type EpochInfoType, EpochStatus, type ExclusiveConfigProviderProps, ExtendedConfigStore, type Favorite, type FavoriteTab, type FilteredChains, type FundingRates, MaintenanceStatus, type MarginRatioReturn, type MarketsItem, MarketsStorageKey, type MarketsStore, MarketsType, type NewListing, ORDERLY_ORDERBOOK_DEPTH_KEY, type OrderBookItem, type OrderEntryReturn, type OrderMetadata, type OrderMetadataConfig, type OrderParams, type OrderValidationItem, type OrderValidationResult, type OrderbookData, type OrderbookOptions, type OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, type PosterLayoutConfig, type PriceMode, type Recent, RefferalAPI, type RestrictedInfoOptions, type RestrictedInfoReturns, type RwaSymbolResult, type RwaSymbolsInfo, ScopeType, type StatusInfo, StatusProvider, type SymbolsInfo, TWType, type UseChainsOptions, type UseChainsReturnObject, type UseOrderEntryMetaState, WalletConnectorContext, type WalletConnectorContextState, type WalletRewards, type WalletRewardsHistoryReturns, type WalletRewardsItem, type WalletState, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, useAccount, useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEventEmitter, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry, useOrderEntry$1 as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, type useQueryOptions, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSymbolInfo, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTickerStream, useTokenInfo, useTokensInfo, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, index as utils, _default as version };
|
|
2846
|
+
export { type APIKeyItem, type AccountRewardsHistory, type AccountRewardsHistoryRow, type Brokers, type Chain, type ChainFilter, type Chains, type CheckReferralCodeReturns, type CollateralOutputs, type ComputedAlgoOrder, type ConfigProviderProps, type ConnectedChain, type CurrentEpochEstimate, DefaultLayoutConfig, DistributionId, type DrawOptions, ENVType, type EpochInfoItem, type EpochInfoType, EpochStatus, type ExclusiveConfigProviderProps, ExtendedConfigStore, type Favorite, type FavoriteTab, type FilteredChains, type FundingRates, MaintenanceStatus, type MarginRatioReturn, type MarketsItem, MarketsStorageKey, type MarketsStore, MarketsType, type NewListing, ORDERLY_ORDERBOOK_DEPTH_KEY, type OrderBookItem, type OrderEntryReturn, type OrderMetadata, type OrderMetadataConfig, type OrderParams, type OrderValidationItem, type OrderValidationResult, type OrderbookData, type OrderbookOptions, type OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, type PosterLayoutConfig, type PriceMode, type Recent, RefferalAPI, type RestrictedInfoOptions, type RestrictedInfoReturns, type RwaSymbolResult, type RwaSymbolsInfo, ScopeType, type StatusInfo, StatusProvider, type SymbolsInfo, TWType, type UseChainsOptions, type UseChainsReturnObject, type UseOrderEntryMetaState, WalletConnectorContext, type WalletConnectorContextState, type WalletRewards, type WalletRewardsHistoryReturns, type WalletRewardsItem, type WalletState, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEventEmitter, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry, useOrderEntry$1 as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, type useQueryOptions, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, index as utils, _default as version };
|