@0xmonaco/react 0.1.18 → 0.1.19
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/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useOrderbook/index.d.ts +2 -0
- package/dist/hooks/useOrderbook/index.d.ts.map +1 -0
- package/dist/hooks/useOrderbook/index.js +2 -0
- package/dist/hooks/useOrderbook/index.js.map +1 -0
- package/dist/hooks/useOrderbook/types.d.ts +26 -0
- package/dist/hooks/useOrderbook/types.d.ts.map +1 -0
- package/dist/hooks/useOrderbook/types.js +2 -0
- package/dist/hooks/useOrderbook/types.js.map +1 -0
- package/dist/hooks/useOrderbook/useOrderbook.d.ts +34 -0
- package/dist/hooks/useOrderbook/useOrderbook.d.ts.map +1 -0
- package/dist/hooks/useOrderbook/useOrderbook.js +131 -0
- package/dist/hooks/useOrderbook/useOrderbook.js.map +1 -0
- package/dist/hooks/useTradeFeed/index.d.ts +3 -0
- package/dist/hooks/useTradeFeed/index.d.ts.map +1 -0
- package/dist/hooks/useTradeFeed/index.js +3 -0
- package/dist/hooks/useTradeFeed/index.js.map +1 -0
- package/dist/hooks/useTradeFeed/types.d.ts +49 -0
- package/dist/hooks/useTradeFeed/types.d.ts.map +1 -0
- package/dist/hooks/useTradeFeed/types.js +2 -0
- package/dist/hooks/useTradeFeed/types.js.map +1 -0
- package/dist/hooks/useTradeFeed/useTradeFeed.d.ts +32 -0
- package/dist/hooks/useTradeFeed/useTradeFeed.d.ts.map +1 -0
- package/dist/hooks/useTradeFeed/useTradeFeed.js +143 -0
- package/dist/hooks/useTradeFeed/useTradeFeed.js.map +1 -0
- package/dist/hooks/useTradeFeed/utils.d.ts +4 -0
- package/dist/hooks/useTradeFeed/utils.d.ts.map +1 -0
- package/dist/hooks/useTradeFeed/utils.js +16 -0
- package/dist/hooks/useTradeFeed/utils.js.map +1 -0
- package/package.json +2 -2
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./useAuth";
|
|
2
2
|
export * from "./useMarket";
|
|
3
3
|
export * from "./useMonaco";
|
|
4
|
+
export * from "./useOrderbook";
|
|
4
5
|
export * from "./useProfile";
|
|
5
6
|
export * from "./useTrade";
|
|
7
|
+
export * from "./useTradeFeed";
|
|
6
8
|
export * from "./useVault";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./useAuth";
|
|
2
2
|
export * from "./useMarket";
|
|
3
3
|
export * from "./useMonaco";
|
|
4
|
+
export * from "./useOrderbook";
|
|
4
5
|
export * from "./useProfile";
|
|
5
6
|
export * from "./useTrade";
|
|
7
|
+
export * from "./useTradeFeed";
|
|
6
8
|
export * from "./useVault";
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ConnectionStatus, OrderbookEvent, TradingMode } from "@0xmonaco/types";
|
|
2
|
+
/**
|
|
3
|
+
* State structure for current subscription ref
|
|
4
|
+
*/
|
|
5
|
+
export interface CurrentSubscriptionRef {
|
|
6
|
+
/** The pair subscribed to */
|
|
7
|
+
pair: string;
|
|
8
|
+
/** The mode subscribed to */
|
|
9
|
+
mode: TradingMode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Return type for the useOrderbook hook
|
|
13
|
+
*/
|
|
14
|
+
export interface UseOrderbookReturn {
|
|
15
|
+
/** Current orderbook snapshot */
|
|
16
|
+
orderbook: OrderbookEvent | null;
|
|
17
|
+
/** WebSocket connection status */
|
|
18
|
+
connectionStatus: ConnectionStatus;
|
|
19
|
+
/** Whether currently subscribed to a market */
|
|
20
|
+
subscribed: boolean;
|
|
21
|
+
/** Any error that occurred during connection or subscription */
|
|
22
|
+
error: Error | null;
|
|
23
|
+
/** Clear the current error state */
|
|
24
|
+
clearError: () => void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IAEjC,kCAAkC;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IAEpB,gEAAgE;IAChE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,oCAAoC;IACpC,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TradingMode } from "@0xmonaco/types";
|
|
2
|
+
import type { UseOrderbookReturn } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* React hook to subscribe to and manage the orderbook for a given trading pair and mode.
|
|
5
|
+
*
|
|
6
|
+
* Connects to the Monaco SDK WebSocket orderbook feed, subscribes to updates,
|
|
7
|
+
* and provides the latest orderbook event, connection status, subscription state, and error handling.
|
|
8
|
+
*
|
|
9
|
+
* @param {string | null} tradingPair - The trading pair to subscribe to (e.g., "BTC/USD"). If null, no subscription is made.
|
|
10
|
+
* @param {TradingMode} tradingMode - The trading mode to use for the subscription (e.g., "live", "test").
|
|
11
|
+
* @returns {UseOrderbookReturn} An object containing the latest orderbook event, connection status, subscription state, error, and error clearing function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useOrderbook } from "./useOrderbook";
|
|
16
|
+
*
|
|
17
|
+
* function OrderbookComponent() {
|
|
18
|
+
* const { orderbook, connectionStatus, subscribed, error, clearError } = useOrderbook("BTC/USD", "live");
|
|
19
|
+
*
|
|
20
|
+
* if (error) return <div>Error: {error.message} <button onClick={clearError}>Clear</button></div>;
|
|
21
|
+
* if (!subscribed) return <div>Not subscribed</div>;
|
|
22
|
+
* if (!orderbook) return <div>Loading...</div>;
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* <h2>Orderbook ({connectionStatus})</h2>
|
|
27
|
+
* {/** Render orderbook data here }
|
|
28
|
+
* </div>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function useOrderbook(tradingPair: string | null, tradingMode: TradingMode): UseOrderbookReturn;
|
|
34
|
+
//# sourceMappingURL=useOrderbook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOrderbook.d.ts","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/useOrderbook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInE,OAAO,KAAK,EAA0B,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,kBAAkB,CA+GrG"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useMonacoSDK } from "../useMonaco";
|
|
3
|
+
/**
|
|
4
|
+
* React hook to subscribe to and manage the orderbook for a given trading pair and mode.
|
|
5
|
+
*
|
|
6
|
+
* Connects to the Monaco SDK WebSocket orderbook feed, subscribes to updates,
|
|
7
|
+
* and provides the latest orderbook event, connection status, subscription state, and error handling.
|
|
8
|
+
*
|
|
9
|
+
* @param {string | null} tradingPair - The trading pair to subscribe to (e.g., "BTC/USD"). If null, no subscription is made.
|
|
10
|
+
* @param {TradingMode} tradingMode - The trading mode to use for the subscription (e.g., "live", "test").
|
|
11
|
+
* @returns {UseOrderbookReturn} An object containing the latest orderbook event, connection status, subscription state, error, and error clearing function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useOrderbook } from "./useOrderbook";
|
|
16
|
+
*
|
|
17
|
+
* function OrderbookComponent() {
|
|
18
|
+
* const { orderbook, connectionStatus, subscribed, error, clearError } = useOrderbook("BTC/USD", "live");
|
|
19
|
+
*
|
|
20
|
+
* if (error) return <div>Error: {error.message} <button onClick={clearError}>Clear</button></div>;
|
|
21
|
+
* if (!subscribed) return <div>Not subscribed</div>;
|
|
22
|
+
* if (!orderbook) return <div>Loading...</div>;
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* <h2>Orderbook ({connectionStatus})</h2>
|
|
27
|
+
* {/** Render orderbook data here }
|
|
28
|
+
* </div>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function useOrderbook(tradingPair, tradingMode) {
|
|
34
|
+
const { sdk } = useMonacoSDK();
|
|
35
|
+
const [orderbook, setOrderbook] = useState(null);
|
|
36
|
+
const [error, setError] = useState(null);
|
|
37
|
+
const currentSubscriptionRef = useRef(null);
|
|
38
|
+
const orderbookWSClient = useMemo(() => sdk?.websocket.orderbook, [sdk?.websocket.orderbook]);
|
|
39
|
+
const subscribed = !!currentSubscriptionRef.current?.pair;
|
|
40
|
+
const clearError = useCallback(() => {
|
|
41
|
+
setError(null);
|
|
42
|
+
}, []);
|
|
43
|
+
const connect = useCallback(async () => {
|
|
44
|
+
if (!orderbookWSClient)
|
|
45
|
+
return;
|
|
46
|
+
// Prevent duplicate connections
|
|
47
|
+
const currentStatus = orderbookWSClient.getConnectionStatus();
|
|
48
|
+
if (currentStatus === "connecting" || currentStatus === "connected")
|
|
49
|
+
return;
|
|
50
|
+
setError(null);
|
|
51
|
+
try {
|
|
52
|
+
await orderbookWSClient.connect();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
56
|
+
}
|
|
57
|
+
}, [orderbookWSClient]);
|
|
58
|
+
const subscribe = useCallback(async (pair, mode) => {
|
|
59
|
+
if (!orderbookWSClient)
|
|
60
|
+
return;
|
|
61
|
+
// Check if connected before subscribing
|
|
62
|
+
if (orderbookWSClient.getConnectionStatus() !== "connected") {
|
|
63
|
+
console.warn("Cannot subscribe: WebSocket not connected");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
setOrderbook(null);
|
|
67
|
+
setError(null);
|
|
68
|
+
try {
|
|
69
|
+
const normalizedMode = mode.toLowerCase();
|
|
70
|
+
orderbookWSClient.subscribeToOrderbookEvents(pair, normalizedMode, (event) => {
|
|
71
|
+
setOrderbook(event);
|
|
72
|
+
});
|
|
73
|
+
currentSubscriptionRef.current = { pair, mode: normalizedMode };
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
77
|
+
}
|
|
78
|
+
}, [orderbookWSClient]);
|
|
79
|
+
const unsubscribe = useCallback(() => {
|
|
80
|
+
if (!orderbookWSClient)
|
|
81
|
+
return;
|
|
82
|
+
if (!currentSubscriptionRef.current)
|
|
83
|
+
return;
|
|
84
|
+
// Check if connected before unsubscribing
|
|
85
|
+
if (orderbookWSClient.getConnectionStatus() !== "connected") {
|
|
86
|
+
console.warn("Cannot unsubscribe: WebSocket not connected");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const tradingMode = currentSubscriptionRef.current.mode;
|
|
91
|
+
orderbookWSClient.unsubscribeFromOrderbookEvents(currentSubscriptionRef.current.pair, tradingMode);
|
|
92
|
+
currentSubscriptionRef.current = null;
|
|
93
|
+
setOrderbook(null);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
97
|
+
}
|
|
98
|
+
}, [orderbookWSClient]);
|
|
99
|
+
const disconnect = useCallback(() => {
|
|
100
|
+
if (orderbookWSClient?.getConnectionStatus() !== "connected")
|
|
101
|
+
return;
|
|
102
|
+
try {
|
|
103
|
+
orderbookWSClient.disconnect();
|
|
104
|
+
setOrderbook(null);
|
|
105
|
+
setError(null);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
109
|
+
}
|
|
110
|
+
}, [orderbookWSClient]);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (tradingPair && tradingMode) {
|
|
113
|
+
if (tradingPair === currentSubscriptionRef.current?.pair && tradingMode === currentSubscriptionRef.current?.mode)
|
|
114
|
+
return;
|
|
115
|
+
unsubscribe();
|
|
116
|
+
void subscribe(tradingPair, tradingMode);
|
|
117
|
+
}
|
|
118
|
+
}, [tradingPair, tradingMode, unsubscribe, subscribe]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
void connect(); // Connect on mount
|
|
121
|
+
return () => disconnect(); // Disconnect on unmount
|
|
122
|
+
}, [connect, disconnect]);
|
|
123
|
+
return {
|
|
124
|
+
orderbook,
|
|
125
|
+
connectionStatus: orderbookWSClient?.getConnectionStatus() || "disconnected",
|
|
126
|
+
subscribed,
|
|
127
|
+
error,
|
|
128
|
+
clearError,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=useOrderbook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOrderbook.js","sourceRoot":"","sources":["../../../src/hooks/useOrderbook/useOrderbook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,YAAY,CAAC,WAA0B,EAAE,WAAwB;IAC/E,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC;IAE/B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IACxE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,sBAAsB,GAAG,MAAM,CAAgC,IAAI,CAAC,CAAC;IAE3E,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9F,MAAM,UAAU,GAAG,CAAC,CAAC,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC;IAE1D,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;QAClC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;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ot":"","sources":["../../../src/hooks/useTradeFeed/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ConnectionStatus, OrderSide, TradingMode } from "@0xmonaco/types";
|
|
2
|
+
/**
|
|
3
|
+
* State structure for current subscription ref
|
|
4
|
+
*/
|
|
5
|
+
export interface CurrentSubscriptionRef {
|
|
6
|
+
/** The pair subscribed to */
|
|
7
|
+
pair: string;
|
|
8
|
+
/** The mode subscribed to */
|
|
9
|
+
mode: TradingMode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Standardized trade data extracted from order events
|
|
13
|
+
*/
|
|
14
|
+
export interface Trade {
|
|
15
|
+
/** Execution price of the trade */
|
|
16
|
+
price: string;
|
|
17
|
+
/** Trading pair symbol (e.g., "BTC/USDC") */
|
|
18
|
+
tradingPair: string;
|
|
19
|
+
/** Trading pair ID (UUID) */
|
|
20
|
+
tradingPairId: string | undefined;
|
|
21
|
+
/** Quantity executed in this trade */
|
|
22
|
+
quantity: string;
|
|
23
|
+
/** User ID (UUID) */
|
|
24
|
+
userId: string;
|
|
25
|
+
/** Trading mode (e.g., "Spot", "Margin") */
|
|
26
|
+
tradingMode: TradingMode;
|
|
27
|
+
/** Original order ID */
|
|
28
|
+
orderId: string;
|
|
29
|
+
/** Event timestamp */
|
|
30
|
+
timestamp: string;
|
|
31
|
+
/** Order side ("BUY" or "SELL") */
|
|
32
|
+
side?: OrderSide;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Return type for the useTradeFeed hook
|
|
36
|
+
*/
|
|
37
|
+
export interface UseTradeFeedReturn {
|
|
38
|
+
/** Array of standardized trades received from the WebSocket feed */
|
|
39
|
+
trades: Trade[];
|
|
40
|
+
/** WebSocket connection status */
|
|
41
|
+
connectionStatus: ConnectionStatus;
|
|
42
|
+
/** Whether currently subscribed to a market */
|
|
43
|
+
subscribed: boolean;
|
|
44
|
+
/** Any error that occurred during connection or subscription */
|
|
45
|
+
error: Error | null;
|
|
46
|
+
/** Clear the current error state */
|
|
47
|
+
clearError: () => void;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,WAAW,CAAC;CACnB;AACD;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,WAAW,EAAE,WAAW,CAAC;IACzB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,kCAAkC;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,oCAAoC;IACpC,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TradingMode } from "@0xmonaco/types";
|
|
2
|
+
import type { UseTradeFeedReturn } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for subscribing to real-time trades events via WebSocket
|
|
5
|
+
*
|
|
6
|
+
* @param tradingPair - Trading pair symbol (e.g., "BTC/USDC") or null to disconnect
|
|
7
|
+
* @param tradingMode - Trading mode (e.g., "spot" or "margin")
|
|
8
|
+
* @param maxEvents - Maximum number of trades to keep in memory (default: 50)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { trades, connectionStatus, subscribed, error, clearError } = useTradeFeed("BTC/USDC", "spot");
|
|
13
|
+
*
|
|
14
|
+
* if (error) {
|
|
15
|
+
* return <ErrorMessage error={error} onDismiss={clearError} />;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* if (connectionStatus === ConnectionStatus.Connecting) {
|
|
19
|
+
* return <Spinner message="Connecting to WebSocket..." />;
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* if (connectionStatus === ConnectionStatus.Connected && !subscribed) {
|
|
23
|
+
* return <Spinner message="Subscribing to market..." />;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* if (subscribed) {
|
|
27
|
+
* return <TradeFeed trades={trades} />;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useTradeFeed(tradingPair: string | null, tradingMode: TradingMode, maxEvents?: number): UseTradeFeedReturn;
|
|
32
|
+
//# sourceMappingURL=useTradeFeed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTradeFeed.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/useTradeFeed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2D,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG5G,OAAO,KAAK,EAAiC,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGjF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,GAAE,MAAW,GAAG,kBAAkB,CA+H7H"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useMonacoSDK } from "../useMonaco";
|
|
3
|
+
import { convertOrderEventToTrade } from "./utils";
|
|
4
|
+
/**
|
|
5
|
+
* Hook for subscribing to real-time trades events via WebSocket
|
|
6
|
+
*
|
|
7
|
+
* @param tradingPair - Trading pair symbol (e.g., "BTC/USDC") or null to disconnect
|
|
8
|
+
* @param tradingMode - Trading mode (e.g., "spot" or "margin")
|
|
9
|
+
* @param maxEvents - Maximum number of trades to keep in memory (default: 50)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const { trades, connectionStatus, subscribed, error, clearError } = useTradeFeed("BTC/USDC", "spot");
|
|
14
|
+
*
|
|
15
|
+
* if (error) {
|
|
16
|
+
* return <ErrorMessage error={error} onDismiss={clearError} />;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* if (connectionStatus === ConnectionStatus.Connecting) {
|
|
20
|
+
* return <Spinner message="Connecting to WebSocket..." />;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* if (connectionStatus === ConnectionStatus.Connected && !subscribed) {
|
|
24
|
+
* return <Spinner message="Subscribing to market..." />;
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* if (subscribed) {
|
|
28
|
+
* return <TradeFeed trades={trades} />;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function useTradeFeed(tradingPair, tradingMode, maxEvents = 50) {
|
|
33
|
+
const validatedMaxEvents = maxEvents < 1 ? 50 : maxEvents;
|
|
34
|
+
if (maxEvents < 1) {
|
|
35
|
+
console.warn("useTradeFeed: maxEvents must be >= 1, defaulting to 50");
|
|
36
|
+
}
|
|
37
|
+
const { sdk } = useMonacoSDK();
|
|
38
|
+
const [trades, setTrades] = useState([]);
|
|
39
|
+
const [error, setError] = useState(null);
|
|
40
|
+
const currentSubscriptionRef = useRef(null);
|
|
41
|
+
const ordersWSClient = useMemo(() => sdk?.websocket.orders, [sdk?.websocket.orders]);
|
|
42
|
+
const subscribed = !!currentSubscriptionRef.current?.pair;
|
|
43
|
+
const clearError = useCallback(() => {
|
|
44
|
+
setError(null);
|
|
45
|
+
}, []);
|
|
46
|
+
const connect = useCallback(async () => {
|
|
47
|
+
if (!ordersWSClient)
|
|
48
|
+
return;
|
|
49
|
+
// Prevent duplicate connections
|
|
50
|
+
const currentStatus = ordersWSClient.getConnectionStatus();
|
|
51
|
+
if (currentStatus === "connecting" || currentStatus === "connected")
|
|
52
|
+
return;
|
|
53
|
+
setError(null);
|
|
54
|
+
try {
|
|
55
|
+
await ordersWSClient.connect();
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
59
|
+
}
|
|
60
|
+
}, [ordersWSClient]);
|
|
61
|
+
const subscribe = useCallback(async (pair, mode) => {
|
|
62
|
+
if (!ordersWSClient)
|
|
63
|
+
return;
|
|
64
|
+
// Check if connected before subscribing
|
|
65
|
+
if (ordersWSClient.getConnectionStatus() !== "connected") {
|
|
66
|
+
console.warn("Cannot subscribe: WebSocket not connected");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setTrades([]);
|
|
70
|
+
setError(null);
|
|
71
|
+
try {
|
|
72
|
+
ordersWSClient.subscribeToOrderEvents(pair, mode, (event) => {
|
|
73
|
+
if (event.eventType === "OrderFilled" || event.eventType === "OrderPartiallyFilled") {
|
|
74
|
+
const eventData = event.data;
|
|
75
|
+
// Only include taker trades to avoid duplicates
|
|
76
|
+
if (eventData.role !== "taker") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const trade = convertOrderEventToTrade(event);
|
|
80
|
+
setTrades((prevTrades) => {
|
|
81
|
+
return [trade, ...prevTrades].slice(0, validatedMaxEvents);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
currentSubscriptionRef.current = { pair, mode };
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
89
|
+
}
|
|
90
|
+
}, [ordersWSClient, validatedMaxEvents]);
|
|
91
|
+
const unsubscribe = useCallback(() => {
|
|
92
|
+
if (!ordersWSClient)
|
|
93
|
+
return;
|
|
94
|
+
if (!currentSubscriptionRef.current)
|
|
95
|
+
return;
|
|
96
|
+
// Check if connected before unsubscribing
|
|
97
|
+
if (ordersWSClient.getConnectionStatus() !== "connected") {
|
|
98
|
+
console.warn("Cannot unsubscribe: WebSocket not connected");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const tradingMode = currentSubscriptionRef.current.mode;
|
|
103
|
+
ordersWSClient.unsubscribeFromOrderEvents(currentSubscriptionRef.current.pair, tradingMode);
|
|
104
|
+
currentSubscriptionRef.current = null;
|
|
105
|
+
setTrades([]);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
109
|
+
}
|
|
110
|
+
}, [ordersWSClient]);
|
|
111
|
+
const disconnect = useCallback(() => {
|
|
112
|
+
if (ordersWSClient?.getConnectionStatus() !== "connected")
|
|
113
|
+
return;
|
|
114
|
+
try {
|
|
115
|
+
ordersWSClient.disconnect();
|
|
116
|
+
setTrades([]);
|
|
117
|
+
setError(null);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
121
|
+
}
|
|
122
|
+
}, [ordersWSClient]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (tradingPair && tradingMode) {
|
|
125
|
+
if (tradingPair === currentSubscriptionRef.current?.pair && tradingMode === currentSubscriptionRef.current?.mode)
|
|
126
|
+
return;
|
|
127
|
+
unsubscribe();
|
|
128
|
+
void subscribe(tradingPair, tradingMode);
|
|
129
|
+
}
|
|
130
|
+
}, [tradingPair, tradingMode, unsubscribe, subscribe]);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
void connect(); // Connect on mount
|
|
133
|
+
return () => disconnect(); // Disconnect on unmount
|
|
134
|
+
}, [connect, disconnect]);
|
|
135
|
+
return {
|
|
136
|
+
trades,
|
|
137
|
+
connectionStatus: ordersWSClient?.getConnectionStatus() || "disconnected",
|
|
138
|
+
subscribed,
|
|
139
|
+
error,
|
|
140
|
+
clearError,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=useTradeFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTradeFeed.js","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/useTradeFeed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,YAAY,CAAC,WAA0B,EAAE,WAAwB,EAAE,YAAoB,EAAE;IACvG,MAAM,kBAAkB,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CA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AAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,WAAW,IAAI,WAAW,EAAE,CAAC;YAC/B,IAAI,WAAW,KAAK,sBAAsB,CAAC,OAAO,EAAE,IAAI,IAAI,WAAW,KAAK,sBAAsB,CAAC,OAAO,EAAE,IAAI;gBAAE,OAAO;YACzH,WAAW,EAAE,CAAC;YACd,KAAK,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,OAAO,EAAE,CAAC,CAAC,mBAAmB;QACnC,OAAO,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,wBAAwB;IACrD,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IAE1B,OAAO;QACL,MAAM;QACN,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,EAAE,IAAI,cAAc;QACzE,UAAU;QACV,KAAK;QACL,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA4D,MAAM,iBAAiB,CAAC;AAC5G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAejE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function convertOrderEventToTrade(event) {
|
|
2
|
+
const { orderId, timestamp, data } = event;
|
|
3
|
+
const eventData = data;
|
|
4
|
+
return {
|
|
5
|
+
price: eventData.price ?? eventData.averageFillPrice ?? "0",
|
|
6
|
+
tradingPair: eventData.tradingPair,
|
|
7
|
+
tradingPairId: eventData.tradingPairId,
|
|
8
|
+
quantity: eventData.quantity ?? eventData.totalFilled,
|
|
9
|
+
userId: eventData.userId,
|
|
10
|
+
tradingMode: eventData.tradingMode.toUpperCase(),
|
|
11
|
+
orderId,
|
|
12
|
+
timestamp,
|
|
13
|
+
side: eventData.side,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/hooks/useTradeFeed/utils.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,wBAAwB,CAAC,KAAiB;IACxD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAoE,CAAC;IAEvF,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,gBAAgB,IAAI,GAAG;QAC3D,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,aAAa,EAAE,SAAS,CAAC,aAAa;QACtC,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,WAAW;QACrD,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,WAAW,EAAE,SAAS,CAAC,WAAW,CAAC,WAAW,EAAiB;QAC/D,OAAO;QACP,SAAS;QACT,IAAI,EAAE,SAAS,CAAC,IAAI;KACrB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@0xmonaco/core": "0.2.
|
|
12
|
+
"@0xmonaco/core": "0.2.11"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/react": "^19.1.12",
|