@0xmonaco/react 1.0.98 → 1.1.0
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/coverage.d.ts
CHANGED
package/dist/coverage.js
CHANGED
|
@@ -37,6 +37,7 @@ export const COVERED = {
|
|
|
37
37
|
get_mark_price: "useMarket",
|
|
38
38
|
get_market_metadata: "useMarket",
|
|
39
39
|
get_my_fee_tier: "useFees",
|
|
40
|
+
get_fee_schedule: "useFees",
|
|
40
41
|
get_my_trader_code: "useMyTraderCode",
|
|
41
42
|
set_trader_code: "useSetTraderCode",
|
|
42
43
|
clear_trader_code: "useClearTraderCode",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { GetMyFeeTierParams, GetMyFeeTierResponse, SimulateFeeParams, SimulateFeeResponse } from "@0xmonaco/types";
|
|
1
|
+
import type { GetFeeScheduleResponse, GetMyFeeTierParams, GetMyFeeTierResponse, SimulateFeeParams, SimulateFeeResponse } from "@0xmonaco/types";
|
|
2
2
|
export interface UseFeesReturn {
|
|
3
3
|
/** Simulate fees for an order before placing it */
|
|
4
4
|
simulateFees: (params: SimulateFeeParams) => Promise<SimulateFeeResponse>;
|
|
5
5
|
/** Get the caller's current fee tier, rolling 14-day volumes, and a pair's schedule */
|
|
6
6
|
getMyFeeTier: (params: GetMyFeeTierParams) => Promise<GetMyFeeTierResponse>;
|
|
7
|
+
/** Get a trading pair's public fee tier schedule (no authentication needed) */
|
|
8
|
+
getFeeSchedule: (tradingPairId: string) => Promise<GetFeeScheduleResponse>;
|
|
7
9
|
}
|
|
@@ -14,8 +14,15 @@ export const useFees = () => {
|
|
|
14
14
|
// Parameter validation is handled by the SDK core using Zod
|
|
15
15
|
return await sdk.fees.getMyFeeTier(params);
|
|
16
16
|
}, [sdk]);
|
|
17
|
+
const getFeeSchedule = useCallback(async (tradingPairId) => {
|
|
18
|
+
if (!sdk)
|
|
19
|
+
throw new Error("SDK not available");
|
|
20
|
+
// Public read: the core client sends it unsigned, so it works before sign-in
|
|
21
|
+
return await sdk.fees.getFeeSchedule(tradingPairId);
|
|
22
|
+
}, [sdk]);
|
|
17
23
|
return {
|
|
18
24
|
simulateFees,
|
|
19
25
|
getMyFeeTier,
|
|
26
|
+
getFeeSchedule,
|
|
20
27
|
};
|
|
21
28
|
};
|
|
@@ -441,7 +441,7 @@ const ORDER_STATUSES = {
|
|
|
441
441
|
const ORDER_TYPES = { LIMIT: true, MARKET: true };
|
|
442
442
|
const ORDER_SIDES = { BUY: true, SELL: true };
|
|
443
443
|
const TRADING_MODES = { SPOT: true, MARGIN: true };
|
|
444
|
-
const TIMES_IN_FORCE = { GTC: true, IOC: true, FOK: true
|
|
444
|
+
const TIMES_IN_FORCE = { GTC: true, IOC: true, FOK: true };
|
|
445
445
|
/**
|
|
446
446
|
* Narrow a widened WebSocket value back to its closed union, or `undefined`.
|
|
447
447
|
*
|
|
@@ -601,6 +601,10 @@ export function orderFromSnapshotItem(item) {
|
|
|
601
601
|
// What placed the order, as REST reports it. Absent stays absent, so a
|
|
602
602
|
// snapshot that does not report one leaves the label the row already had.
|
|
603
603
|
...(item.origin === undefined ? {} : { origin: item.origin }),
|
|
604
|
+
// The Monaco fee rates fixed at placement. Absent stays absent: an order
|
|
605
|
+
// placed before rates were stored has none, never "0".
|
|
606
|
+
...(item.placementTakerFeeBps === undefined ? {} : { placementTakerFeeBps: item.placementTakerFeeBps }),
|
|
607
|
+
...(item.placementMakerFeeBps === undefined ? {} : { placementMakerFeeBps: item.placementMakerFeeBps }),
|
|
604
608
|
// Carried, not dropped: it is what the merge ranks this row by, and a row
|
|
605
609
|
// whose state came from the snapshot while its version stayed at the held
|
|
606
610
|
// value would be internally inconsistent — reporting a step it does not
|
|
@@ -686,7 +690,9 @@ export function applyOrderSnapshot(current, items, limit) {
|
|
|
686
690
|
// ranking, as `mergeOrders` does: the stored row's value stands, and a
|
|
687
691
|
// held row that has none gains it from a snapshot that lost on version.
|
|
688
692
|
const origin = row.origin ?? existing.origin;
|
|
689
|
-
|
|
693
|
+
// The placement fee rates likewise, the held row first.
|
|
694
|
+
const merged = withPlacementFeeRates(origin === existing.origin ? existing : { ...existing, origin }, row);
|
|
695
|
+
return merged === existing ? [] : [merged];
|
|
690
696
|
}
|
|
691
697
|
return [{ ...existing, ...row }];
|
|
692
698
|
});
|
|
@@ -790,6 +796,25 @@ export function snapshotOrderRows(items) {
|
|
|
790
796
|
const mapped = items.map(orderFromSnapshotItem);
|
|
791
797
|
return { rows: mapped.filter((row) => row !== null), hasUndescribableRow: mapped.some((row) => row === null) };
|
|
792
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Fill the Monaco fee rates fixed at placement onto `order` from `sources`, in
|
|
801
|
+
* order. An order id never changes its rates (a replacement is a new order),
|
|
802
|
+
* so like `origin` they are merged outside the version ranking: the first
|
|
803
|
+
* source that knows a rate supplies it, and a row that lost the ranking still
|
|
804
|
+
* contributes one the winner lacks. Returns `order` itself when nothing
|
|
805
|
+
* changes.
|
|
806
|
+
*/
|
|
807
|
+
function withPlacementFeeRates(order, ...sources) {
|
|
808
|
+
const takerFeeBps = [order, ...sources].map((source) => source.placementTakerFeeBps).find((rate) => rate !== undefined);
|
|
809
|
+
const makerFeeBps = [order, ...sources].map((source) => source.placementMakerFeeBps).find((rate) => rate !== undefined);
|
|
810
|
+
if (takerFeeBps === order.placementTakerFeeBps && makerFeeBps === order.placementMakerFeeBps)
|
|
811
|
+
return order;
|
|
812
|
+
return {
|
|
813
|
+
...order,
|
|
814
|
+
...(takerFeeBps === undefined ? {} : { placementTakerFeeBps: takerFeeBps }),
|
|
815
|
+
...(makerFeeBps === undefined ? {} : { placementMakerFeeBps: makerFeeBps }),
|
|
816
|
+
};
|
|
817
|
+
}
|
|
793
818
|
/**
|
|
794
819
|
* Reconcile a REST read against live state, ranking on `version` first.
|
|
795
820
|
*
|
|
@@ -823,7 +848,8 @@ export function mergeOrders(current, fetched, limit) {
|
|
|
823
848
|
// keeps it against a REST response that does not report one. If both
|
|
824
849
|
// report one and they differ, the REST row is the stored order and stands.
|
|
825
850
|
const origin = incoming.origin ?? live.origin ?? undefined;
|
|
826
|
-
|
|
851
|
+
// The placement fee rates likewise, the REST row first.
|
|
852
|
+
return withPlacementFeeRates(origin === winner.origin ? winner : { ...winner, origin }, incoming, live);
|
|
827
853
|
});
|
|
828
854
|
const liveOnly = current.filter((order) => !fetchedIds.has(order.id));
|
|
829
855
|
// Cap by RECENCY, not by side. Prepending every live-only row and slicing
|
|
@@ -921,6 +947,11 @@ export function orderFromEvent(event) {
|
|
|
921
947
|
// not reported, never "USER", and an unrecognized value is passed through
|
|
922
948
|
// (the model's type is widened for it).
|
|
923
949
|
origin: typeof data.origin === "string" ? data.origin : undefined,
|
|
950
|
+
// The Monaco fee rates fixed at placement, as REST reports them. Spread in
|
|
951
|
+
// only when sent: an order placed before rates were stored has none, and
|
|
952
|
+
// absent must not read as "0".
|
|
953
|
+
...(typeof data.placementTakerFeeBps === "string" ? { placementTakerFeeBps: data.placementTakerFeeBps } : {}),
|
|
954
|
+
...(typeof data.placementMakerFeeBps === "string" ? { placementMakerFeeBps: data.placementMakerFeeBps } : {}),
|
|
924
955
|
// The local revision the merge ranks against. Without it every REST
|
|
925
956
|
// response outranks live state by default and the stream can be undone.
|
|
926
957
|
version: typeof data.version === "number" ? data.version : undefined,
|
|
@@ -1003,7 +1034,13 @@ export function updateOrderFromEvent(order, event) {
|
|
|
1003
1034
|
// it, and one labels a row held without it even when the frame loses on
|
|
1004
1035
|
// version, but never replaces a value already held (which may be the stored
|
|
1005
1036
|
// REST one).
|
|
1006
|
-
|
|
1037
|
+
const labelled = order.origin === undefined && typeof data.origin === "string" ? { ...winner, origin: data.origin } : winner;
|
|
1038
|
+
// The placement fee rates likewise: the held row's stand, and a frame
|
|
1039
|
+
// supplies any it lacks.
|
|
1040
|
+
return withPlacementFeeRates(labelled, order, {
|
|
1041
|
+
...(typeof data.placementTakerFeeBps === "string" ? { placementTakerFeeBps: data.placementTakerFeeBps } : {}),
|
|
1042
|
+
...(typeof data.placementMakerFeeBps === "string" ? { placementMakerFeeBps: data.placementMakerFeeBps } : {}),
|
|
1043
|
+
});
|
|
1007
1044
|
}
|
|
1008
1045
|
/**
|
|
1009
1046
|
* Whether a live event can advance the row currently held.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/react",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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
|
|
20
|
-
"@0xmonaco/types": "1.0
|
|
19
|
+
"@0xmonaco/core": "1.1.0",
|
|
20
|
+
"@0xmonaco/types": "1.1.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^19.3.0",
|