@0xmonaco/react 1.0.82 → 1.0.83

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.
@@ -0,0 +1,6 @@
1
+ import type { Candlestick } from "@0xmonaco/types";
2
+ /**
3
+ * Live candle events may omit persisted OI. Keep the REST-sampled pair only
4
+ * while updating that same candle; a new candle must not inherit the old pair.
5
+ */
6
+ export declare function mergeLiveCandleOpenInterest(previous: Candlestick | undefined, live: Candlestick): Candlestick;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Live candle events may omit persisted OI. Keep the REST-sampled pair only
3
+ * while updating that same candle; a new candle must not inherit the old pair.
4
+ */
5
+ export function mergeLiveCandleOpenInterest(previous, live) {
6
+ if (previous?.T === live.T && live.openInterestBase == null && live.openInterestNotional == null) {
7
+ return {
8
+ ...live,
9
+ openInterestBase: previous.openInterestBase,
10
+ openInterestNotional: previous.openInterestNotional,
11
+ };
12
+ }
13
+ return live;
14
+ }
@@ -1,5 +1,6 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
2
  import { useMonacoSDK } from "../useMonaco";
3
+ import { mergeLiveCandleOpenInterest } from "./mergeLiveCandleOpenInterest";
3
4
  /**
4
5
  * Hook for subscribing to real-time OHLCV candlestick events via WebSocket (public)
5
6
  *
@@ -37,16 +38,18 @@ export function useOHLCV(params) {
37
38
  try {
38
39
  unsubscribe = sdk.ws.ohlcv(tradingPairId, tradingMode, interval, (event) => {
39
40
  setCandlesticks((prev) => {
41
+ const lastCandle = prev[prev.length - 1];
42
+ const liveCandle = event.candlestick;
43
+ const candle = mergeLiveCandleOpenInterest(lastCandle, liveCandle);
40
44
  if (prev.length === 0) {
41
- return [event.candlestick];
45
+ return [candle];
42
46
  }
43
- const lastCandle = prev[prev.length - 1];
44
47
  if (lastCandle && lastCandle.T === event.candlestick.T) {
45
48
  const updated = [...prev];
46
- updated[updated.length - 1] = event.candlestick;
49
+ updated[updated.length - 1] = candle;
47
50
  return updated;
48
51
  }
49
- return [...prev, event.candlestick];
52
+ return [...prev, candle];
50
53
  });
51
54
  });
52
55
  setSubscribed(true);
@@ -96,9 +96,15 @@ export function useUserOrders(maxOrders = 50) {
96
96
  pageToken: "",
97
97
  });
98
98
  // Deduplicate the paginated orders by id, keeping the first occurrence.
99
+ // A slice is dropped too. Only a server from before 0XM-3070 lists slices,
100
+ // and against one this page can come back short of `maxOrders`; the hook
101
+ // does not page further to make up the difference, since the next server
102
+ // release stops listing them.
99
103
  const seenIds = new Set();
100
104
  const dedupedOrders = [];
101
105
  for (const order of response.orders) {
106
+ if (isTwapSlice(order.parentOrderId))
107
+ continue;
102
108
  if (!seenIds.has(order.id)) {
103
109
  seenIds.add(order.id);
104
110
  dedupedOrders.push(order);
@@ -304,6 +310,9 @@ export function useUserOrders(maxOrders = 50) {
304
310
  // This prevents race conditions where WS events could be overwritten by REST response
305
311
  try {
306
312
  unsubscribe = sdk.ws.userOrders((event) => {
313
+ // A slice's frames carry its parent; the list never holds one.
314
+ if ("parentOrderId" in event.data && isTwapSlice(event.data.parentOrderId))
315
+ return;
307
316
  // Built OUTSIDE the state updater: an updater must stay pure, and
308
317
  // React may invoke it more than once. `null` here means the event
309
318
  // is an `OrderPlaced` this version cannot describe.
@@ -334,7 +343,10 @@ export function useUserOrders(maxOrders = 50) {
334
343
  // REST round trip. It matters most after a reconnect: the
335
344
  // resubscribe brings a fresh one, while a targeted read resolves
336
345
  // each formerly-resting order it omits.
337
- (items) => {
346
+ (snapshotItems) => {
347
+ // The snapshot carries resting slices with their parent; the list
348
+ // never holds one, so it is neither added nor looked for.
349
+ const items = snapshotItems.filter((item) => !isTwapSlice(item.parentOrderId));
338
350
  // Read BEFORE the updater: whether a row was declined depends only
339
351
  // on the rows themselves, and an updater must stay free of side
340
352
  // effects because React may invoke it more than once. A row this
@@ -443,6 +455,19 @@ function asKnown(known, value) {
443
455
  function asOrderStatus(value) {
444
456
  return asKnown(ORDER_STATUSES, value);
445
457
  }
458
+ /**
459
+ * Whether a row or frame belongs to a TWAP slice: a child order its TWAP
460
+ * parent placed, which names that parent in `parentOrderId`.
461
+ *
462
+ * The order listing leaves slices to their parent's slice list
463
+ * (`listTwapOrderSlices`, 0XM-3070), and this hook mirrors the listing, so it
464
+ * drops them from every source — the REST page, the subscribe-time snapshot and
465
+ * the live frames. Without the last two, a resting slice would appear live and
466
+ * then vanish on the next REST read.
467
+ */
468
+ function isTwapSlice(parentOrderId) {
469
+ return typeof parentOrderId === "string" && parentOrderId.length > 0;
470
+ }
446
471
  /**
447
472
  * `live`, with every REST-only field taken from the fetched row.
448
473
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/react",
3
- "version": "1.0.82",
3
+ "version": "1.0.83",
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.0.82",
20
- "@0xmonaco/types": "1.0.82"
19
+ "@0xmonaco/core": "1.0.83",
20
+ "@0xmonaco/types": "1.0.83"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^19.2.18",