@0xmonaco/react 0.8.20 → 0.8.22-develop.efb9dc9

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.
@@ -8,6 +8,7 @@ export declare const COVERED: {
8
8
  batch_create_orders: string;
9
9
  batch_replace_orders: string;
10
10
  cancel_conditional_order: string;
11
+ get_conditional_order: string;
11
12
  cancel_order: string;
12
13
  close_position: string;
13
14
  batch_close_all_positions: string;
@@ -19,6 +20,10 @@ export declare const COVERED: {
19
20
  get_mark_price: string;
20
21
  get_market_metadata: string;
21
22
  get_my_fee_tier: string;
23
+ get_my_trader_code: string;
24
+ get_rewards_balance: string;
25
+ get_trader_code_info: string;
26
+ transfer_rewards: string;
22
27
  get_open_interest: string;
23
28
  get_order_by_id: string;
24
29
  get_orderbook_snapshot: string;
@@ -26,6 +31,7 @@ export declare const COVERED: {
26
31
  get_perp_market_config: string;
27
32
  get_perp_market_summary: string;
28
33
  get_position: string;
34
+ get_position_pnl_history: string;
29
35
  get_position_risk: string;
30
36
  get_trades: string;
31
37
  get_user_balance_by_asset: string;
package/dist/coverage.js CHANGED
@@ -8,6 +8,7 @@ export const COVERED = {
8
8
  batch_create_orders: "useTrade",
9
9
  batch_replace_orders: "useTrade",
10
10
  cancel_conditional_order: "useTrade",
11
+ get_conditional_order: "useTrade",
11
12
  cancel_order: "useTrade",
12
13
  close_position: "usePositions",
13
14
  batch_close_all_positions: "usePositions",
@@ -19,6 +20,10 @@ export const COVERED = {
19
20
  get_mark_price: "useMarket",
20
21
  get_market_metadata: "useMarket",
21
22
  get_my_fee_tier: "useFees",
23
+ get_my_trader_code: "usePitpass",
24
+ get_rewards_balance: "usePitpass",
25
+ get_trader_code_info: "usePitpass",
26
+ transfer_rewards: "usePitpass",
22
27
  get_open_interest: "useMarket",
23
28
  get_order_by_id: "useTrade",
24
29
  get_orderbook_snapshot: "useOrderbook",
@@ -26,6 +31,7 @@ export const COVERED = {
26
31
  get_perp_market_config: "useMarket",
27
32
  get_perp_market_summary: "useMarket",
28
33
  get_position: "usePositions",
34
+ get_position_pnl_history: "usePositionPnlHistory",
29
35
  get_position_risk: "usePositions",
30
36
  get_trades: "useTradeFeed",
31
37
  get_user_balance_by_asset: "useProfile",
@@ -4,6 +4,7 @@ export * from "./useMarket";
4
4
  export * from "./useMonaco";
5
5
  export * from "./useOHLCV";
6
6
  export * from "./useOrderbook";
7
+ export * from "./usePositionPnlHistory";
7
8
  export * from "./usePositions";
8
9
  export * from "./useProfile";
9
10
  export * from "./useTokenLifecycle";
@@ -4,6 +4,7 @@ export * from "./useMarket";
4
4
  export * from "./useMonaco";
5
5
  export * from "./useOHLCV";
6
6
  export * from "./useOrderbook";
7
+ export * from "./usePositionPnlHistory";
7
8
  export * from "./usePositions";
8
9
  export * from "./useProfile";
9
10
  export * from "./useTokenLifecycle";
@@ -0,0 +1,2 @@
1
+ export type { UsePositionPnlHistoryParams, UsePositionPnlHistoryReturn } from "./types";
2
+ export { usePositionPnlHistory } from "./usePositionPnlHistory";
@@ -0,0 +1 @@
1
+ export { usePositionPnlHistory } from "./usePositionPnlHistory";
@@ -0,0 +1,15 @@
1
+ import type { GetPositionPnlHistoryParams, PositionPnlPoint } from "@0xmonaco/types";
2
+ export interface UsePositionPnlHistoryParams extends GetPositionPnlHistoryParams {
3
+ /** Position UUID to chart; pass null/undefined to defer fetching */
4
+ positionId: string | null | undefined;
5
+ }
6
+ export interface UsePositionPnlHistoryReturn {
7
+ /** Forward-filled PnL state samples, oldest first */
8
+ data: PositionPnlPoint[];
9
+ /** True while a fetch is in flight */
10
+ loading: boolean;
11
+ /** Last fetch error, if any */
12
+ error: Error | null;
13
+ /** Re-run the fetch with the current parameters */
14
+ refetch: () => Promise<void>;
15
+ }
File without changes
@@ -0,0 +1,12 @@
1
+ import type { UsePositionPnlHistoryParams, UsePositionPnlHistoryReturn } from "./types";
2
+ /**
3
+ * Hook for fetching a position's bucketed PnL history.
4
+ *
5
+ * Fetches the forward-filled PnL state samples for one owned position at the
6
+ * requested interval and refetches whenever the position or window changes.
7
+ * `cumFundingPaid`/`cumFees` are cost-positive on the wire — negate at render
8
+ * time to display funding as a signed PnL contribution.
9
+ *
10
+ * @param params - positionId plus the interval and optional start/end times
11
+ */
12
+ export declare function usePositionPnlHistory(params: UsePositionPnlHistoryParams): UsePositionPnlHistoryReturn;
@@ -0,0 +1,59 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { useMonacoSDK } from "../useMonaco";
3
+ /**
4
+ * Hook for fetching a position's bucketed PnL history.
5
+ *
6
+ * Fetches the forward-filled PnL state samples for one owned position at the
7
+ * requested interval and refetches whenever the position or window changes.
8
+ * `cumFundingPaid`/`cumFees` are cost-positive on the wire — negate at render
9
+ * time to display funding as a signed PnL contribution.
10
+ *
11
+ * @param params - positionId plus the interval and optional start/end times
12
+ */
13
+ export function usePositionPnlHistory(params) {
14
+ const { positionId, interval, startTime, endTime } = params;
15
+ const { sdk } = useMonacoSDK();
16
+ const [data, setData] = useState([]);
17
+ const [loading, setLoading] = useState(false);
18
+ const [error, setError] = useState(null);
19
+ // Only the newest in-flight request may touch state: a slower response for
20
+ // an older position/window must not overwrite a newer result.
21
+ const requestSeq = useRef(0);
22
+ const fetchHistory = useCallback(async () => {
23
+ const seq = ++requestSeq.current;
24
+ if (!sdk?.positions || !positionId) {
25
+ setData([]);
26
+ setLoading(false);
27
+ setError(null);
28
+ return;
29
+ }
30
+ setLoading(true);
31
+ setError(null);
32
+ try {
33
+ const response = await sdk.positions.getPositionPnlHistory(positionId, {
34
+ interval,
35
+ startTime,
36
+ endTime,
37
+ });
38
+ if (seq !== requestSeq.current)
39
+ return;
40
+ setData(response.data);
41
+ }
42
+ catch (err) {
43
+ if (seq !== requestSeq.current)
44
+ return;
45
+ // Drop prior data so a stale series is never shown under a fresh error.
46
+ setData([]);
47
+ setError(err instanceof Error ? err : new Error(String(err)));
48
+ }
49
+ finally {
50
+ if (seq === requestSeq.current) {
51
+ setLoading(false);
52
+ }
53
+ }
54
+ }, [sdk, positionId, interval, startTime, endTime]);
55
+ useEffect(() => {
56
+ void fetchHistory();
57
+ }, [fetchHistory]);
58
+ return { data, loading, error, refetch: fetchHistory };
59
+ }
@@ -1,4 +1,4 @@
1
- import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ReplaceOrderResponse, TradingAPI } from "@0xmonaco/types";
1
+ import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, ConditionalOrder, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ReplaceOrderResponse, TradingAPI } from "@0xmonaco/types";
2
2
  type PlaceLimitOrderOptions = NonNullable<Parameters<TradingAPI["placeLimitOrder"]>[4]>;
3
3
  type PlaceMarketOrderOptions = NonNullable<Parameters<TradingAPI["placeMarketOrder"]>[3]>;
4
4
  export interface UseTradeReturn {
@@ -10,6 +10,8 @@ export interface UseTradeReturn {
10
10
  cancelOrder: (orderId: string) => Promise<CancelOrderResponse>;
11
11
  /** Cancel an active conditional TP/SL order */
12
12
  cancelConditionalOrder: (conditionalOrderId: string) => Promise<CancelConditionalOrderResponse>;
13
+ /** Get a single conditional TP/SL order by its UUID */
14
+ getConditionalOrder: (conditionalOrderId: string) => Promise<ConditionalOrder>;
13
15
  /** List conditional TP/SL orders */
14
16
  listConditionalOrders: (params?: ListConditionalOrdersParams) => Promise<ListConditionalOrdersResponse>;
15
17
  /** Batch cancel specific orders by their IDs */
@@ -46,6 +46,13 @@ export const useTrade = () => {
46
46
  throw new Error("Conditional order ID is required and cannot be empty");
47
47
  return await sdk.trading.cancelConditionalOrder(conditionalOrderId);
48
48
  }, [sdk]);
49
+ const getConditionalOrder = useCallback(async (conditionalOrderId) => {
50
+ if (!sdk)
51
+ throw new Error("SDK not available");
52
+ if (!conditionalOrderId?.trim())
53
+ throw new Error("Conditional order ID is required and cannot be empty");
54
+ return await sdk.trading.getConditionalOrder(conditionalOrderId);
55
+ }, [sdk]);
49
56
  const listConditionalOrders = useCallback(async (params) => {
50
57
  if (!sdk)
51
58
  throw new Error("SDK not available");
@@ -113,6 +120,7 @@ export const useTrade = () => {
113
120
  // Order management
114
121
  cancelOrder,
115
122
  cancelConditionalOrder,
123
+ getConditionalOrder,
116
124
  listConditionalOrders,
117
125
  batchCancel,
118
126
  batchCancelAll,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/react",
3
- "version": "0.8.20",
3
+ "version": "0.8.22-develop.efb9dc9",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,8 +20,8 @@
20
20
  "lint": "biome lint ."
21
21
  },
22
22
  "dependencies": {
23
- "@0xmonaco/core": "0.8.20",
24
- "@0xmonaco/types": "0.8.20"
23
+ "@0xmonaco/core": "0.8.22-develop.efb9dc9",
24
+ "@0xmonaco/types": "0.8.22-develop.efb9dc9"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "^19.1.12",
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
32
- "wagmi": "^2.0.0 || ^3.0.0",
33
- "viem": "^2.45.2"
32
+ "viem": "^2.45.2",
33
+ "wagmi": "^2.0.0 || ^3.0.0"
34
34
  },
35
35
  "exports": {
36
36
  ".": {