aftermath-ts-sdk 1.3.23-perps.34 → 1.3.23-perps.36
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/general/types/generalTypes.d.ts +4 -0
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.d.ts +177 -262
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetuals.js +185 -256
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +178 -34
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsAccount.js +183 -39
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +116 -140
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsMarket.js +125 -159
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +241 -5
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.d.ts +273 -19
- package/dist/packages/perpetuals/perpetualsVault.d.ts.map +1 -1
- package/dist/packages/perpetuals/perpetualsVault.js +289 -78
- package/package.json +1 -1
|
@@ -34,12 +34,12 @@ const perpetuals_1 = require("./perpetuals");
|
|
|
34
34
|
*
|
|
35
35
|
* ```ts
|
|
36
36
|
* const perps = new Perpetuals(config);
|
|
37
|
-
* const markets = await perps.getMarkets({ marketIds: ["0x..."] });
|
|
38
|
-
* const
|
|
37
|
+
* const { markets } = await perps.getMarkets({ marketIds: ["0x..."] });
|
|
38
|
+
* const market = markets[0];
|
|
39
39
|
*
|
|
40
|
-
* const
|
|
41
|
-
* const stats = await
|
|
42
|
-
* const
|
|
40
|
+
* const { orderbook } = await market.getOrderbook();
|
|
41
|
+
* const stats = await market.get24hrStats();
|
|
42
|
+
* const { basePrice, collateralPrice } = await market.getPrices();
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
class PerpetualsMarket extends caller_1.Caller {
|
|
@@ -51,6 +51,11 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
51
51
|
*
|
|
52
52
|
* @param marketData - Snapshot of market configuration and state.
|
|
53
53
|
* @param config - Optional {@link CallerConfig} (network, base URL, etc.).
|
|
54
|
+
* @param Provider - Optional shared {@link AftermathApi} provider instance.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* This class extends {@link Caller} with the `"perpetuals"` route prefix, meaning
|
|
58
|
+
* all HTTP requests resolve under `/perpetuals/...`.
|
|
54
59
|
*/
|
|
55
60
|
constructor(marketData, config, Provider) {
|
|
56
61
|
super(config, "perpetuals");
|
|
@@ -60,25 +65,24 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
60
65
|
* Compute the maximum order size that can be placed by a given account
|
|
61
66
|
* in this market, under optional leverage and price assumptions.
|
|
62
67
|
*
|
|
63
|
-
* This is
|
|
64
|
-
* -
|
|
65
|
-
* -
|
|
68
|
+
* This is a common frontend helper for:
|
|
69
|
+
* - "max size" buttons
|
|
70
|
+
* - input validation against risk limits
|
|
66
71
|
*
|
|
67
|
-
* **Note:** This
|
|
68
|
-
* account
|
|
72
|
+
* **Note:** This is routed through the `account` namespace because it depends on
|
|
73
|
+
* the account's collateral and positions.
|
|
69
74
|
*
|
|
70
75
|
* @param inputs.accountId - Perpetuals account ID.
|
|
71
76
|
* @param inputs.side - Order side (Bid/Ask).
|
|
72
|
-
* @param inputs.leverage - Optional leverage
|
|
73
|
-
* @param inputs.price - Optional
|
|
74
|
-
* assumption may be used by the backend.
|
|
77
|
+
* @param inputs.leverage - Optional assumed leverage.
|
|
78
|
+
* @param inputs.price - Optional assumed price (e.g. for limit orders).
|
|
75
79
|
*
|
|
76
|
-
* @returns
|
|
80
|
+
* @returns `{ maxOrderSize }` in base units (scaled integer as `bigint`).
|
|
77
81
|
*
|
|
78
82
|
* @example
|
|
79
83
|
* ```ts
|
|
80
84
|
* const { maxOrderSize } = await market.getMaxOrderSize({
|
|
81
|
-
* accountId,
|
|
85
|
+
* accountId: 123n,
|
|
82
86
|
* side: PerpetualsOrderSide.Bid,
|
|
83
87
|
* leverage: 5,
|
|
84
88
|
* });
|
|
@@ -96,15 +100,17 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
96
100
|
});
|
|
97
101
|
});
|
|
98
102
|
// =========================================================================
|
|
99
|
-
//
|
|
100
|
-
//
|
|
103
|
+
// Funding / Timing
|
|
104
|
+
// =========================================================================
|
|
101
105
|
/**
|
|
102
106
|
* Compute the remaining time until the next funding event, in milliseconds.
|
|
103
107
|
*
|
|
104
|
-
* - If the on-chain `nextFundingTimestampMs` exceeds `Number.MAX_SAFE_INTEGER`,
|
|
105
|
-
* this uses `Number.MAX_SAFE_INTEGER` as a cap via {@link nextFundingTimeMs}.
|
|
106
|
-
*
|
|
107
108
|
* @returns `nextFundingTimeMs() - Date.now()`.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* If the next funding timestamp does not fit safely into a JS `number`,
|
|
112
|
+
* {@link nextFundingTimeMs} returns `Number.MAX_SAFE_INTEGER`, and the
|
|
113
|
+
* difference may be very large.
|
|
108
114
|
*/
|
|
109
115
|
this.timeUntilNextFundingMs = () => {
|
|
110
116
|
return this.nextFundingTimeMs() - Date.now();
|
|
@@ -112,9 +118,9 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
112
118
|
/**
|
|
113
119
|
* Get the scheduled timestamp for the next funding event, in milliseconds.
|
|
114
120
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* `Number.MAX_SAFE_INTEGER
|
|
121
|
+
* Safety behavior:
|
|
122
|
+
* - If `marketData.nextFundingTimestampMs` exceeds `Number.MAX_SAFE_INTEGER`,
|
|
123
|
+
* this returns `Number.MAX_SAFE_INTEGER`.
|
|
118
124
|
*
|
|
119
125
|
* @returns Next funding timestamp (ms) as a JS `number`.
|
|
120
126
|
*/
|
|
@@ -127,52 +133,41 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
127
133
|
/**
|
|
128
134
|
* Estimated funding rate per period for this market.
|
|
129
135
|
*
|
|
130
|
-
*
|
|
136
|
+
* This is read directly from `marketData.estimatedFundingRate`.
|
|
131
137
|
*
|
|
132
|
-
*
|
|
133
|
-
* (bookTwap - indexTwap) / indexPrice * (fundingFrequency / fundingPeriod)
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* but here it's read directly from `marketData.estimatedFundingRate`.
|
|
137
|
-
*
|
|
138
|
-
* @returns Estimated funding rate as a fraction (e.g. 0.01 = 1%).
|
|
138
|
+
* @returns Estimated funding rate as a fraction (e.g. `0.01` = 1%).
|
|
139
139
|
*/
|
|
140
|
-
// The funding rate as the difference between book and index TWAPs relative to the index price,
|
|
141
|
-
// scaled by the funding period adjustment:
|
|
142
|
-
// (bookTwap - indexTwap) / indexPrice * (fundingFrequency / fundingPeriod)
|
|
143
140
|
this.estimatedFundingRate = () => {
|
|
144
141
|
return this.marketData.estimatedFundingRate;
|
|
145
142
|
};
|
|
143
|
+
// =========================================================================
|
|
144
|
+
// Margin / Collateral Calculations
|
|
145
|
+
// =========================================================================
|
|
146
146
|
/**
|
|
147
|
-
* Calculate the collateral required to support an order given leverage
|
|
148
|
-
* and prices.
|
|
147
|
+
* Calculate the collateral required to support an order given leverage and prices.
|
|
149
148
|
*
|
|
150
|
-
* The
|
|
149
|
+
* The computed collateral is based on the *remaining* unfilled size:
|
|
150
|
+
* `remaining = initialSize - filledSize`.
|
|
151
151
|
*
|
|
152
|
+
* USD requirement:
|
|
152
153
|
* ```text
|
|
153
|
-
*
|
|
154
|
+
* remainingBase * indexPrice * initialMarginRatio
|
|
154
155
|
* ```
|
|
156
|
+
* where `initialMarginRatio = 1 / leverage` (or 1 if leverage is falsy).
|
|
155
157
|
*
|
|
156
|
-
*
|
|
157
|
-
* - `remainingSizeBase` = `(initialSize - filledSize) / fixedOneN9`
|
|
158
|
-
* - `initialMarginRatio` = `1 / leverage` (or 1 if leverage is falsy).
|
|
159
|
-
*
|
|
160
|
-
* @param inputs.leverage - Target leverage for the order.
|
|
158
|
+
* @param inputs.leverage - Target leverage for the order (>= 1).
|
|
161
159
|
* @param inputs.orderData - Order data containing `initialSize` and `filledSize`.
|
|
162
|
-
* @param inputs.indexPrice -
|
|
163
|
-
* @param inputs.collateralPrice - Price of the collateral asset
|
|
160
|
+
* @param inputs.indexPrice - Index/oracle price of the base asset.
|
|
161
|
+
* @param inputs.collateralPrice - Price of the collateral asset.
|
|
164
162
|
*
|
|
165
163
|
* @returns Object with:
|
|
166
|
-
* - `collateralUsd`: required collateral in USD
|
|
167
|
-
* - `collateral`: required collateral in collateral
|
|
164
|
+
* - `collateralUsd`: required collateral in USD
|
|
165
|
+
* - `collateral`: required collateral in collateral coin units
|
|
168
166
|
*/
|
|
169
167
|
this.calcCollateralUsedForOrder = (inputs) => {
|
|
170
168
|
const { leverage, orderData, indexPrice, collateralPrice } = inputs;
|
|
171
169
|
const imr = 1 / (leverage || 1);
|
|
172
|
-
|
|
173
|
-
const collateralUsd =
|
|
174
|
-
// NOTE: is this safe ?
|
|
175
|
-
(Number(orderData.initialSize - orderData.filledSize) /
|
|
170
|
+
const collateralUsd = (Number(orderData.initialSize - orderData.filledSize) /
|
|
176
171
|
__1.Casting.Fixed.fixedOneN9) *
|
|
177
172
|
indexPrice *
|
|
178
173
|
imr;
|
|
@@ -188,18 +183,15 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
188
183
|
/**
|
|
189
184
|
* Round a price to the nearest valid tick for this market.
|
|
190
185
|
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* If neither `floor` nor `ceil` are set, this uses `Math.round`.
|
|
196
|
-
*
|
|
197
|
-
* @returns Price snapped to a valid tick.
|
|
186
|
+
* Rounding mode:
|
|
187
|
+
* - `floor: true` => round down
|
|
188
|
+
* - `ceil: true` => round up
|
|
189
|
+
* - neither => nearest tick (`Math.round`)
|
|
198
190
|
*
|
|
199
|
-
* @
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
191
|
+
* @param inputs.price - Raw price to round.
|
|
192
|
+
* @param inputs.floor - Force floor rounding.
|
|
193
|
+
* @param inputs.ceil - Force ceil rounding.
|
|
194
|
+
* @returns Price snapped to the market tick size.
|
|
203
195
|
*/
|
|
204
196
|
this.roundToValidPrice = (inputs) => {
|
|
205
197
|
const ticks = inputs.price / this.tickSize();
|
|
@@ -210,20 +202,18 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
210
202
|
: Math.round(ticks)) * this.tickSize());
|
|
211
203
|
};
|
|
212
204
|
/**
|
|
213
|
-
* Round a price to the nearest valid tick
|
|
214
|
-
* a `bigint` scaled by `Fixed.fixedOneN9`.
|
|
205
|
+
* Round a price to the nearest valid tick as a fixed-point `bigint` (1e9 precision).
|
|
215
206
|
*
|
|
216
|
-
* This is
|
|
207
|
+
* This is helpful when you need the on-chain representation directly
|
|
208
|
+
* (e.g. order price fields stored in 9-decimal fixed).
|
|
217
209
|
*
|
|
218
210
|
* @param inputs.price - Raw price as a JS number.
|
|
219
|
-
* @param inputs.floor -
|
|
220
|
-
* @param inputs.ceil -
|
|
221
|
-
*
|
|
222
|
-
* @returns Price scaled by `1e9` and snapped to a valid tick as a `bigint`.
|
|
211
|
+
* @param inputs.floor - Force floor rounding.
|
|
212
|
+
* @param inputs.ceil - Force ceil rounding.
|
|
213
|
+
* @returns Tick-snapped price scaled by `1e9`.
|
|
223
214
|
*/
|
|
224
215
|
this.roundToValidPriceBigInt = (inputs) => {
|
|
225
216
|
const scaledPrice = Number(inputs.price * __1.Casting.Fixed.fixedOneN9);
|
|
226
|
-
// TODO: make sure this calc is safe
|
|
227
217
|
return ((BigInt(inputs.floor
|
|
228
218
|
? Math.floor(scaledPrice)
|
|
229
219
|
: inputs.ceil
|
|
@@ -235,11 +225,15 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
235
225
|
/**
|
|
236
226
|
* Round a base-asset size to the nearest valid lot size for this market.
|
|
237
227
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
228
|
+
* Rounding mode:
|
|
229
|
+
* - `floor: true` => round down
|
|
230
|
+
* - `ceil: true` => round up
|
|
231
|
+
* - neither => nearest lot (`Math.round`)
|
|
241
232
|
*
|
|
242
|
-
* @
|
|
233
|
+
* @param inputs.size - Raw size in base asset units.
|
|
234
|
+
* @param inputs.floor - Force floor rounding.
|
|
235
|
+
* @param inputs.ceil - Force ceil rounding.
|
|
236
|
+
* @returns Size snapped to the market lot size.
|
|
243
237
|
*/
|
|
244
238
|
this.roundToValidSize = (inputs) => {
|
|
245
239
|
const lots = inputs.size / this.lotSize();
|
|
@@ -250,18 +244,15 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
250
244
|
: Math.round(lots)) * this.lotSize());
|
|
251
245
|
};
|
|
252
246
|
/**
|
|
253
|
-
* Round a base-asset size to the nearest valid lot
|
|
254
|
-
* as a scaled `bigint` (`Fixed.fixedOneN9`).
|
|
247
|
+
* Round a base-asset size to the nearest valid lot as a fixed-point `bigint` (1e9 precision).
|
|
255
248
|
*
|
|
256
|
-
* @param inputs.size - Raw size
|
|
257
|
-
* @param inputs.floor -
|
|
258
|
-
* @param inputs.ceil -
|
|
259
|
-
*
|
|
260
|
-
* @returns Size scaled by `1e9` and snapped to valid lot as a `bigint`.
|
|
249
|
+
* @param inputs.size - Raw base size as a JS number.
|
|
250
|
+
* @param inputs.floor - Force floor rounding.
|
|
251
|
+
* @param inputs.ceil - Force ceil rounding.
|
|
252
|
+
* @returns Lot-snapped size scaled by `1e9`.
|
|
261
253
|
*/
|
|
262
254
|
this.roundToValidSizeBigInt = (inputs) => {
|
|
263
255
|
const scaledSize = Number(inputs.size * __1.Casting.Fixed.fixedOneN9);
|
|
264
|
-
// TODO: make sure this calc is safe
|
|
265
256
|
return ((BigInt(inputs.floor
|
|
266
257
|
? Math.floor(scaledSize)
|
|
267
258
|
: inputs.ceil
|
|
@@ -273,16 +264,14 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
273
264
|
/**
|
|
274
265
|
* Construct an "empty" position object for this market.
|
|
275
266
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* object with defaulted values.
|
|
267
|
+
* Useful when an account has no open position but downstream UI/calculations
|
|
268
|
+
* expect a {@link PerpetualsPosition}-shaped object.
|
|
279
269
|
*
|
|
280
270
|
* @returns A zeroed-out {@link PerpetualsPosition} for `this.marketId`.
|
|
281
271
|
*/
|
|
282
272
|
this.emptyPosition = () => {
|
|
283
273
|
return {
|
|
284
274
|
marketId: this.marketId,
|
|
285
|
-
// collateralCoinType: this.marketData.collateralCoinType,
|
|
286
275
|
collateral: 0,
|
|
287
276
|
collateralUsd: 0,
|
|
288
277
|
baseAssetAmount: 0,
|
|
@@ -292,8 +281,8 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
292
281
|
asksQuantity: 0,
|
|
293
282
|
bidsQuantity: 0,
|
|
294
283
|
pendingOrders: [],
|
|
295
|
-
makerFee: 1, // 100%
|
|
296
|
-
takerFee: 1, // 100%
|
|
284
|
+
makerFee: 1, // 100% (placeholder default)
|
|
285
|
+
takerFee: 1, // 100% (placeholder default)
|
|
297
286
|
leverage: 1,
|
|
298
287
|
entryPrice: 0,
|
|
299
288
|
freeCollateral: 0,
|
|
@@ -318,11 +307,10 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
318
307
|
* Fetch the mid price for this market’s orderbook.
|
|
319
308
|
*
|
|
320
309
|
* This is a convenience endpoint that returns only:
|
|
310
|
+
* - `midPrice`: midpoint between best bid and best ask, or `undefined`
|
|
311
|
+
* if the orderbook is empty or unavailable.
|
|
321
312
|
*
|
|
322
|
-
*
|
|
323
|
-
* if the orderbook is empty or malformed.
|
|
324
|
-
*
|
|
325
|
-
* @returns A promise resolving to `{ midPrice }`.
|
|
313
|
+
* @returns `{ midPrice }`.
|
|
326
314
|
*
|
|
327
315
|
* @example
|
|
328
316
|
* ```ts
|
|
@@ -339,15 +327,14 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
339
327
|
* Fetch the 24-hour statistics for this specific market.
|
|
340
328
|
*
|
|
341
329
|
* Under the hood, this calls {@link Perpetuals.getMarkets24hrStats} and
|
|
342
|
-
* returns the first (and only) entry
|
|
330
|
+
* returns the first (and only) entry.
|
|
343
331
|
*
|
|
344
|
-
* @returns {@link PerpetualsMarket24hrStats}
|
|
332
|
+
* @returns {@link PerpetualsMarket24hrStats}.
|
|
345
333
|
*
|
|
346
|
-
* @
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* ```
|
|
334
|
+
* @remarks
|
|
335
|
+
* This method creates a new {@link Perpetuals} instance using `this.config`.
|
|
336
|
+
* If you need shared Provider behavior, prefer calling `perps.getMarkets24hrStats`
|
|
337
|
+
* directly with the same Provider you initialized.
|
|
351
338
|
*/
|
|
352
339
|
get24hrStats() {
|
|
353
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -360,22 +347,20 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
360
347
|
/**
|
|
361
348
|
* Fetch the full orderbook snapshot for this market.
|
|
362
349
|
*
|
|
363
|
-
*
|
|
364
|
-
* - `
|
|
365
|
-
* - `
|
|
350
|
+
* Implementation note:
|
|
351
|
+
* - Currently implemented via the generic `markets` endpoint with `withOrderbook: true`
|
|
352
|
+
* - The backend returns `marketDatas[]` which include both `market` and `orderbook`
|
|
366
353
|
*
|
|
367
|
-
* @returns
|
|
354
|
+
* @returns Object containing `orderbook`.
|
|
368
355
|
*
|
|
369
356
|
* @example
|
|
370
357
|
* ```ts
|
|
371
|
-
* const
|
|
372
|
-
* console.log(
|
|
358
|
+
* const { orderbook } = await market.getOrderbook();
|
|
359
|
+
* console.log(orderbook.bids[0], orderbook.asks[0]);
|
|
373
360
|
* ```
|
|
374
361
|
*/
|
|
375
362
|
getOrderbook() {
|
|
376
363
|
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
-
// TODO: create own endpoint for just orderbook
|
|
378
|
-
// return this.fetchApi<PerpetualsOrderbook>("market/orderbook");
|
|
379
364
|
const { marketDatas } = yield this.fetchApi("markets", {
|
|
380
365
|
marketIds: [this.marketId],
|
|
381
366
|
withOrderbook: true,
|
|
@@ -388,24 +373,16 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
388
373
|
/**
|
|
389
374
|
* Market-level preview of placing a market order.
|
|
390
375
|
*
|
|
391
|
-
* Unlike
|
|
392
|
-
*
|
|
393
|
-
* -
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
* @param
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* - `{ error }`, or
|
|
402
|
-
* - A preview with:
|
|
403
|
-
* - `updatedPosition`
|
|
404
|
-
* - `priceSlippage` / `percentSlippage`
|
|
405
|
-
* - `filledSize` / `filledSizeUsd`
|
|
406
|
-
* - `postedSize` / `postedSizeUsd`
|
|
407
|
-
* - `collateralChange`
|
|
408
|
-
* - `executionPrice`
|
|
376
|
+
* Unlike {@link PerpetualsAccount.getPlaceMarketOrderPreview}, this version:
|
|
377
|
+
* - Calls `account/previews/place-market-order`
|
|
378
|
+
* - Explicitly sets `accountId: undefined`, allowing a “generic” preview that
|
|
379
|
+
* doesn’t rely on a specific account’s on-chain positions/collateral.
|
|
380
|
+
*
|
|
381
|
+
* @param inputs - {@link SdkPerpetualsPlaceMarketOrderPreviewInputs}.
|
|
382
|
+
* @param abortSignal - Optional abort signal to cancel the request.
|
|
383
|
+
*
|
|
384
|
+
* @returns Either `{ error }` or a preview containing the simulated updated position,
|
|
385
|
+
* slippage, filled/posted sizes, collateral change, and execution price.
|
|
409
386
|
*/
|
|
410
387
|
getPlaceMarketOrderPreview(inputs, abortSignal) {
|
|
411
388
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -419,12 +396,10 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
419
396
|
* - `account/previews/place-limit-order`
|
|
420
397
|
* - `accountId: undefined`
|
|
421
398
|
*
|
|
422
|
-
* @param inputs -
|
|
423
|
-
* @param abortSignal - Optional
|
|
399
|
+
* @param inputs - {@link SdkPerpetualsPlaceLimitOrderPreviewInputs}.
|
|
400
|
+
* @param abortSignal - Optional abort signal to cancel the request.
|
|
424
401
|
*
|
|
425
|
-
* @returns Either
|
|
426
|
-
* - `{ error }`, or
|
|
427
|
-
* - A preview object with post-order position, slippage, and collateral changes.
|
|
402
|
+
* @returns Either `{ error }` or a preview describing the simulated post-order state.
|
|
428
403
|
*/
|
|
429
404
|
getPlaceLimitOrderPreview(inputs, abortSignal) {
|
|
430
405
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -437,20 +412,14 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
437
412
|
/**
|
|
438
413
|
* Fetch paginated order history for this market.
|
|
439
414
|
*
|
|
440
|
-
* This
|
|
441
|
-
* for charting, recent orders lists, etc.
|
|
442
|
-
*
|
|
443
|
-
* @param inputs.cursor - Optional pagination cursor.
|
|
444
|
-
* @param inputs.limit - Optional number of orders per page.
|
|
415
|
+
* This is market-wide (public) history, not scoped to any account.
|
|
445
416
|
*
|
|
446
|
-
* @
|
|
447
|
-
*
|
|
417
|
+
* @param inputs.beforeTimestampCursor - Optional pagination cursor.
|
|
418
|
+
* @param inputs.limit - Optional page size.
|
|
448
419
|
*
|
|
449
|
-
* @
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* console.log(result.orders.length, result.nextBeforeTimestampCursor);
|
|
453
|
-
* ```
|
|
420
|
+
* @returns {@link ApiPerpetualsMarketOrderHistoryResponse} containing:
|
|
421
|
+
* - `orders`
|
|
422
|
+
* - `nextBeforeTimestampCursor`
|
|
454
423
|
*/
|
|
455
424
|
getOrderHistory(inputs) {
|
|
456
425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -463,21 +432,17 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
463
432
|
/**
|
|
464
433
|
* Fetch the current base and collateral prices for this market.
|
|
465
434
|
*
|
|
466
|
-
* Internally calls {@link Perpetuals.getPrices} and returns the first
|
|
467
|
-
* element corresponding to `this.marketId`.
|
|
435
|
+
* Internally calls {@link Perpetuals.getPrices} and returns the first result.
|
|
468
436
|
*
|
|
469
|
-
* @returns `{ basePrice, collateralPrice }
|
|
437
|
+
* @returns `{ basePrice, collateralPrice }`.
|
|
470
438
|
*
|
|
471
|
-
* @
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* ```
|
|
439
|
+
* @remarks
|
|
440
|
+
* This method instantiates a new {@link Perpetuals} client using `this.config`.
|
|
441
|
+
* If you rely on a shared Provider, call `perps.getPrices(...)` directly instead.
|
|
475
442
|
*/
|
|
476
443
|
getPrices() {
|
|
477
444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
478
|
-
return (yield new perpetuals_1.Perpetuals(this.config
|
|
479
|
-
// this.Provider
|
|
480
|
-
).getPrices({
|
|
445
|
+
return (yield new perpetuals_1.Perpetuals(this.config).getPrices({
|
|
481
446
|
marketIds: [this.marketId],
|
|
482
447
|
})).marketsPrices[0];
|
|
483
448
|
});
|
|
@@ -486,9 +451,9 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
486
451
|
// Value Conversions
|
|
487
452
|
// =========================================================================
|
|
488
453
|
/**
|
|
489
|
-
* Get the base
|
|
454
|
+
* Get the base-asset lot size for this market as a `number`.
|
|
490
455
|
*
|
|
491
|
-
* Order sizes must be
|
|
456
|
+
* Order sizes must be multiples of this lot size.
|
|
492
457
|
*
|
|
493
458
|
* @returns Lot size in base asset units.
|
|
494
459
|
*/
|
|
@@ -496,9 +461,9 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
496
461
|
return perpetuals_1.Perpetuals.lotOrTickSizeToNumber(this.marketParams.lotSize);
|
|
497
462
|
}
|
|
498
463
|
/**
|
|
499
|
-
* Get the minimal price tick for this market as a `number`.
|
|
464
|
+
* Get the minimal price tick size for this market as a `number`.
|
|
500
465
|
*
|
|
501
|
-
* Limit prices must be
|
|
466
|
+
* Limit prices must be multiples of this tick size.
|
|
502
467
|
*
|
|
503
468
|
* @returns Tick size in quote units (e.g. USD).
|
|
504
469
|
*/
|
|
@@ -506,13 +471,14 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
506
471
|
return perpetuals_1.Perpetuals.lotOrTickSizeToNumber(this.marketParams.tickSize);
|
|
507
472
|
}
|
|
508
473
|
/**
|
|
509
|
-
* Get the maximum theoretical leverage for this market
|
|
474
|
+
* Get the maximum theoretical leverage for this market.
|
|
510
475
|
*
|
|
476
|
+
* Computed as:
|
|
511
477
|
* ```ts
|
|
512
478
|
* 1 / marginRatioInitial
|
|
513
479
|
* ```
|
|
514
480
|
*
|
|
515
|
-
* @returns Maximum leverage
|
|
481
|
+
* @returns Maximum leverage.
|
|
516
482
|
*/
|
|
517
483
|
maxLeverage() {
|
|
518
484
|
return 1 / this.marketParams.marginRatioInitial;
|
|
@@ -530,7 +496,7 @@ class PerpetualsMarket extends caller_1.Caller {
|
|
|
530
496
|
/**
|
|
531
497
|
* Get the maintenance margin ratio for this market.
|
|
532
498
|
*
|
|
533
|
-
* Falling below this ratio may
|
|
499
|
+
* Falling below this ratio may trigger liquidation.
|
|
534
500
|
*
|
|
535
501
|
* @returns Maintenance margin ratio as a fraction.
|
|
536
502
|
*/
|