@0xmonaco/core 1.0.76 → 1.0.80
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.
|
@@ -77,10 +77,12 @@ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
|
|
|
77
77
|
*/
|
|
78
78
|
transferRewards(params: TransferRewardsParams): Promise<TransferRewardsResponse>;
|
|
79
79
|
/**
|
|
80
|
-
* Read the caller's own referral position: their upline (L1, L2,
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
80
|
+
* Read the caller's own referral position: their upline (L1, L2, ..., as
|
|
81
|
+
* many levels as their trades on this client application pay), their L1
|
|
82
|
+
* referrer, total earned, and recent rewards. Self-scoped — no id is sent,
|
|
83
|
+
* so it can only ever return your own chain. `referrer` is "" when you were
|
|
84
|
+
* not referred; `upline` is also empty when this client application pays no
|
|
85
|
+
* referral levels.
|
|
84
86
|
*/
|
|
85
87
|
getMyReferralPosition(): Promise<GetMyReferralPositionResponse>;
|
|
86
88
|
/**
|
|
@@ -96,7 +98,8 @@ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
|
|
|
96
98
|
* Read one level of the caller's own referral tree: the wallets `parent`
|
|
97
99
|
* directly referred (the caller when omitted), a page at a time, newest
|
|
98
100
|
* first. `parent` must be the caller or one of their own referees above the
|
|
99
|
-
* deepest
|
|
101
|
+
* deepest level any client application rewards (at most 10); any other
|
|
102
|
+
* wallet is a 404. The caller's direct referees (L1) are always listed.
|
|
100
103
|
*/
|
|
101
104
|
getMyReferralTree(params?: GetMyReferralTreeParams): Promise<GetMyReferralTreeResponse>;
|
|
102
105
|
}
|
package/dist/api/pitpass/api.js
CHANGED
|
@@ -109,10 +109,12 @@ export class PitpassAPIImpl extends BaseAPI {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
|
-
* Read the caller's own referral position: their upline (L1, L2,
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
112
|
+
* Read the caller's own referral position: their upline (L1, L2, ..., as
|
|
113
|
+
* many levels as their trades on this client application pay), their L1
|
|
114
|
+
* referrer, total earned, and recent rewards. Self-scoped — no id is sent,
|
|
115
|
+
* so it can only ever return your own chain. `referrer` is "" when you were
|
|
116
|
+
* not referred; `upline` is also empty when this client application pays no
|
|
117
|
+
* referral levels.
|
|
116
118
|
*/
|
|
117
119
|
async getMyReferralPosition() {
|
|
118
120
|
return await this.makeAuthenticatedRequest("/api/v1/pitpass/referrals/me", {
|
|
@@ -146,7 +148,8 @@ export class PitpassAPIImpl extends BaseAPI {
|
|
|
146
148
|
* Read one level of the caller's own referral tree: the wallets `parent`
|
|
147
149
|
* directly referred (the caller when omitted), a page at a time, newest
|
|
148
150
|
* first. `parent` must be the caller or one of their own referees above the
|
|
149
|
-
* deepest
|
|
151
|
+
* deepest level any client application rewards (at most 10); any other
|
|
152
|
+
* wallet is a 404. The caller's direct referees (L1) are always listed.
|
|
150
153
|
*/
|
|
151
154
|
async getMyReferralTree(params) {
|
|
152
155
|
if (params) {
|
|
@@ -11,10 +11,11 @@ export declare class PositionsAPIImpl extends BaseAPI implements PositionsAPI {
|
|
|
11
11
|
* paging loop off it — follow `nextPageToken`.
|
|
12
12
|
*
|
|
13
13
|
* Order depends on the filter: `status: "OPEN"` is served from the engine's
|
|
14
|
-
* live view in `(marginAccountId, tradingPairId, positionId)` order
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* live view in `(marginAccountId, tradingPairId, positionId)` order;
|
|
15
|
+
* `status: "CLOSED"` and `status: "LIQUIDATED"` from persisted rows
|
|
16
|
+
* newest-closed first; every other filter from persisted rows
|
|
17
|
+
* newest-opened first. Each is a separate cursor space, so a token is only
|
|
18
|
+
* valid in the one that minted it.
|
|
18
19
|
*/
|
|
19
20
|
listPositions(params?: ListPositionsParams): Promise<ListPositionsResponse>;
|
|
20
21
|
getPosition(positionId: string): Promise<GetPositionResponse>;
|
|
@@ -12,10 +12,11 @@ export class PositionsAPIImpl extends BaseAPI {
|
|
|
12
12
|
* paging loop off it — follow `nextPageToken`.
|
|
13
13
|
*
|
|
14
14
|
* Order depends on the filter: `status: "OPEN"` is served from the engine's
|
|
15
|
-
* live view in `(marginAccountId, tradingPairId, positionId)` order
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* live view in `(marginAccountId, tradingPairId, positionId)` order;
|
|
16
|
+
* `status: "CLOSED"` and `status: "LIQUIDATED"` from persisted rows
|
|
17
|
+
* newest-closed first; every other filter from persisted rows
|
|
18
|
+
* newest-opened first. Each is a separate cursor space, so a token is only
|
|
19
|
+
* valid in the one that minted it.
|
|
19
20
|
*/
|
|
20
21
|
async listPositions(params) {
|
|
21
22
|
if (params) {
|
|
@@ -454,6 +454,10 @@ function parseMarketStatsSummary(raw) {
|
|
|
454
454
|
// marketStatus stays lenient (read as string, not a strict enum) so an
|
|
455
455
|
// unrecognized status value never drops an otherwise-valid summary row.
|
|
456
456
|
marketStatus: readString(data, "marketStatus"),
|
|
457
|
+
indexPrice: readOptionalString(data, "indexPrice"),
|
|
458
|
+
fundingRate: readOptionalString(data, "fundingRate"),
|
|
459
|
+
premium: readOptionalString(data, "premium"),
|
|
460
|
+
openInterestNotional: readOptionalString(data, "openInterestNotional"),
|
|
457
461
|
};
|
|
458
462
|
}
|
|
459
463
|
function parseMarketStatsAllEvent(rawData) {
|
|
@@ -464,6 +468,60 @@ function parseMarketStatsAllEvent(rawData) {
|
|
|
464
468
|
markets: rawData.markets.map(parseMarketStatsSummary),
|
|
465
469
|
};
|
|
466
470
|
}
|
|
471
|
+
function parseRiskTier(raw) {
|
|
472
|
+
if (!isRecord(raw)) {
|
|
473
|
+
throw new Error("Invalid instrument event: each riskTiers entry must be an object");
|
|
474
|
+
}
|
|
475
|
+
const tierLevel = raw.tierLevel;
|
|
476
|
+
if (typeof tierLevel !== "number" || !Number.isSafeInteger(tierLevel) || tierLevel < 1) {
|
|
477
|
+
throw new Error("Invalid WebSocket event: tierLevel must be a positive integer");
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
tierLevel,
|
|
481
|
+
lowerBoundNotional: readString(raw, "lowerBoundNotional"),
|
|
482
|
+
maxLeverage: readOptionalString(raw, "maxLeverage"),
|
|
483
|
+
initialMarginRatio: readString(raw, "initialMarginRatio"),
|
|
484
|
+
maintenanceMarginRatio: readString(raw, "maintenanceMarginRatio"),
|
|
485
|
+
initialMarginDeduction: readString(raw, "initialMarginDeduction"),
|
|
486
|
+
maintenanceMarginDeduction: readString(raw, "maintenanceMarginDeduction"),
|
|
487
|
+
maxPositionNotional: readOptionalString(raw, "maxPositionNotional"),
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Read the perp-only margin ladder. Absent (a spot market, or a server that
|
|
492
|
+
* predates the key) is `undefined`, never a made-up empty ladder; a present
|
|
493
|
+
* value that is not an array of well-formed tiers throws like any other
|
|
494
|
+
* malformed field.
|
|
495
|
+
*/
|
|
496
|
+
function readOptionalRiskTiers(source, field) {
|
|
497
|
+
const value = source[field];
|
|
498
|
+
if (value === undefined || value === null)
|
|
499
|
+
return undefined;
|
|
500
|
+
if (!Array.isArray(value)) {
|
|
501
|
+
throw new Error(`Invalid WebSocket event: ${field} must be an array`);
|
|
502
|
+
}
|
|
503
|
+
return value.map(parseRiskTier);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Parse one `trades` snapshot row: the live trade frame's `data` body.
|
|
507
|
+
*
|
|
508
|
+
* Strict, unlike the live trade handler's casts: a snapshot is delivered
|
|
509
|
+
* all-or-nothing, so a row with a missing or non-string field must throw for
|
|
510
|
+
* {@link snapshotFrameHandler} to withhold the frame. The output is the same
|
|
511
|
+
* `TradeEventData` the live handler builds, `makerSide` uppercased likewise.
|
|
512
|
+
*/
|
|
513
|
+
function parseTradeEventData(raw) {
|
|
514
|
+
if (!isRecord(raw)) {
|
|
515
|
+
throw new Error("Invalid trade snapshot row: must be an object");
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
tradeId: readString(raw, "trade_id"),
|
|
519
|
+
price: readString(raw, "price"),
|
|
520
|
+
quantity: readString(raw, "quantity"),
|
|
521
|
+
makerSide: readString(raw, "maker_side").toUpperCase(),
|
|
522
|
+
executedAt: readString(raw, "executed_at"),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
467
525
|
function parseInstrumentEventData(raw) {
|
|
468
526
|
if (!isRecord(raw)) {
|
|
469
527
|
throw new Error("Invalid instrument event: data must be an object");
|
|
@@ -510,6 +568,7 @@ function parseInstrumentEventData(raw) {
|
|
|
510
568
|
maxLeverage: readOptionalString(data, "maxLeverage"),
|
|
511
569
|
initialMarginRate: readOptionalString(data, "initialMarginRate"),
|
|
512
570
|
maintenanceMarginRate: readOptionalString(data, "maintenanceMarginRate"),
|
|
571
|
+
riskTiers: readOptionalRiskTiers(data, "riskTiers"),
|
|
513
572
|
// Values are snake_case wire field NAMES (e.g. "tick_size"); only object
|
|
514
573
|
// keys are camelCased, so they pass through untouched.
|
|
515
574
|
changedFields: readStringArray(data, "changedFields"),
|
|
@@ -1457,7 +1516,7 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1457
1516
|
}
|
|
1458
1517
|
});
|
|
1459
1518
|
};
|
|
1460
|
-
const subscribeTrades = (tradingPairId, handler) => {
|
|
1519
|
+
const subscribeTrades = (tradingPairId, handler, onSnapshot) => {
|
|
1461
1520
|
const channel = `trades:${tradingPairId}`;
|
|
1462
1521
|
return subscribe(channel, (rawData) => {
|
|
1463
1522
|
try {
|
|
@@ -1480,7 +1539,7 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1480
1539
|
catch (err) {
|
|
1481
1540
|
console.error("WebSocket: Error processing trade event", err);
|
|
1482
1541
|
}
|
|
1483
|
-
});
|
|
1542
|
+
}, onSnapshot && snapshotFrameHandler("trades", parseTradeEventData, onSnapshot));
|
|
1484
1543
|
};
|
|
1485
1544
|
const subscribeMovements = (handler) => {
|
|
1486
1545
|
// User is identified from the authenticated session, so channel is just "movements"
|
|
@@ -1717,8 +1776,9 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1717
1776
|
* markets, or pass one to filter. Every frame carries the market's FULL
|
|
1718
1777
|
* current config as a terminal-state snapshot (never an additive delta);
|
|
1719
1778
|
* `changedFields` names what the mutation touched. A subscribe-time snapshot
|
|
1720
|
-
* of
|
|
1721
|
-
*
|
|
1779
|
+
* of every listed market arrives before the live diffs, inactive markets
|
|
1780
|
+
* included and flagged `isActive: false` (filter on `isActive` for the
|
|
1781
|
+
* tradable set); a subscriber joining a channel this client already holds is replayed the
|
|
1722
1782
|
* current baseline from a local cache instead (the server snapshots only
|
|
1723
1783
|
* genuinely new wire subscriptions). Detected broadcast lag closes the connection
|
|
1724
1784
|
* with 1013; a new wire subscription provides a fresh baseline.
|
|
@@ -1761,8 +1821,8 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1761
1821
|
}
|
|
1762
1822
|
},
|
|
1763
1823
|
// The subscribe-time baseline arrives as one Snapshot frame whose data is
|
|
1764
|
-
// a flat InstrumentEventData[] (a `listing` per
|
|
1765
|
-
// per-item envelope).
|
|
1824
|
+
// a flat InstrumentEventData[] (a `listing` per market, inactive ones
|
|
1825
|
+
// flagged `isActive: false`, no per-item envelope).
|
|
1766
1826
|
//
|
|
1767
1827
|
// Where it goes depends on whether the caller opted in. With
|
|
1768
1828
|
// `onSnapshot`, the rows are handed over as one array and the event
|
|
@@ -1774,7 +1834,7 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1774
1834
|
// asked would be a silent behaviour break.
|
|
1775
1835
|
//
|
|
1776
1836
|
// Either way the local cache is replaced wholesale rather than upserted,
|
|
1777
|
-
// so markets absent from the snapshot (
|
|
1837
|
+
// so markets absent from the snapshot (no longer listed) do
|
|
1778
1838
|
// not linger.
|
|
1779
1839
|
snapshotFrameHandler("instrument", parseInstrumentEventData, (items) => {
|
|
1780
1840
|
const events = items.map((item) => ({ tradingPairId: item.tradingPairId, data: item }));
|
|
@@ -1818,18 +1878,13 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1818
1878
|
// follows the same delivery contract: one array to `onSnapshot`
|
|
1819
1879
|
// when opted in, per-market events otherwise.
|
|
1820
1880
|
//
|
|
1821
|
-
//
|
|
1822
|
-
//
|
|
1823
|
-
//
|
|
1824
|
-
//
|
|
1825
|
-
// its market set from the array, so a delisted row there would
|
|
1826
|
-
// resurrect a market that is gone. The per-market EVENTS are not
|
|
1827
|
-
// filtered: a delisting is a legitimate event, it is what tells a
|
|
1828
|
-
// legacy subscriber the market went inactive, and dropping it would
|
|
1829
|
-
// change a caller that never opted into any of this.
|
|
1881
|
+
// Both forms carry the cache's full set, delistings it has seen live
|
|
1882
|
+
// included, because that is what a real snapshot is: the server
|
|
1883
|
+
// enumerates inactive markets too, each flagged `isActive: false`.
|
|
1884
|
+
// A consumer wanting the tradable set filters on `isActive`.
|
|
1830
1885
|
if (onSnapshot) {
|
|
1831
1886
|
try {
|
|
1832
|
-
onSnapshot(replay.
|
|
1887
|
+
onSnapshot(replay.map((event) => event.data));
|
|
1833
1888
|
}
|
|
1834
1889
|
catch (err) {
|
|
1835
1890
|
console.error("WebSocket: Error processing instrument baseline replay", err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.80",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://docs.0xmonaco.com/sdk/typescript",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"viem": "^2.45.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@0xmonaco/contracts": "1.0.
|
|
23
|
-
"@0xmonaco/types": "1.0.
|
|
22
|
+
"@0xmonaco/contracts": "1.0.80",
|
|
23
|
+
"@0xmonaco/types": "1.0.80",
|
|
24
24
|
"@noble/curves": "^1.9.1",
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
26
|
"http-status-codes": "^2.3.0"
|