@0xmonaco/react 1.1.15 → 1.1.17
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/README.md +10 -18
- package/dist/coverage.d.ts +4 -0
- package/dist/coverage.js +4 -0
- package/dist/hooks/useOrderbook/ordering.d.ts +33 -0
- package/dist/hooks/useOrderbook/ordering.js +35 -0
- package/dist/hooks/useOrderbook/useOrderbook.d.ts +12 -0
- package/dist/hooks/useOrderbook/useOrderbook.js +33 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -306,28 +306,20 @@ useEffect(() => {
|
|
|
306
306
|
```
|
|
307
307
|
|
|
308
308
|
#### `useOrderbook()`
|
|
309
|
-
|
|
309
|
+
One market's grouped orderbook: a REST snapshot for the first render, then the live `orderbook` channel.
|
|
310
310
|
|
|
311
311
|
```tsx
|
|
312
|
-
const {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
bids: event.bids.length,
|
|
320
|
-
asks: event.asks.length,
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
return () => {
|
|
325
|
-
unsubscribe("BTC/USDC", "SPOT");
|
|
326
|
-
disconnect();
|
|
327
|
-
};
|
|
328
|
-
}, []);
|
|
312
|
+
const { orderbook, subscribed, error, clearError } = useOrderbook(
|
|
313
|
+
tradingPairId, // trading pair UUID
|
|
314
|
+
"SPOT", // trading mode
|
|
315
|
+
1, // price grouping magnitude
|
|
316
|
+
"BASE", // quantity denomination
|
|
317
|
+
10, // levels per side for the REST snapshot (optional)
|
|
318
|
+
);
|
|
329
319
|
```
|
|
330
320
|
|
|
321
|
+
The snapshot and the live updates are ordered by `bookSeq`, so the book never goes back in time: a snapshot or update with a lower `bookSeq` than the book held is ignored. At an equal `bookSeq` a live update replaces the REST snapshot. A book without `bookSeq` cannot be ordered: live updates are then applied as they arrive, and the REST snapshot only when no book is held yet.
|
|
322
|
+
|
|
331
323
|
## TypeScript Configuration
|
|
332
324
|
|
|
333
325
|
For optimal type inference, use these TypeScript settings:
|
package/dist/coverage.d.ts
CHANGED
|
@@ -96,6 +96,8 @@ export declare const INTENTIONALLY_EXCLUDED: {
|
|
|
96
96
|
refresh_managed_market_quotes: string;
|
|
97
97
|
claim_buildercode_rewards: string;
|
|
98
98
|
set_builder_fee: string;
|
|
99
|
+
set_builder_rules: string;
|
|
100
|
+
preview_builder_rules: string;
|
|
99
101
|
cancel_twap_order: string;
|
|
100
102
|
create_delegated_session: string;
|
|
101
103
|
create_twap_order: string;
|
|
@@ -161,6 +163,8 @@ export declare const INTENTIONALLY_EXCLUDED: {
|
|
|
161
163
|
list_application_users: string;
|
|
162
164
|
list_buildercode_payouts: string;
|
|
163
165
|
list_builder_fee_changes: string;
|
|
166
|
+
list_builder_rules: string;
|
|
167
|
+
resolve_builder_rate: string;
|
|
164
168
|
list_delegated_agent_owners: string;
|
|
165
169
|
list_delegated_agents: string;
|
|
166
170
|
list_all_funding_history: string;
|
package/dist/coverage.js
CHANGED
|
@@ -96,6 +96,8 @@ export const INTENTIONALLY_EXCLUDED = {
|
|
|
96
96
|
refresh_managed_market_quotes: "Cadenced fenced intents belong to the managed maker driver; core SDK exposes the transport.",
|
|
97
97
|
claim_buildercode_rewards: "BuilderCodes payout claim is a frontend-operator workflow, not an end-user trading action; covered by @0xmonaco/core.",
|
|
98
98
|
set_builder_fee: "BuilderCodes fee administration is a frontend-operator workflow covered by @0xmonaco/core; no React hook.",
|
|
99
|
+
set_builder_rules: "BuilderCodes fee rule administration is a frontend-operator workflow covered by @0xmonaco/core; no React hook.",
|
|
100
|
+
preview_builder_rules: "BuilderCodes fee rule administration is a frontend-operator workflow covered by @0xmonaco/core; no React hook.",
|
|
99
101
|
cancel_twap_order: "TWAP parent orders are an advanced execution-algo surface (covered by @0xmonaco/core); no React hook yet.",
|
|
100
102
|
create_delegated_session: "Delegated-agent management is an automation/agent surface, not a UI workflow; no React hook.",
|
|
101
103
|
create_twap_order: "TWAP parent orders are an advanced execution-algo surface (covered by @0xmonaco/core); no React hook yet.",
|
|
@@ -161,6 +163,8 @@ export const INTENTIONALLY_EXCLUDED = {
|
|
|
161
163
|
list_application_users: "Application reporting endpoint (public, selected by clientId) for frontend operators; not a user-wallet React workflow.",
|
|
162
164
|
list_buildercode_payouts: "BuilderCodes frontend-operator reporting is covered by @0xmonaco/core; no React hook.",
|
|
163
165
|
list_builder_fee_changes: "BuilderCodes frontend-operator audit reporting is covered by @0xmonaco/core; no React hook.",
|
|
166
|
+
list_builder_rules: "BuilderCodes fee rule administration is a frontend-operator workflow covered by @0xmonaco/core; no React hook.",
|
|
167
|
+
resolve_builder_rate: "BuilderCodes fee rule administration is a frontend-operator workflow covered by @0xmonaco/core; no React hook.",
|
|
164
168
|
list_delegated_agent_owners: "Delegated-agent management is an automation/agent surface, not a UI workflow; no React hook.",
|
|
165
169
|
list_delegated_agents: "Delegated-agent management is an automation/agent surface, not a UI workflow; no React hook.",
|
|
166
170
|
list_all_funding_history: "Bulk market data; useMarket covers per-pair funding; no React hook.",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OrderbookEvent } from "@0xmonaco/types";
|
|
2
|
+
/** Where a book came from: the REST snapshot read or a live `orderbook` frame. */
|
|
3
|
+
export type OrderbookSource = "rest" | "stream";
|
|
4
|
+
/** The book the hook holds, with the sequence it is exact as of when the server sent one. */
|
|
5
|
+
export interface HeldOrderbook {
|
|
6
|
+
source: OrderbookSource;
|
|
7
|
+
/** `bookSeq` as an integer, or `undefined` when the book carried none. */
|
|
8
|
+
seq: bigint | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* `bookSeq` as an integer, or `undefined` when it is absent (a server that
|
|
12
|
+
* predates it) or not a decimal integer. Never throws.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readBookSeq(book: OrderbookEvent): bigint | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a book that just arrived replaces the one held.
|
|
17
|
+
*
|
|
18
|
+
* `bookSeq` is the durable-log sequence a book is exact as of. The REST
|
|
19
|
+
* snapshot and every `orderbook` frame take it from the same market-data
|
|
20
|
+
* watermark, for every magnitude and quotation, so a lower `bookSeq` is an
|
|
21
|
+
* older book wherever the two came from.
|
|
22
|
+
*
|
|
23
|
+
* - Nothing held: the book is applied.
|
|
24
|
+
* - Both carry `bookSeq`: a lower one is ignored and a higher one applied.
|
|
25
|
+
* At an equal `bookSeq` a frame replaces a REST snapshot (the stream's
|
|
26
|
+
* grouping covers the whole book, the snapshot's only the levels read);
|
|
27
|
+
* a REST snapshot never replaces a frame, and a second frame is a
|
|
28
|
+
* duplicate.
|
|
29
|
+
* - Either lacks `bookSeq`: the two cannot be ordered. Frames arrive in
|
|
30
|
+
* order and each restates the book, so a frame is applied; a REST snapshot
|
|
31
|
+
* is not, since it may have been read before the frame held.
|
|
32
|
+
*/
|
|
33
|
+
export declare function replacesHeld(held: HeldOrderbook | null, source: OrderbookSource, seq: bigint | undefined): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bookSeq` as an integer, or `undefined` when it is absent (a server that
|
|
3
|
+
* predates it) or not a decimal integer. Never throws.
|
|
4
|
+
*/
|
|
5
|
+
export function readBookSeq(book) {
|
|
6
|
+
const raw = book.bookSeq;
|
|
7
|
+
return typeof raw === "string" && /^\d+$/.test(raw) ? BigInt(raw) : undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether a book that just arrived replaces the one held.
|
|
11
|
+
*
|
|
12
|
+
* `bookSeq` is the durable-log sequence a book is exact as of. The REST
|
|
13
|
+
* snapshot and every `orderbook` frame take it from the same market-data
|
|
14
|
+
* watermark, for every magnitude and quotation, so a lower `bookSeq` is an
|
|
15
|
+
* older book wherever the two came from.
|
|
16
|
+
*
|
|
17
|
+
* - Nothing held: the book is applied.
|
|
18
|
+
* - Both carry `bookSeq`: a lower one is ignored and a higher one applied.
|
|
19
|
+
* At an equal `bookSeq` a frame replaces a REST snapshot (the stream's
|
|
20
|
+
* grouping covers the whole book, the snapshot's only the levels read);
|
|
21
|
+
* a REST snapshot never replaces a frame, and a second frame is a
|
|
22
|
+
* duplicate.
|
|
23
|
+
* - Either lacks `bookSeq`: the two cannot be ordered. Frames arrive in
|
|
24
|
+
* order and each restates the book, so a frame is applied; a REST snapshot
|
|
25
|
+
* is not, since it may have been read before the frame held.
|
|
26
|
+
*/
|
|
27
|
+
export function replacesHeld(held, source, seq) {
|
|
28
|
+
if (held === null)
|
|
29
|
+
return true;
|
|
30
|
+
if (seq === undefined || held.seq === undefined)
|
|
31
|
+
return source === "stream";
|
|
32
|
+
if (seq !== held.seq)
|
|
33
|
+
return seq > held.seq;
|
|
34
|
+
return source === "stream" && held.source === "rest";
|
|
35
|
+
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import type { OrderbookQuotationMode, TradingMode } from "@0xmonaco/types";
|
|
2
2
|
import type { UseOrderbookReturn } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* One market's grouped orderbook: a REST snapshot for the first paint, then
|
|
5
|
+
* the live `orderbook` channel, each frame of which restates the whole view.
|
|
6
|
+
*
|
|
7
|
+
* The two are ordered by `bookSeq`, the durable-log sequence a book is exact
|
|
8
|
+
* as of, so the book held never goes back in time: a REST snapshot that lands
|
|
9
|
+
* after a newer frame is ignored, as is a frame older than the book held. At
|
|
10
|
+
* an equal `bookSeq` a frame replaces the REST snapshot and nothing else
|
|
11
|
+
* changes. A book without `bookSeq` (a server that predates it) cannot be
|
|
12
|
+
* ordered: frames are then applied as they arrive, and the REST snapshot only
|
|
13
|
+
* when no book is held yet.
|
|
14
|
+
*/
|
|
3
15
|
export declare function useOrderbook(tradingPairId: string, tradingMode: TradingMode, magnitude: number, quotationMode: OrderbookQuotationMode, depth?: number): UseOrderbookReturn;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import { useMonacoSDK } from "../useMonaco";
|
|
3
|
+
import { readBookSeq, replacesHeld } from "./ordering";
|
|
4
|
+
/**
|
|
5
|
+
* One market's grouped orderbook: a REST snapshot for the first paint, then
|
|
6
|
+
* the live `orderbook` channel, each frame of which restates the whole view.
|
|
7
|
+
*
|
|
8
|
+
* The two are ordered by `bookSeq`, the durable-log sequence a book is exact
|
|
9
|
+
* as of, so the book held never goes back in time: a REST snapshot that lands
|
|
10
|
+
* after a newer frame is ignored, as is a frame older than the book held. At
|
|
11
|
+
* an equal `bookSeq` a frame replaces the REST snapshot and nothing else
|
|
12
|
+
* changes. A book without `bookSeq` (a server that predates it) cannot be
|
|
13
|
+
* ordered: frames are then applied as they arrive, and the REST snapshot only
|
|
14
|
+
* when no book is held yet.
|
|
15
|
+
*/
|
|
3
16
|
export function useOrderbook(tradingPairId, tradingMode, magnitude, quotationMode, depth = 10) {
|
|
4
17
|
const { sdk } = useMonacoSDK();
|
|
5
18
|
const [orderbook, setOrderbook] = useState(null);
|
|
@@ -14,15 +27,32 @@ export function useOrderbook(tradingPairId, tradingMode, magnitude, quotationMod
|
|
|
14
27
|
}
|
|
15
28
|
setOrderbook(null);
|
|
16
29
|
setError(null);
|
|
30
|
+
// This subscription's book. A changed parameter starts a new one from
|
|
31
|
+
// nothing; `active` keeps a late REST answer for the old one out of it.
|
|
32
|
+
let active = true;
|
|
33
|
+
let held = null;
|
|
34
|
+
const apply = (source, book) => {
|
|
35
|
+
if (!active)
|
|
36
|
+
return;
|
|
37
|
+
const seq = readBookSeq(book);
|
|
38
|
+
if (!replacesHeld(held, source, seq))
|
|
39
|
+
return;
|
|
40
|
+
held = { source, seq };
|
|
41
|
+
setOrderbook(book);
|
|
42
|
+
};
|
|
17
43
|
// Fetch initial orderbook via REST
|
|
18
44
|
sdk.orderbook
|
|
19
45
|
.getOrderbook(tradingPairId, { depth, tradingMode, magnitude, denomination: quotationMode })
|
|
20
|
-
.then((initial) =>
|
|
21
|
-
.catch((err) =>
|
|
46
|
+
.then((initial) => apply("rest", initial))
|
|
47
|
+
.catch((err) => {
|
|
48
|
+
if (active)
|
|
49
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
50
|
+
});
|
|
22
51
|
// Subscribe to WebSocket updates (ws connection handled by MonacoProvider)
|
|
23
|
-
const unsubscribe = sdk.ws.orderbook(tradingPairId, tradingMode, magnitude, quotationMode,
|
|
52
|
+
const unsubscribe = sdk.ws.orderbook(tradingPairId, tradingMode, magnitude, quotationMode, (frame) => apply("stream", frame));
|
|
24
53
|
setSubscribed(true);
|
|
25
54
|
return () => {
|
|
55
|
+
active = false;
|
|
26
56
|
unsubscribe();
|
|
27
57
|
setSubscribed(false);
|
|
28
58
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://docs.0xmonaco.com/sdk/typescript",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"lint": "biome lint ."
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@0xmonaco/core": "1.1.
|
|
20
|
-
"@0xmonaco/types": "1.1.
|
|
19
|
+
"@0xmonaco/core": "1.1.17",
|
|
20
|
+
"@0xmonaco/types": "1.1.17"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^19.3.0",
|