@0xmonaco/react 0.7.7 → 0.7.9

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.
Files changed (109) hide show
  1. package/dist/hooks/index.d.ts +15 -0
  2. package/dist/hooks/index.js +15 -0
  3. package/dist/hooks/useAuth/index.d.ts +2 -0
  4. package/dist/hooks/useAuth/index.js +1 -0
  5. package/dist/hooks/useAuth/types.d.ts +30 -0
  6. package/dist/hooks/useAuth/types.js +0 -0
  7. package/dist/hooks/useAuth/useAuth.d.ts +2 -0
  8. package/dist/hooks/useAuth/useAuth.js +145 -0
  9. package/dist/hooks/useFees/index.d.ts +2 -0
  10. package/dist/hooks/useFees/index.js +1 -0
  11. package/dist/hooks/useFees/types.d.ts +5 -0
  12. package/dist/hooks/useFees/types.js +0 -0
  13. package/dist/hooks/useFees/useFees.d.ts +2 -0
  14. package/dist/hooks/useFees/useFees.js +14 -0
  15. package/dist/hooks/useMarket/index.d.ts +2 -0
  16. package/dist/hooks/useMarket/index.js +1 -0
  17. package/dist/hooks/useMarket/types.d.ts +30 -0
  18. package/dist/hooks/useMarket/types.js +0 -0
  19. package/dist/hooks/useMarket/useMarket.d.ts +2 -0
  20. package/dist/hooks/useMarket/useMarket.js +92 -0
  21. package/dist/hooks/useMonaco/index.d.ts +2 -0
  22. package/dist/hooks/useMonaco/index.js +1 -0
  23. package/dist/hooks/useMonaco/types.d.ts +13 -0
  24. package/dist/hooks/useMonaco/types.js +0 -0
  25. package/dist/hooks/useMonaco/useMonaco.d.ts +2 -0
  26. package/dist/hooks/useMonaco/useMonaco.js +13 -0
  27. package/dist/hooks/useOHLCV/index.d.ts +2 -0
  28. package/dist/hooks/useOHLCV/index.js +2 -0
  29. package/dist/hooks/useOHLCV/types.d.ts +29 -0
  30. package/dist/hooks/useOHLCV/types.js +0 -0
  31. package/dist/hooks/useOHLCV/useOHLCV.d.ts +11 -0
  32. package/dist/hooks/useOHLCV/useOHLCV.js +76 -0
  33. package/dist/hooks/useOrderbook/index.d.ts +2 -0
  34. package/dist/hooks/useOrderbook/index.js +1 -0
  35. package/dist/hooks/useOrderbook/types.d.ts +27 -0
  36. package/dist/hooks/useOrderbook/types.js +0 -0
  37. package/dist/hooks/useOrderbook/useOrderbook.d.ts +3 -0
  38. package/dist/hooks/useOrderbook/useOrderbook.js +31 -0
  39. package/dist/hooks/usePositions/index.d.ts +2 -0
  40. package/dist/hooks/usePositions/index.js +1 -0
  41. package/dist/hooks/usePositions/types.d.ts +11 -0
  42. package/dist/hooks/usePositions/types.js +0 -0
  43. package/dist/hooks/usePositions/usePositions.d.ts +2 -0
  44. package/dist/hooks/usePositions/usePositions.js +65 -0
  45. package/dist/hooks/useProfile/index.d.ts +2 -0
  46. package/dist/hooks/useProfile/index.js +1 -0
  47. package/dist/hooks/useProfile/types.d.ts +23 -0
  48. package/dist/hooks/useProfile/types.js +0 -0
  49. package/dist/hooks/useProfile/useProfile.d.ts +2 -0
  50. package/dist/hooks/useProfile/useProfile.js +128 -0
  51. package/dist/hooks/useTokenLifecycle/index.d.ts +2 -0
  52. package/dist/hooks/useTokenLifecycle/index.js +1 -0
  53. package/dist/hooks/useTokenLifecycle/types.d.ts +23 -0
  54. package/dist/hooks/useTokenLifecycle/types.js +0 -0
  55. package/dist/hooks/useTokenLifecycle/useTokenLifecycle.d.ts +20 -0
  56. package/dist/hooks/useTokenLifecycle/useTokenLifecycle.js +125 -0
  57. package/dist/hooks/useTokenLifecycle/utils.d.ts +7 -0
  58. package/dist/hooks/useTokenLifecycle/utils.js +15 -0
  59. package/dist/hooks/useTrade/index.d.ts +2 -0
  60. package/dist/hooks/useTrade/index.js +1 -0
  61. package/dist/hooks/useTrade/types.d.ts +53 -0
  62. package/dist/hooks/useTrade/types.js +0 -0
  63. package/dist/hooks/useTrade/useTrade.d.ts +2 -0
  64. package/dist/hooks/useTrade/useTrade.js +132 -0
  65. package/dist/hooks/useTradeFeed/index.d.ts +2 -0
  66. package/dist/hooks/useTradeFeed/index.js +2 -0
  67. package/dist/hooks/useTradeFeed/types.d.ts +14 -0
  68. package/dist/hooks/useTradeFeed/types.js +0 -0
  69. package/dist/hooks/useTradeFeed/useTradeFeed.d.ts +12 -0
  70. package/dist/hooks/useTradeFeed/useTradeFeed.js +32 -0
  71. package/dist/hooks/useUserBalances/index.d.ts +2 -0
  72. package/dist/hooks/useUserBalances/index.js +2 -0
  73. package/dist/hooks/useUserBalances/types.d.ts +18 -0
  74. package/dist/hooks/useUserBalances/types.js +0 -0
  75. package/dist/hooks/useUserBalances/useUserBalances.d.ts +9 -0
  76. package/dist/hooks/useUserBalances/useUserBalances.js +171 -0
  77. package/dist/hooks/useUserMovements/index.d.ts +2 -0
  78. package/dist/hooks/useUserMovements/index.js +2 -0
  79. package/dist/hooks/useUserMovements/types.d.ts +23 -0
  80. package/dist/hooks/useUserMovements/types.js +0 -0
  81. package/dist/hooks/useUserMovements/useUserMovements.d.ts +18 -0
  82. package/dist/hooks/useUserMovements/useUserMovements.js +122 -0
  83. package/dist/hooks/useUserOrders/index.d.ts +2 -0
  84. package/dist/hooks/useUserOrders/index.js +2 -0
  85. package/dist/hooks/useUserOrders/types.d.ts +18 -0
  86. package/dist/hooks/useUserOrders/types.js +0 -0
  87. package/dist/hooks/useUserOrders/useUserOrders.d.ts +11 -0
  88. package/dist/hooks/useUserOrders/useUserOrders.js +191 -0
  89. package/dist/hooks/useVault/index.d.ts +2 -0
  90. package/dist/hooks/useVault/index.js +1 -0
  91. package/dist/hooks/useVault/types.d.ts +15 -0
  92. package/dist/hooks/useVault/types.js +0 -0
  93. package/dist/hooks/useVault/useVault.d.ts +2 -0
  94. package/dist/hooks/useVault/useVault.js +66 -0
  95. package/dist/index.d.ts +3 -0
  96. package/dist/index.js +3 -0
  97. package/dist/provider/MonacoProvider.d.ts +3 -0
  98. package/dist/provider/MonacoProvider.js +142 -0
  99. package/dist/provider/TradeFeedProvider.d.ts +22 -0
  100. package/dist/provider/TradeFeedProvider.js +143 -0
  101. package/dist/provider/index.d.ts +3 -0
  102. package/dist/provider/index.js +3 -0
  103. package/dist/provider/types.d.ts +49 -0
  104. package/dist/provider/types.js +9 -0
  105. package/dist/utils/index.d.ts +1 -0
  106. package/dist/utils/index.js +1 -0
  107. package/dist/utils/tokenStorage.d.ts +38 -0
  108. package/dist/utils/tokenStorage.js +102 -0
  109. package/package.json +3 -3
@@ -0,0 +1,15 @@
1
+ export * from "./useAuth";
2
+ export * from "./useFees";
3
+ export * from "./useMarket";
4
+ export * from "./useMonaco";
5
+ export * from "./useOHLCV";
6
+ export * from "./useOrderbook";
7
+ export * from "./usePositions";
8
+ export * from "./useProfile";
9
+ export * from "./useTokenLifecycle";
10
+ export * from "./useTrade";
11
+ export * from "./useTradeFeed";
12
+ export * from "./useUserBalances";
13
+ export * from "./useUserMovements";
14
+ export * from "./useUserOrders";
15
+ export * from "./useVault";
@@ -0,0 +1,15 @@
1
+ export * from "./useAuth";
2
+ export * from "./useFees";
3
+ export * from "./useMarket";
4
+ export * from "./useMonaco";
5
+ export * from "./useOHLCV";
6
+ export * from "./useOrderbook";
7
+ export * from "./usePositions";
8
+ export * from "./useProfile";
9
+ export * from "./useTokenLifecycle";
10
+ export * from "./useTrade";
11
+ export * from "./useTradeFeed";
12
+ export * from "./useUserBalances";
13
+ export * from "./useUserMovements";
14
+ export * from "./useUserOrders";
15
+ export * from "./useVault";
@@ -0,0 +1,2 @@
1
+ export type * from "./types";
2
+ export { useAuth } from "./useAuth";
@@ -0,0 +1 @@
1
+ export { useAuth } from "./useAuth";
@@ -0,0 +1,30 @@
1
+ import type { AuthState, ChallengeResponse, TokenRefreshResponse } from "@0xmonaco/types";
2
+ import type { AuthenticationStatus } from "../../provider";
3
+ export interface UseAuthState {
4
+ /** Current authentication status */
5
+ authenticationStatus: AuthenticationStatus;
6
+ }
7
+ export interface UseAuthReturn extends UseAuthState {
8
+ /**
9
+ * Complete authentication flow. Returns AuthState with accessToken and refreshToken.
10
+ * @param options - Optional configuration
11
+ * @param options.connectWebSocket - Auto-connect all authenticated WebSocket channels after login (currently Orders) (default: false)
12
+ */
13
+ login: (options?: {
14
+ connectWebSocket?: boolean;
15
+ }) => Promise<AuthState>;
16
+ /** Logout user and clear state. Revokes the refresh token on the server. */
17
+ logout: () => Promise<void>;
18
+ /** Refresh authentication tokens using the stored refresh token. */
19
+ refreshAuth: () => Promise<AuthState>;
20
+ /** Sign a challenge message with the connected wallet. */
21
+ signChallenge: (message: string) => Promise<string>;
22
+ /** Create authentication challenge for the given address. */
23
+ createChallenge: (address: string) => Promise<ChallengeResponse>;
24
+ /** Complete authentication with signature. Returns tokens. */
25
+ authenticate: () => Promise<AuthState>;
26
+ /** Refresh access token. Pass the refreshToken from authState. */
27
+ refreshToken: (refreshToken: string) => Promise<TokenRefreshResponse>;
28
+ /** Revoke the current session's refresh token on the server. */
29
+ revokeToken: () => Promise<void>;
30
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import type { UseAuthReturn } from "./types";
2
+ export declare const useAuth: () => UseAuthReturn;
@@ -0,0 +1,145 @@
1
+ import { useCallback } from "react";
2
+ import { AuthenticationStatus, useMonacoContext } from "../../provider";
3
+ import { useMonacoSDK } from "../useMonaco";
4
+ export const useAuth = () => {
5
+ const { sdk, clientId } = useMonacoSDK();
6
+ const { authenticationStatus, setAuthenticationStatus, tokenLifecycle, isWalletConnected } = useMonacoContext();
7
+ const login = useCallback(async () => {
8
+ if (!sdk)
9
+ throw new Error("SDK not available");
10
+ if (!isWalletConnected)
11
+ throw new Error("Wallet not connected");
12
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
13
+ try {
14
+ const authState = await sdk.login(clientId);
15
+ // Initialize token lifecycle management (caching + auto-refresh)
16
+ tokenLifecycle.initializeTokens(authState);
17
+ const authenticated = sdk.isAuthenticated();
18
+ setAuthenticationStatus(authenticated ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.UNAUTHENTICATED);
19
+ return authState;
20
+ }
21
+ catch (error) {
22
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
23
+ throw error;
24
+ }
25
+ }, [sdk, isWalletConnected, clientId, setAuthenticationStatus, tokenLifecycle]);
26
+ const logout = useCallback(async () => {
27
+ if (!sdk)
28
+ throw new Error("SDK not available");
29
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
30
+ try {
31
+ await sdk.logout();
32
+ // Clear cached tokens and stop auto-refresh
33
+ tokenLifecycle.clearTokens();
34
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
35
+ }
36
+ catch (error) {
37
+ // Clear tokens even if logout fails
38
+ tokenLifecycle.clearTokens();
39
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
40
+ throw error;
41
+ }
42
+ }, [sdk, setAuthenticationStatus, tokenLifecycle]);
43
+ const refreshAuth = useCallback(async () => {
44
+ if (!sdk)
45
+ throw new Error("SDK not available");
46
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
47
+ try {
48
+ const result = await sdk.refreshAuth();
49
+ // Reinitialize the token lifecycle with new tokens
50
+ tokenLifecycle.initializeTokens(result);
51
+ const authenticated = sdk.isAuthenticated();
52
+ setAuthenticationStatus(authenticated ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.UNAUTHENTICATED);
53
+ return result;
54
+ }
55
+ catch (error) {
56
+ tokenLifecycle.clearTokens();
57
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
58
+ throw error;
59
+ }
60
+ }, [sdk, setAuthenticationStatus, tokenLifecycle]);
61
+ const signChallenge = useCallback(async (message) => {
62
+ if (!sdk)
63
+ throw new Error("SDK not available");
64
+ if (!message?.trim())
65
+ throw new Error("Message is required and cannot be empty");
66
+ return await sdk.auth.signChallenge(message);
67
+ }, [sdk]);
68
+ const createChallenge = useCallback(async (address) => {
69
+ if (!sdk)
70
+ throw new Error("SDK not available");
71
+ if (!address?.trim())
72
+ throw new Error("Address is required and cannot be empty");
73
+ if (!clientId?.trim())
74
+ throw new Error("Client ID is required and cannot be empty");
75
+ return await sdk.auth.createChallenge(address, clientId);
76
+ }, [sdk, clientId]);
77
+ const authenticate = useCallback(async () => {
78
+ if (!sdk)
79
+ throw new Error("SDK not available");
80
+ if (!clientId?.trim())
81
+ throw new Error("Client ID is required and cannot be empty");
82
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
83
+ try {
84
+ const result = await sdk.auth.authenticate(clientId);
85
+ const authenticated = sdk.isAuthenticated();
86
+ setAuthenticationStatus(authenticated ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.UNAUTHENTICATED);
87
+ return {
88
+ accessToken: result.accessToken,
89
+ refreshToken: result.refreshToken,
90
+ expiresAt: result.expiresAt,
91
+ user: result.user,
92
+ };
93
+ }
94
+ catch (error) {
95
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
96
+ throw error;
97
+ }
98
+ }, [sdk, clientId, setAuthenticationStatus]);
99
+ const refreshToken = useCallback(async (token) => {
100
+ if (!sdk)
101
+ throw new Error("SDK not available");
102
+ if (!token?.trim())
103
+ throw new Error("Refresh token is required and cannot be empty");
104
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
105
+ try {
106
+ const result = await sdk.auth.refreshToken(token);
107
+ const authenticated = sdk.isAuthenticated();
108
+ setAuthenticationStatus(authenticated ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.UNAUTHENTICATED);
109
+ return result;
110
+ }
111
+ catch (error) {
112
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
113
+ throw error;
114
+ }
115
+ }, [sdk, setAuthenticationStatus]);
116
+ const revokeToken = useCallback(async () => {
117
+ if (!sdk)
118
+ throw new Error("SDK not available");
119
+ setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
120
+ try {
121
+ await sdk.auth.revokeToken();
122
+ const authenticated = sdk.isAuthenticated();
123
+ setAuthenticationStatus(authenticated ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.UNAUTHENTICATED);
124
+ }
125
+ catch (error) {
126
+ setAuthenticationStatus(AuthenticationStatus.UNAUTHENTICATED);
127
+ throw error;
128
+ }
129
+ }, [sdk, setAuthenticationStatus]);
130
+ return {
131
+ // State
132
+ authenticationStatus,
133
+ // Primary auth actions
134
+ login,
135
+ logout,
136
+ // Token management
137
+ refreshAuth,
138
+ refreshToken,
139
+ revokeToken,
140
+ // Low-level auth functions
141
+ authenticate,
142
+ signChallenge,
143
+ createChallenge,
144
+ };
145
+ };
@@ -0,0 +1,2 @@
1
+ export type { UseFeesReturn } from "./types";
2
+ export { useFees } from "./useFees";
@@ -0,0 +1 @@
1
+ export { useFees } from "./useFees";
@@ -0,0 +1,5 @@
1
+ import type { SimulateFeeParams, SimulateFeeResponse } from "@0xmonaco/types";
2
+ export interface UseFeesReturn {
3
+ /** Simulate fees for an order before placing it */
4
+ simulateFees: (params: SimulateFeeParams) => Promise<SimulateFeeResponse>;
5
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import type { UseFeesReturn } from "./types";
2
+ export declare const useFees: () => UseFeesReturn;
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import { useMonacoSDK } from "../useMonaco";
3
+ export const useFees = () => {
4
+ const { sdk } = useMonacoSDK();
5
+ const simulateFees = useCallback(async (params) => {
6
+ if (!sdk)
7
+ throw new Error("SDK not available");
8
+ // Parameter validation is handled by the SDK core using Zod
9
+ return await sdk.fees.simulateFees(params);
10
+ }, [sdk]);
11
+ return {
12
+ simulateFees,
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ export type { UseMarketReturn } from "./types";
2
+ export { useMarket } from "./useMarket";
@@ -0,0 +1 @@
1
+ export { useMarket } from "./useMarket";
@@ -0,0 +1,30 @@
1
+ import type { Candlestick, FundingState, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
2
+ export interface UseMarketReturn {
3
+ /** Get all available trading pairs with optional filtering and pagination */
4
+ getPaginatedTradingPairs: (params?: GetTradingPairsParams) => Promise<GetTradingPairsResponse>;
5
+ /** Get a specific trading pair by symbol */
6
+ getTradingPairBySymbol: (symbol: string) => Promise<TradingPair | undefined>;
7
+ /**
8
+ * Get candlestick data for a trading pair.
9
+ *
10
+ * Supports TradingView-compliant query patterns:
11
+ * - `endTime` + `limit`: Backward pagination (bars ending at timestamp)
12
+ * - `startTime` + `limit`: Forward pagination (bars starting from timestamp)
13
+ * - `limit` only: Most recent bars
14
+ * - `startTime` + `endTime` + `limit`: Specific range (capped at limit)
15
+ *
16
+ * @param tradingPairId - Trading pair UUID
17
+ * @param interval - Candlestick interval (1m, 5m, 15m, 1h, 4h, 1d)
18
+ * @param params - Optional query parameters (startTime, endTime, limit)
19
+ */
20
+ getCandlesticks: (tradingPairId: string, interval: Interval, params?: GetCandlesticksParams) => Promise<Candlestick[]>;
21
+ /** Get comprehensive market metadata including 24h statistics */
22
+ getMarketMetadata: (pairId: string) => Promise<MarketMetadata>;
23
+ getPerpMarketConfig: (tradingPairId: string) => Promise<PerpMarketConfig>;
24
+ getPerpMarketSummary: (tradingPairId: string) => Promise<PerpMarketSummary>;
25
+ getMarkPrice: (tradingPairId: string) => Promise<MarkPrice>;
26
+ getIndexPrice: (tradingPairId: string) => Promise<IndexPrice>;
27
+ getFundingState: (tradingPairId: string) => Promise<FundingState>;
28
+ listFundingHistory: (tradingPairId: string, params?: ListFundingHistoryParams) => Promise<ListFundingHistoryResponse>;
29
+ getOpenInterest: (tradingPairId: string) => Promise<OpenInterest>;
30
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import type { UseMarketReturn } from "./types";
2
+ export declare const useMarket: () => UseMarketReturn;
@@ -0,0 +1,92 @@
1
+ import { useCallback } from "react";
2
+ import { useMonacoSDK } from "../useMonaco";
3
+ function requireTradingPairId(tradingPairId) {
4
+ if (!tradingPairId?.trim())
5
+ throw new Error("Trading pair ID is required and cannot be empty");
6
+ }
7
+ export const useMarket = () => {
8
+ const { sdk } = useMonacoSDK();
9
+ const getPaginatedTradingPairs = useCallback(async (params) => {
10
+ if (!sdk)
11
+ throw new Error("SDK not available");
12
+ return await sdk.market.getPaginatedTradingPairs(params);
13
+ }, [sdk]);
14
+ const getTradingPairBySymbol = useCallback(async (symbol) => {
15
+ if (!sdk)
16
+ throw new Error("SDK not available");
17
+ if (!symbol?.trim())
18
+ throw new Error("Symbol is required and cannot be empty");
19
+ return await sdk.market.getTradingPairBySymbol(symbol);
20
+ }, [sdk]);
21
+ const getCandlesticks = useCallback(async (tradingPairId, interval, params) => {
22
+ if (!sdk)
23
+ throw new Error("SDK not available");
24
+ if (!tradingPairId?.trim())
25
+ throw new Error("Trading pair ID is required and cannot be empty");
26
+ if (!interval)
27
+ throw new Error("Interval is required");
28
+ return await sdk.market.getCandlesticks(tradingPairId, interval, params);
29
+ }, [sdk]);
30
+ const getMarketMetadata = useCallback(async (pairId) => {
31
+ if (!sdk)
32
+ throw new Error("SDK not available");
33
+ if (!pairId?.trim())
34
+ throw new Error("Pair ID is required and cannot be empty");
35
+ return await sdk.market.getMarketMetadata(pairId);
36
+ }, [sdk]);
37
+ const getPerpMarketConfig = useCallback(async (tradingPairId) => {
38
+ if (!sdk)
39
+ throw new Error("SDK not available");
40
+ requireTradingPairId(tradingPairId);
41
+ return await sdk.market.getPerpMarketConfig(tradingPairId);
42
+ }, [sdk]);
43
+ const getPerpMarketSummary = useCallback(async (tradingPairId) => {
44
+ if (!sdk)
45
+ throw new Error("SDK not available");
46
+ requireTradingPairId(tradingPairId);
47
+ return await sdk.market.getPerpMarketSummary(tradingPairId);
48
+ }, [sdk]);
49
+ const getMarkPrice = useCallback(async (tradingPairId) => {
50
+ if (!sdk)
51
+ throw new Error("SDK not available");
52
+ requireTradingPairId(tradingPairId);
53
+ return await sdk.market.getMarkPrice(tradingPairId);
54
+ }, [sdk]);
55
+ const getIndexPrice = useCallback(async (tradingPairId) => {
56
+ if (!sdk)
57
+ throw new Error("SDK not available");
58
+ requireTradingPairId(tradingPairId);
59
+ return await sdk.market.getIndexPrice(tradingPairId);
60
+ }, [sdk]);
61
+ const getFundingState = useCallback(async (tradingPairId) => {
62
+ if (!sdk)
63
+ throw new Error("SDK not available");
64
+ requireTradingPairId(tradingPairId);
65
+ return await sdk.market.getFundingState(tradingPairId);
66
+ }, [sdk]);
67
+ const listFundingHistory = useCallback(async (tradingPairId, params) => {
68
+ if (!sdk)
69
+ throw new Error("SDK not available");
70
+ requireTradingPairId(tradingPairId);
71
+ return await sdk.market.listFundingHistory(tradingPairId, params);
72
+ }, [sdk]);
73
+ const getOpenInterest = useCallback(async (tradingPairId) => {
74
+ if (!sdk)
75
+ throw new Error("SDK not available");
76
+ requireTradingPairId(tradingPairId);
77
+ return await sdk.market.getOpenInterest(tradingPairId);
78
+ }, [sdk]);
79
+ return {
80
+ getPaginatedTradingPairs,
81
+ getTradingPairBySymbol,
82
+ getCandlesticks,
83
+ getMarketMetadata,
84
+ getPerpMarketConfig,
85
+ getPerpMarketSummary,
86
+ getMarkPrice,
87
+ getIndexPrice,
88
+ getFundingState,
89
+ listFundingHistory,
90
+ getOpenInterest,
91
+ };
92
+ };
@@ -0,0 +1,2 @@
1
+ export type { UseMonacoReturn } from "./types";
2
+ export { useMonacoSDK } from "./useMonaco";
@@ -0,0 +1 @@
1
+ export { useMonacoSDK } from "./useMonaco";
@@ -0,0 +1,13 @@
1
+ import type { MonacoSDK } from "@0xmonaco/types";
2
+ export interface UseMonacoReturn {
3
+ /** Monaco SDK instance */
4
+ sdk: MonacoSDK | null;
5
+ /** Client ID for authentication */
6
+ clientId: string;
7
+ /** Any error that occurred (SDK initialization, authentication, etc.) */
8
+ error: Error | null;
9
+ /** Clear the current error state */
10
+ clearError: () => void;
11
+ /** Set an error state */
12
+ setError: (error: Error | null) => void;
13
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import type { UseMonacoReturn } from "./types";
2
+ export declare const useMonacoSDK: () => UseMonacoReturn;
@@ -0,0 +1,13 @@
1
+ import { useCallback } from "react";
2
+ import { useMonacoContext } from "../../provider";
3
+ export const useMonacoSDK = () => {
4
+ const { sdk, clientId, error, setError } = useMonacoContext();
5
+ const clearError = useCallback(() => setError(null), [setError]);
6
+ return {
7
+ sdk,
8
+ clientId,
9
+ error,
10
+ clearError,
11
+ setError,
12
+ };
13
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export { useOHLCV } from "./useOHLCV";
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export { useOHLCV } from "./useOHLCV";
@@ -0,0 +1,29 @@
1
+ import type { Candlestick, GetCandlesticksParams, Interval, TradingMode } from "@0xmonaco/types";
2
+ /**
3
+ * Parameters for the useOHLCV hook
4
+ */
5
+ export interface UseOHLCVParams {
6
+ /** Trading pair UUID */
7
+ tradingPairId: string;
8
+ /** Trading mode (e.g., "CLOB") */
9
+ tradingMode: TradingMode;
10
+ /** Candlestick interval (1m, 5m, 15m, 1h, 4h, 1d) */
11
+ interval: Interval;
12
+ /** Optional parameters for initial candlestick fetch */
13
+ initialFetchParams?: GetCandlesticksParams;
14
+ }
15
+ /**
16
+ * Return type for the useOHLCV hook
17
+ */
18
+ export interface UseOHLCVReturn {
19
+ /** Array of candlesticks (oldest to newest) */
20
+ candlesticks: Candlestick[];
21
+ /** Whether the initial candlesticks are being fetched */
22
+ loading: boolean;
23
+ /** Whether currently subscribed to WebSocket updates */
24
+ subscribed: boolean;
25
+ /** Any error that occurred during connection or subscription */
26
+ error: Error | null;
27
+ /** Clear the current error */
28
+ clearError: () => void;
29
+ }
File without changes
@@ -0,0 +1,11 @@
1
+ import type { UseOHLCVParams, UseOHLCVReturn } from "./types";
2
+ /**
3
+ * Hook for subscribing to real-time OHLCV candlestick events via WebSocket (public)
4
+ *
5
+ * Fetches initial candlesticks from the REST API, then subscribes to real-time updates.
6
+ * When a new candlestick event arrives, it either updates the most recent candlestick
7
+ * (if timestamps match) or appends a new one.
8
+ *
9
+ * @param params - Configuration including tradingPairId, tradingMode, interval, and optional fetch params
10
+ */
11
+ export declare function useOHLCV(params: UseOHLCVParams): UseOHLCVReturn;
@@ -0,0 +1,76 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { useMonacoSDK } from "../useMonaco";
3
+ /**
4
+ * Hook for subscribing to real-time OHLCV candlestick events via WebSocket (public)
5
+ *
6
+ * Fetches initial candlesticks from the REST API, then subscribes to real-time updates.
7
+ * When a new candlestick event arrives, it either updates the most recent candlestick
8
+ * (if timestamps match) or appends a new one.
9
+ *
10
+ * @param params - Configuration including tradingPairId, tradingMode, interval, and optional fetch params
11
+ */
12
+ export function useOHLCV(params) {
13
+ const { tradingPairId, tradingMode, interval, initialFetchParams } = params;
14
+ const { sdk } = useMonacoSDK();
15
+ const [candlesticks, setCandlesticks] = useState([]);
16
+ const [loading, setLoading] = useState(false);
17
+ const [error, setError] = useState(null);
18
+ const [subscribed, setSubscribed] = useState(false);
19
+ const clearError = useCallback(() => setError(null), []);
20
+ useEffect(() => {
21
+ if (!sdk?.ws || !sdk?.market || !tradingPairId || !tradingMode || !interval) {
22
+ setSubscribed(false);
23
+ setLoading(false);
24
+ return;
25
+ }
26
+ setCandlesticks([]);
27
+ setError(null);
28
+ setLoading(true);
29
+ let unsubscribe;
30
+ let cancelled = false;
31
+ sdk.market
32
+ .getCandlesticks(tradingPairId, interval, initialFetchParams)
33
+ .then((initialCandlesticks) => {
34
+ if (cancelled)
35
+ return;
36
+ setCandlesticks(initialCandlesticks);
37
+ try {
38
+ unsubscribe = sdk.ws.ohlcv(tradingPairId, tradingMode, interval, (event) => {
39
+ setCandlesticks((prev) => {
40
+ if (prev.length === 0) {
41
+ return [event.candlestick];
42
+ }
43
+ const lastCandle = prev[prev.length - 1];
44
+ if (lastCandle && lastCandle.T === event.candlestick.T) {
45
+ const updated = [...prev];
46
+ updated[updated.length - 1] = event.candlestick;
47
+ return updated;
48
+ }
49
+ return [...prev, event.candlestick];
50
+ });
51
+ });
52
+ setSubscribed(true);
53
+ }
54
+ catch (err) {
55
+ setError(err instanceof Error ? err : new Error(String(err)));
56
+ setSubscribed(false);
57
+ }
58
+ })
59
+ .catch((err) => {
60
+ if (!cancelled) {
61
+ setError(err instanceof Error ? err : new Error(String(err)));
62
+ }
63
+ })
64
+ .finally(() => {
65
+ if (!cancelled) {
66
+ setLoading(false);
67
+ }
68
+ });
69
+ return () => {
70
+ cancelled = true;
71
+ unsubscribe?.();
72
+ setSubscribed(false);
73
+ };
74
+ }, [sdk?.ws, sdk?.market, tradingPairId, tradingMode, interval, initialFetchParams]);
75
+ return { candlesticks, loading, subscribed, error, clearError };
76
+ }
@@ -0,0 +1,2 @@
1
+ export type { OrderbookSubscriptionRef, UseOrderbookReturn } from "./types";
2
+ export { useOrderbook } from "./useOrderbook";
@@ -0,0 +1 @@
1
+ export { useOrderbook } from "./useOrderbook";
@@ -0,0 +1,27 @@
1
+ import type { OrderbookEvent, OrderbookQuotationMode, TradingMode } from "@0xmonaco/types";
2
+ /**
3
+ * State structure for current subscription ref
4
+ */
5
+ export interface OrderbookSubscriptionRef {
6
+ /** The pair subscribed to */
7
+ pair: string;
8
+ /** The mode subscribed to */
9
+ mode: TradingMode;
10
+ /** The magnitude for orderbook grouping */
11
+ magnitude?: number;
12
+ /** The quotation mode for orderbook subscription */
13
+ quotationMode?: OrderbookQuotationMode;
14
+ }
15
+ /**
16
+ * Return type for the useOrderbook hook
17
+ */
18
+ export interface UseOrderbookReturn {
19
+ /** Current orderbook snapshot */
20
+ orderbook: OrderbookEvent | null;
21
+ /** Whether currently subscribed to a market */
22
+ subscribed: boolean;
23
+ /** Any error that occurred during connection or subscription */
24
+ error: Error | null;
25
+ /** Clear the current error state */
26
+ clearError: () => void;
27
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ import type { OrderbookQuotationMode, TradingMode } from "@0xmonaco/types";
2
+ import type { UseOrderbookReturn } from "./types";
3
+ export declare function useOrderbook(tradingPairId: string, tradingMode: TradingMode, magnitude: number, quotationMode: OrderbookQuotationMode, depth?: number): UseOrderbookReturn;
@@ -0,0 +1,31 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { useMonacoSDK } from "../useMonaco";
3
+ export function useOrderbook(tradingPairId, tradingMode, magnitude, quotationMode, depth = 10) {
4
+ const { sdk } = useMonacoSDK();
5
+ const [orderbook, setOrderbook] = useState(null);
6
+ const [error, setError] = useState(null);
7
+ const [subscribed, setSubscribed] = useState(false);
8
+ const clearError = useCallback(() => setError(null), []);
9
+ // Connect and subscribe to orderbook updates
10
+ useEffect(() => {
11
+ if (!sdk?.ws || !sdk?.orderbook || !tradingPairId) {
12
+ setSubscribed(false);
13
+ return;
14
+ }
15
+ setOrderbook(null);
16
+ setError(null);
17
+ // Fetch initial orderbook via REST
18
+ sdk.orderbook
19
+ .getOrderbook(tradingPairId, { depth, tradingMode, magnitude, denomination: quotationMode })
20
+ .then((initial) => setOrderbook(initial))
21
+ .catch((err) => setError(err instanceof Error ? err : new Error(String(err))));
22
+ // Subscribe to WebSocket updates (ws connection handled by MonacoProvider)
23
+ const unsubscribe = sdk.ws.orderbook(tradingPairId, tradingMode, magnitude, quotationMode, setOrderbook);
24
+ setSubscribed(true);
25
+ return () => {
26
+ unsubscribe();
27
+ setSubscribed(false);
28
+ };
29
+ }, [sdk?.ws, sdk?.orderbook, tradingPairId, tradingMode, magnitude, quotationMode, depth]);
30
+ return { orderbook, subscribed, error, clearError };
31
+ }
@@ -0,0 +1,2 @@
1
+ export type { UsePositionsReturn } from "./types";
2
+ export { usePositions } from "./usePositions";
@@ -0,0 +1 @@
1
+ export { usePositions } from "./usePositions";