@0xmonaco/core 1.0.77 → 1.0.81
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/api/pitpass/api.d.ts +12 -9
- package/dist/api/pitpass/api.js +12 -9
- package/dist/api/pitpass/index.d.ts +2 -2
- package/dist/api/pitpass/index.js +2 -2
- package/dist/api/positions/api.d.ts +5 -4
- package/dist/api/positions/api.js +5 -4
- package/dist/api/websocket/websocket.js +87 -4
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* TraderCodes API Implementation (`sdk.pitpass`)
|
|
3
3
|
*
|
|
4
|
-
* Provides methods for the
|
|
4
|
+
* Provides methods for the TraderCodes referral program: reading your wallet-derived
|
|
5
5
|
* TraderCode, a public lookup to validate a referral code at sign-up, reading
|
|
6
6
|
* your accrued rewards balance, and transferring rewards into a tradeable balance.
|
|
7
7
|
*
|
|
@@ -69,18 +69,20 @@ export declare class PitpassAPIImpl extends BaseAPI implements PitpassAPI {
|
|
|
69
69
|
*/
|
|
70
70
|
getTraderCodeInfo(code: string): Promise<TraderCodeInfoResponse>;
|
|
71
71
|
/**
|
|
72
|
-
* Return the caller's current
|
|
72
|
+
* Return the caller's current TraderCodes rewards-bucket balances.
|
|
73
73
|
*/
|
|
74
74
|
getRewardsBalance(): Promise<GetRewardsBalanceResponse>;
|
|
75
75
|
/**
|
|
76
|
-
* Transfer earned
|
|
76
|
+
* Transfer earned TraderCodes rewards into a trading balance.
|
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* TraderCodes API Implementation (`sdk.pitpass`)
|
|
3
3
|
*
|
|
4
|
-
* Provides methods for the
|
|
4
|
+
* Provides methods for the TraderCodes referral program: reading your wallet-derived
|
|
5
5
|
* TraderCode, a public lookup to validate a referral code at sign-up, reading
|
|
6
6
|
* your accrued rewards balance, and transferring rewards into a tradeable balance.
|
|
7
7
|
*
|
|
@@ -93,13 +93,13 @@ export class PitpassAPIImpl extends BaseAPI {
|
|
|
93
93
|
return await this.makePublicRequest(`/api/v1/pitpass/codes/${encoded}`, { method: "GET" });
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
* Return the caller's current
|
|
96
|
+
* Return the caller's current TraderCodes rewards-bucket balances.
|
|
97
97
|
*/
|
|
98
98
|
async getRewardsBalance() {
|
|
99
99
|
return await this.makeAuthenticatedRequest("/api/v1/pitpass/rewards/balance", { method: "GET" });
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* Transfer earned
|
|
102
|
+
* Transfer earned TraderCodes rewards into a trading balance.
|
|
103
103
|
*/
|
|
104
104
|
async transferRewards(params) {
|
|
105
105
|
const validated = validate(TransferRewardsParamsSchema, params);
|
|
@@ -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) {
|
|
@@ -256,6 +256,9 @@ function parsePositionEventData(raw) {
|
|
|
256
256
|
// every `>=` comparison, so the server omits the key rather than sending
|
|
257
257
|
// zero.
|
|
258
258
|
version: readOptionalSequence(data, "version"),
|
|
259
|
+
// Lifetime funding since open. Optional: an older deployment does not
|
|
260
|
+
// send it, and the server omits it when it cannot serve the whole value.
|
|
261
|
+
fundingPaid: readOptionalString(data, "fundingPaid"),
|
|
259
262
|
};
|
|
260
263
|
}
|
|
261
264
|
function parsePositionEvent(rawData) {
|
|
@@ -468,6 +471,85 @@ function parseMarketStatsAllEvent(rawData) {
|
|
|
468
471
|
markets: rawData.markets.map(parseMarketStatsSummary),
|
|
469
472
|
};
|
|
470
473
|
}
|
|
474
|
+
function parseRiskTier(raw) {
|
|
475
|
+
if (!isRecord(raw)) {
|
|
476
|
+
throw new Error("Invalid instrument event: each riskTiers entry must be an object");
|
|
477
|
+
}
|
|
478
|
+
const tierLevel = raw.tierLevel;
|
|
479
|
+
if (typeof tierLevel !== "number" || !Number.isSafeInteger(tierLevel) || tierLevel < 1) {
|
|
480
|
+
throw new Error("Invalid WebSocket event: tierLevel must be a positive integer");
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
tierLevel,
|
|
484
|
+
lowerBoundNotional: readString(raw, "lowerBoundNotional"),
|
|
485
|
+
maxLeverage: readOptionalString(raw, "maxLeverage"),
|
|
486
|
+
initialMarginRatio: readString(raw, "initialMarginRatio"),
|
|
487
|
+
maintenanceMarginRatio: readString(raw, "maintenanceMarginRatio"),
|
|
488
|
+
initialMarginDeduction: readString(raw, "initialMarginDeduction"),
|
|
489
|
+
maintenanceMarginDeduction: readString(raw, "maintenanceMarginDeduction"),
|
|
490
|
+
maxPositionNotional: readOptionalString(raw, "maxPositionNotional"),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Read the perp-only margin ladder. Absent (a spot market, or a server that
|
|
495
|
+
* predates the key) is `undefined`, never a made-up empty ladder; a present
|
|
496
|
+
* value that is not an array of well-formed tiers throws like any other
|
|
497
|
+
* malformed field.
|
|
498
|
+
*/
|
|
499
|
+
function readOptionalRiskTiers(source, field) {
|
|
500
|
+
const value = source[field];
|
|
501
|
+
if (value === undefined || value === null)
|
|
502
|
+
return undefined;
|
|
503
|
+
if (!Array.isArray(value)) {
|
|
504
|
+
throw new Error(`Invalid WebSocket event: ${field} must be an array`);
|
|
505
|
+
}
|
|
506
|
+
return value.map(parseRiskTier);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Parse one `trades` snapshot row: the live trade frame's `data` body.
|
|
510
|
+
*
|
|
511
|
+
* Strict, unlike the live trade handler's casts: a snapshot is delivered
|
|
512
|
+
* all-or-nothing, so a row with a missing or non-string field must throw for
|
|
513
|
+
* {@link snapshotFrameHandler} to withhold the frame. The output is the same
|
|
514
|
+
* `TradeEventData` the live handler builds, `makerSide` uppercased likewise.
|
|
515
|
+
*/
|
|
516
|
+
function parseTradeEventData(raw) {
|
|
517
|
+
if (!isRecord(raw)) {
|
|
518
|
+
throw new Error("Invalid trade snapshot row: must be an object");
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
tradeId: readString(raw, "trade_id"),
|
|
522
|
+
price: readString(raw, "price"),
|
|
523
|
+
quantity: readString(raw, "quantity"),
|
|
524
|
+
makerSide: readString(raw, "maker_side").toUpperCase(),
|
|
525
|
+
executedAt: readString(raw, "executed_at"),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Parse one `ohlcv` snapshot row: the live candle frame's `data` body.
|
|
530
|
+
*
|
|
531
|
+
* Strict, unlike the live OHLCV handler's casts: a snapshot is delivered
|
|
532
|
+
* all-or-nothing, so a row with a missing or mistyped field must throw for
|
|
533
|
+
* {@link snapshotFrameHandler} to withhold the frame. The output is the live
|
|
534
|
+
* candlestick minus `s`; `i` is the subscription's interval, since the row
|
|
535
|
+
* carries no envelope.
|
|
536
|
+
*/
|
|
537
|
+
function parseOHLCVSnapshotCandle(raw, interval) {
|
|
538
|
+
if (!isRecord(raw)) {
|
|
539
|
+
throw new Error("Invalid ohlcv snapshot row: must be an object");
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
T: readSequence(raw, "period_start"),
|
|
543
|
+
t: readSequence(raw, "period_end"),
|
|
544
|
+
o: readString(raw, "open"),
|
|
545
|
+
h: readString(raw, "high"),
|
|
546
|
+
l: readString(raw, "low"),
|
|
547
|
+
c: readString(raw, "close"),
|
|
548
|
+
v: readString(raw, "volume"),
|
|
549
|
+
i: interval,
|
|
550
|
+
n: readSequence(raw, "trades_count"),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
471
553
|
function parseInstrumentEventData(raw) {
|
|
472
554
|
if (!isRecord(raw)) {
|
|
473
555
|
throw new Error("Invalid instrument event: data must be an object");
|
|
@@ -514,6 +596,7 @@ function parseInstrumentEventData(raw) {
|
|
|
514
596
|
maxLeverage: readOptionalString(data, "maxLeverage"),
|
|
515
597
|
initialMarginRate: readOptionalString(data, "initialMarginRate"),
|
|
516
598
|
maintenanceMarginRate: readOptionalString(data, "maintenanceMarginRate"),
|
|
599
|
+
riskTiers: readOptionalRiskTiers(data, "riskTiers"),
|
|
517
600
|
// Values are snake_case wire field NAMES (e.g. "tick_size"); only object
|
|
518
601
|
// keys are camelCased, so they pass through untouched.
|
|
519
602
|
changedFields: readStringArray(data, "changedFields"),
|
|
@@ -1413,7 +1496,7 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1413
1496
|
}
|
|
1414
1497
|
});
|
|
1415
1498
|
};
|
|
1416
|
-
const subscribeOHLCV = (tradingPairId, tradingMode, interval, handler, priceType) => {
|
|
1499
|
+
const subscribeOHLCV = (tradingPairId, tradingMode, interval, handler, priceType, onSnapshot) => {
|
|
1417
1500
|
// Four-token channel selects the trade-derived candles (back-compat); the
|
|
1418
1501
|
// optional fifth token selects the price series (`mark` = close-only mark
|
|
1419
1502
|
// series, `*` = both).
|
|
@@ -1459,9 +1542,9 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1459
1542
|
catch (err) {
|
|
1460
1543
|
console.error("WebSocket: Error processing OHLCV event", err);
|
|
1461
1544
|
}
|
|
1462
|
-
});
|
|
1545
|
+
}, onSnapshot && snapshotFrameHandler("ohlcv", (raw) => parseOHLCVSnapshotCandle(raw, interval), onSnapshot));
|
|
1463
1546
|
};
|
|
1464
|
-
const subscribeTrades = (tradingPairId, handler) => {
|
|
1547
|
+
const subscribeTrades = (tradingPairId, handler, onSnapshot) => {
|
|
1465
1548
|
const channel = `trades:${tradingPairId}`;
|
|
1466
1549
|
return subscribe(channel, (rawData) => {
|
|
1467
1550
|
try {
|
|
@@ -1484,7 +1567,7 @@ export function createMonacoWebSocket(baseUrl, options = {}, serverClock = new S
|
|
|
1484
1567
|
catch (err) {
|
|
1485
1568
|
console.error("WebSocket: Error processing trade event", err);
|
|
1486
1569
|
}
|
|
1487
|
-
});
|
|
1570
|
+
}, onSnapshot && snapshotFrameHandler("trades", parseTradeEventData, onSnapshot));
|
|
1488
1571
|
};
|
|
1489
1572
|
const subscribeMovements = (handler) => {
|
|
1490
1573
|
// User is identified from the authenticated session, so channel is just "movements"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.81",
|
|
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.81",
|
|
23
|
+
"@0xmonaco/types": "1.0.81",
|
|
24
24
|
"@noble/curves": "^1.9.1",
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
26
|
"http-status-codes": "^2.3.0"
|