@orderly.network/perp 1.0.28 → 2.0.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/index.d.mts +103 -33
- package/dist/index.d.ts +103 -33
- package/dist/index.js +106 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ declare global {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
declare const _default: "
|
|
11
|
+
declare const _default: "2.0.0";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Calculates the notional value of a single position.
|
|
@@ -24,7 +24,7 @@ declare function notional(qty: number, mark_price: number): number;
|
|
|
24
24
|
* @link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Notional
|
|
25
25
|
*/
|
|
26
26
|
declare function totalNotional(positions: API.Position[]): number;
|
|
27
|
-
|
|
27
|
+
type UnrealPnLInputs = {
|
|
28
28
|
markPrice: number;
|
|
29
29
|
openPrice: number;
|
|
30
30
|
qty: number;
|
|
@@ -35,7 +35,7 @@ declare type UnrealPnLInputs = {
|
|
|
35
35
|
* @returns The unrealized profit or loss of the position.
|
|
36
36
|
*/
|
|
37
37
|
declare function unrealizedPnL(inputs: UnrealPnLInputs): number;
|
|
38
|
-
|
|
38
|
+
type UnrealPnLROIInputs = {
|
|
39
39
|
positionQty: number;
|
|
40
40
|
openPrice: number;
|
|
41
41
|
IMR: number;
|
|
@@ -53,10 +53,11 @@ declare function unrealizedPnLROI(inputs: UnrealPnLROIInputs): number;
|
|
|
53
53
|
* @returns The total unrealized profit or loss of all positions.
|
|
54
54
|
*/
|
|
55
55
|
declare function totalUnrealizedPnL(positions: API.Position[]): number;
|
|
56
|
-
|
|
56
|
+
type LiqPriceInputs = {
|
|
57
57
|
markPrice: number;
|
|
58
58
|
totalCollateral: number;
|
|
59
59
|
positionQty: number;
|
|
60
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "mmr">[];
|
|
60
61
|
MMR: number;
|
|
61
62
|
};
|
|
62
63
|
/**
|
|
@@ -66,7 +67,7 @@ declare type LiqPriceInputs = {
|
|
|
66
67
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Position-Liq.-Price}
|
|
67
68
|
*/
|
|
68
69
|
declare function liqPrice(inputs: LiqPriceInputs): number;
|
|
69
|
-
|
|
70
|
+
type MMInputs = {
|
|
70
71
|
positionQty: number;
|
|
71
72
|
markPrice: number;
|
|
72
73
|
MMR: number;
|
|
@@ -77,7 +78,7 @@ declare type MMInputs = {
|
|
|
77
78
|
* @returns The maintenance margin of the position.
|
|
78
79
|
*/
|
|
79
80
|
declare function maintenanceMargin(inputs: MMInputs): number;
|
|
80
|
-
|
|
81
|
+
type UnsettlementPnLInputs = {
|
|
81
82
|
positionQty: number;
|
|
82
83
|
markPrice: number;
|
|
83
84
|
costPosition: number;
|
|
@@ -91,7 +92,7 @@ declare type UnsettlementPnLInputs = {
|
|
|
91
92
|
* @link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Unsettlement-PNL-%5BinlineExtension%5D
|
|
92
93
|
*/
|
|
93
94
|
declare function unsettlementPnL(inputs: UnsettlementPnLInputs): number;
|
|
94
|
-
|
|
95
|
+
type TotalUnsettlementPnLInputs = {
|
|
95
96
|
positions: (API.Position & {
|
|
96
97
|
sum_unitary_funding: number;
|
|
97
98
|
})[];
|
|
@@ -106,22 +107,23 @@ declare type TotalUnsettlementPnLInputs = {
|
|
|
106
107
|
declare function totalUnsettlementPnL(positions: (API.Position & {
|
|
107
108
|
sum_unitary_funding: number;
|
|
108
109
|
})[]): number;
|
|
109
|
-
|
|
110
|
-
* Calculates the maintenance margin requirement (MMR) of a position.
|
|
111
|
-
* @param inputs The inputs for calculating the MMR.
|
|
112
|
-
* @returns The MMR of the position.
|
|
113
|
-
*/
|
|
114
|
-
declare function MMR(inputs: {
|
|
110
|
+
type MMRInputs = {
|
|
115
111
|
baseMMR: number;
|
|
116
112
|
baseIMR: number;
|
|
117
113
|
IMRFactor: number;
|
|
118
114
|
positionNotional: number;
|
|
119
115
|
IMR_factor_power: number;
|
|
120
|
-
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Calculates the maintenance margin requirement (MMR) of a position.
|
|
119
|
+
* @param inputs The inputs for calculating the MMR.
|
|
120
|
+
* @returns The MMR of the position.
|
|
121
|
+
*/
|
|
122
|
+
declare function MMR$1(inputs: MMRInputs): number;
|
|
121
123
|
|
|
122
124
|
type positions_LiqPriceInputs = LiqPriceInputs;
|
|
123
125
|
type positions_MMInputs = MMInputs;
|
|
124
|
-
|
|
126
|
+
type positions_MMRInputs = MMRInputs;
|
|
125
127
|
type positions_TotalUnsettlementPnLInputs = TotalUnsettlementPnLInputs;
|
|
126
128
|
type positions_UnrealPnLInputs = UnrealPnLInputs;
|
|
127
129
|
type positions_UnrealPnLROIInputs = UnrealPnLROIInputs;
|
|
@@ -139,7 +141,8 @@ declare namespace positions {
|
|
|
139
141
|
export {
|
|
140
142
|
positions_LiqPriceInputs as LiqPriceInputs,
|
|
141
143
|
positions_MMInputs as MMInputs,
|
|
142
|
-
|
|
144
|
+
MMR$1 as MMR,
|
|
145
|
+
positions_MMRInputs as MMRInputs,
|
|
143
146
|
positions_TotalUnsettlementPnLInputs as TotalUnsettlementPnLInputs,
|
|
144
147
|
positions_UnrealPnLInputs as UnrealPnLInputs,
|
|
145
148
|
positions_UnrealPnLROIInputs as UnrealPnLROIInputs,
|
|
@@ -156,10 +159,10 @@ declare namespace positions {
|
|
|
156
159
|
};
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
|
|
162
|
+
type ResultOptions = {
|
|
160
163
|
dp: number;
|
|
161
164
|
};
|
|
162
|
-
|
|
165
|
+
type TotalValueInputs = {
|
|
163
166
|
totalUnsettlementPnL: number;
|
|
164
167
|
USDCHolding: number;
|
|
165
168
|
nonUSDCHolding: {
|
|
@@ -178,7 +181,7 @@ declare function totalValue(inputs: TotalValueInputs): Decimal;
|
|
|
178
181
|
*
|
|
179
182
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Free-collateral}
|
|
180
183
|
*/
|
|
181
|
-
|
|
184
|
+
type FreeCollateralInputs = {
|
|
182
185
|
totalCollateral: Decimal;
|
|
183
186
|
totalInitialMarginWithOrders: number;
|
|
184
187
|
};
|
|
@@ -186,7 +189,7 @@ declare type FreeCollateralInputs = {
|
|
|
186
189
|
* 计算可用保证金
|
|
187
190
|
*/
|
|
188
191
|
declare function freeCollateral(inputs: FreeCollateralInputs): Decimal;
|
|
189
|
-
|
|
192
|
+
type TotalCollateralValueInputs = {
|
|
190
193
|
USDCHolding: number;
|
|
191
194
|
nonUSDCHolding: {
|
|
192
195
|
holding: number;
|
|
@@ -201,7 +204,7 @@ declare type TotalCollateralValueInputs = {
|
|
|
201
204
|
*/
|
|
202
205
|
declare function totalCollateral(inputs: TotalCollateralValueInputs): Decimal;
|
|
203
206
|
declare function initialMarginWithOrder(): void;
|
|
204
|
-
|
|
207
|
+
type PositionNotionalWithOrderInputs = {
|
|
205
208
|
markPrice: number;
|
|
206
209
|
positionQtyWithOrders: number;
|
|
207
210
|
};
|
|
@@ -209,7 +212,7 @@ declare type PositionNotionalWithOrderInputs = {
|
|
|
209
212
|
* 單一 Symbol position / orders notional 加總
|
|
210
213
|
*/
|
|
211
214
|
declare function positionNotionalWithOrder_by_symbol(inputs: PositionNotionalWithOrderInputs): Decimal;
|
|
212
|
-
|
|
215
|
+
type PositionQtyWithOrderInputs = {
|
|
213
216
|
positionQty: number;
|
|
214
217
|
buyOrdersQty: number;
|
|
215
218
|
sellOrdersQty: number;
|
|
@@ -218,7 +221,7 @@ declare type PositionQtyWithOrderInputs = {
|
|
|
218
221
|
* 單一 Symbol position / orders qty 加總
|
|
219
222
|
*/
|
|
220
223
|
declare function positionQtyWithOrders_by_symbol(inputs: PositionQtyWithOrderInputs): number;
|
|
221
|
-
|
|
224
|
+
type IMRInputs = {
|
|
222
225
|
maxLeverage: number;
|
|
223
226
|
baseIMR: number;
|
|
224
227
|
IMR_Factor: number;
|
|
@@ -247,7 +250,7 @@ declare function getPositonsAndOrdersNotionalBySymbol(inputs: {
|
|
|
247
250
|
symbol: string;
|
|
248
251
|
markPrice: number;
|
|
249
252
|
}): number;
|
|
250
|
-
|
|
253
|
+
type TotalInitialMarginWithOrdersInputs = {
|
|
251
254
|
positions: API.Position[];
|
|
252
255
|
orders: API.Order[];
|
|
253
256
|
markPrices: {
|
|
@@ -275,7 +278,7 @@ declare function groupOrdersBySymbol(orders: API.Order[]): {
|
|
|
275
278
|
* @returns An array of unique symbols.
|
|
276
279
|
*/
|
|
277
280
|
declare function extractSymbols(positions: Pick<API.Position, "symbol">[], orders: Pick<API.Order, "symbol">[]): string[];
|
|
278
|
-
|
|
281
|
+
type OtherIMsInputs = {
|
|
279
282
|
positions: API.Position[];
|
|
280
283
|
orders: API.Order[];
|
|
281
284
|
markPrices: {
|
|
@@ -291,7 +294,7 @@ declare type OtherIMsInputs = {
|
|
|
291
294
|
* 除当前symbol外的其他symbol已占用的总保证金
|
|
292
295
|
*/
|
|
293
296
|
declare function otherIMs(inputs: OtherIMsInputs): number;
|
|
294
|
-
|
|
297
|
+
type MaxQtyInputs = {
|
|
295
298
|
symbol: string;
|
|
296
299
|
baseMaxQty: number;
|
|
297
300
|
/**
|
|
@@ -317,9 +320,9 @@ declare type MaxQtyInputs = {
|
|
|
317
320
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Max-Order-QTY}
|
|
318
321
|
*/
|
|
319
322
|
declare function maxQty(side: OrderSide, inputs: MaxQtyInputs, options?: ResultOptions): number;
|
|
320
|
-
declare function maxQtyByLong(inputs: Omit<MaxQtyInputs, "side"
|
|
321
|
-
declare function maxQtyByShort(inputs: Omit<MaxQtyInputs, "side"
|
|
322
|
-
|
|
323
|
+
declare function maxQtyByLong(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
324
|
+
declare function maxQtyByShort(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
325
|
+
type TotalMarginRatioInputs = {
|
|
323
326
|
totalCollateral: number;
|
|
324
327
|
markPrices: {
|
|
325
328
|
[key: string]: number;
|
|
@@ -330,7 +333,7 @@ declare type TotalMarginRatioInputs = {
|
|
|
330
333
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Margin-Ratio}
|
|
331
334
|
*/
|
|
332
335
|
declare function totalMarginRatio(inputs: TotalMarginRatioInputs, dp?: number): number;
|
|
333
|
-
|
|
336
|
+
type TotalUnrealizedROIInputs = {
|
|
334
337
|
totalUnrealizedPnL: number;
|
|
335
338
|
totalValue: number;
|
|
336
339
|
};
|
|
@@ -343,16 +346,32 @@ declare function totalUnrealizedROI(inputs: TotalUnrealizedROIInputs): number;
|
|
|
343
346
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Current-account-leverage}
|
|
344
347
|
*/
|
|
345
348
|
declare function currentLeverage(totalMarginRatio: number): number;
|
|
346
|
-
|
|
349
|
+
type AvailableBalanceInputs = {
|
|
347
350
|
USDCHolding: number;
|
|
348
351
|
unsettlementPnL: number;
|
|
349
352
|
};
|
|
350
353
|
declare function availableBalance(inputs: AvailableBalanceInputs): number;
|
|
354
|
+
type AccountMMRInputs = {
|
|
355
|
+
positionsMMR: number;
|
|
356
|
+
/**
|
|
357
|
+
* Notional sum of all positions,
|
|
358
|
+
* positions.totalNotional()
|
|
359
|
+
*/
|
|
360
|
+
positionsNotional: number;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* total maintenance margin ratio
|
|
364
|
+
* @param inputs AccountMMRInputs
|
|
365
|
+
* @returns number|null
|
|
366
|
+
*/
|
|
367
|
+
declare function MMR(inputs: AccountMMRInputs): number | null;
|
|
351
368
|
|
|
369
|
+
type account_AccountMMRInputs = AccountMMRInputs;
|
|
352
370
|
type account_AvailableBalanceInputs = AvailableBalanceInputs;
|
|
353
371
|
type account_FreeCollateralInputs = FreeCollateralInputs;
|
|
354
372
|
declare const account_IMR: typeof IMR;
|
|
355
373
|
type account_IMRInputs = IMRInputs;
|
|
374
|
+
declare const account_MMR: typeof MMR;
|
|
356
375
|
type account_MaxQtyInputs = MaxQtyInputs;
|
|
357
376
|
type account_OtherIMsInputs = OtherIMsInputs;
|
|
358
377
|
type account_PositionNotionalWithOrderInputs = PositionNotionalWithOrderInputs;
|
|
@@ -387,10 +406,12 @@ declare const account_totalUnrealizedROI: typeof totalUnrealizedROI;
|
|
|
387
406
|
declare const account_totalValue: typeof totalValue;
|
|
388
407
|
declare namespace account {
|
|
389
408
|
export {
|
|
409
|
+
account_AccountMMRInputs as AccountMMRInputs,
|
|
390
410
|
account_AvailableBalanceInputs as AvailableBalanceInputs,
|
|
391
411
|
account_FreeCollateralInputs as FreeCollateralInputs,
|
|
392
412
|
account_IMR as IMR,
|
|
393
413
|
account_IMRInputs as IMRInputs,
|
|
414
|
+
account_MMR as MMR,
|
|
394
415
|
account_MaxQtyInputs as MaxQtyInputs,
|
|
395
416
|
account_OtherIMsInputs as OtherIMsInputs,
|
|
396
417
|
account_PositionNotionalWithOrderInputs as PositionNotionalWithOrderInputs,
|
|
@@ -427,22 +448,71 @@ declare namespace account {
|
|
|
427
448
|
}
|
|
428
449
|
|
|
429
450
|
/**
|
|
430
|
-
*
|
|
451
|
+
* Maximum price when placing an order
|
|
431
452
|
* @see https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Max-price
|
|
432
453
|
*/
|
|
433
454
|
declare function maxPrice(markprice: number, range: number): number;
|
|
434
455
|
/**
|
|
435
|
-
*
|
|
456
|
+
* Minimum price when placing an order
|
|
436
457
|
* @see https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Min-price
|
|
437
458
|
*/
|
|
438
459
|
declare function minPrice(markprice: number, range: number): number;
|
|
460
|
+
/**
|
|
461
|
+
* Scrope price when placing an order
|
|
462
|
+
* @returns number
|
|
463
|
+
*/
|
|
464
|
+
declare function scropePrice(price: number, scrope: number, side: "BUY" | "SELL"): number;
|
|
465
|
+
type EstimatedLiquidationPriceInputs = {
|
|
466
|
+
totalCollateral: number;
|
|
467
|
+
markPrice: number;
|
|
468
|
+
baseMMR: number;
|
|
469
|
+
baseIMR: number;
|
|
470
|
+
IMR_Factor: number;
|
|
471
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol" | "mmr">[];
|
|
472
|
+
newOrder: {
|
|
473
|
+
symbol: string;
|
|
474
|
+
qty: number;
|
|
475
|
+
price: number;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* Estimated liquidation price
|
|
480
|
+
* @param inputs
|
|
481
|
+
* @returns
|
|
482
|
+
*/
|
|
483
|
+
declare function estLiqPrice(inputs: EstimatedLiquidationPriceInputs): number;
|
|
484
|
+
type EstimatedLeverageInputs = {
|
|
485
|
+
totalCollateral: number;
|
|
486
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol">[];
|
|
487
|
+
newOrder: {
|
|
488
|
+
symbol: string;
|
|
489
|
+
qty: number;
|
|
490
|
+
price: number;
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Estimated leverage
|
|
495
|
+
* @param inputs EstimtedLeverageInputs
|
|
496
|
+
* @returns number
|
|
497
|
+
*/
|
|
498
|
+
declare function estLeverage(inputs: EstimatedLeverageInputs): number | null;
|
|
439
499
|
|
|
500
|
+
type order_EstimatedLeverageInputs = EstimatedLeverageInputs;
|
|
501
|
+
type order_EstimatedLiquidationPriceInputs = EstimatedLiquidationPriceInputs;
|
|
502
|
+
declare const order_estLeverage: typeof estLeverage;
|
|
503
|
+
declare const order_estLiqPrice: typeof estLiqPrice;
|
|
440
504
|
declare const order_maxPrice: typeof maxPrice;
|
|
441
505
|
declare const order_minPrice: typeof minPrice;
|
|
506
|
+
declare const order_scropePrice: typeof scropePrice;
|
|
442
507
|
declare namespace order {
|
|
443
508
|
export {
|
|
509
|
+
order_EstimatedLeverageInputs as EstimatedLeverageInputs,
|
|
510
|
+
order_EstimatedLiquidationPriceInputs as EstimatedLiquidationPriceInputs,
|
|
511
|
+
order_estLeverage as estLeverage,
|
|
512
|
+
order_estLiqPrice as estLiqPrice,
|
|
444
513
|
order_maxPrice as maxPrice,
|
|
445
514
|
order_minPrice as minPrice,
|
|
515
|
+
order_scropePrice as scropePrice,
|
|
446
516
|
};
|
|
447
517
|
}
|
|
448
518
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare global {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
declare const _default: "
|
|
11
|
+
declare const _default: "2.0.0";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Calculates the notional value of a single position.
|
|
@@ -24,7 +24,7 @@ declare function notional(qty: number, mark_price: number): number;
|
|
|
24
24
|
* @link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Notional
|
|
25
25
|
*/
|
|
26
26
|
declare function totalNotional(positions: API.Position[]): number;
|
|
27
|
-
|
|
27
|
+
type UnrealPnLInputs = {
|
|
28
28
|
markPrice: number;
|
|
29
29
|
openPrice: number;
|
|
30
30
|
qty: number;
|
|
@@ -35,7 +35,7 @@ declare type UnrealPnLInputs = {
|
|
|
35
35
|
* @returns The unrealized profit or loss of the position.
|
|
36
36
|
*/
|
|
37
37
|
declare function unrealizedPnL(inputs: UnrealPnLInputs): number;
|
|
38
|
-
|
|
38
|
+
type UnrealPnLROIInputs = {
|
|
39
39
|
positionQty: number;
|
|
40
40
|
openPrice: number;
|
|
41
41
|
IMR: number;
|
|
@@ -53,10 +53,11 @@ declare function unrealizedPnLROI(inputs: UnrealPnLROIInputs): number;
|
|
|
53
53
|
* @returns The total unrealized profit or loss of all positions.
|
|
54
54
|
*/
|
|
55
55
|
declare function totalUnrealizedPnL(positions: API.Position[]): number;
|
|
56
|
-
|
|
56
|
+
type LiqPriceInputs = {
|
|
57
57
|
markPrice: number;
|
|
58
58
|
totalCollateral: number;
|
|
59
59
|
positionQty: number;
|
|
60
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "mmr">[];
|
|
60
61
|
MMR: number;
|
|
61
62
|
};
|
|
62
63
|
/**
|
|
@@ -66,7 +67,7 @@ declare type LiqPriceInputs = {
|
|
|
66
67
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Position-Liq.-Price}
|
|
67
68
|
*/
|
|
68
69
|
declare function liqPrice(inputs: LiqPriceInputs): number;
|
|
69
|
-
|
|
70
|
+
type MMInputs = {
|
|
70
71
|
positionQty: number;
|
|
71
72
|
markPrice: number;
|
|
72
73
|
MMR: number;
|
|
@@ -77,7 +78,7 @@ declare type MMInputs = {
|
|
|
77
78
|
* @returns The maintenance margin of the position.
|
|
78
79
|
*/
|
|
79
80
|
declare function maintenanceMargin(inputs: MMInputs): number;
|
|
80
|
-
|
|
81
|
+
type UnsettlementPnLInputs = {
|
|
81
82
|
positionQty: number;
|
|
82
83
|
markPrice: number;
|
|
83
84
|
costPosition: number;
|
|
@@ -91,7 +92,7 @@ declare type UnsettlementPnLInputs = {
|
|
|
91
92
|
* @link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Unsettlement-PNL-%5BinlineExtension%5D
|
|
92
93
|
*/
|
|
93
94
|
declare function unsettlementPnL(inputs: UnsettlementPnLInputs): number;
|
|
94
|
-
|
|
95
|
+
type TotalUnsettlementPnLInputs = {
|
|
95
96
|
positions: (API.Position & {
|
|
96
97
|
sum_unitary_funding: number;
|
|
97
98
|
})[];
|
|
@@ -106,22 +107,23 @@ declare type TotalUnsettlementPnLInputs = {
|
|
|
106
107
|
declare function totalUnsettlementPnL(positions: (API.Position & {
|
|
107
108
|
sum_unitary_funding: number;
|
|
108
109
|
})[]): number;
|
|
109
|
-
|
|
110
|
-
* Calculates the maintenance margin requirement (MMR) of a position.
|
|
111
|
-
* @param inputs The inputs for calculating the MMR.
|
|
112
|
-
* @returns The MMR of the position.
|
|
113
|
-
*/
|
|
114
|
-
declare function MMR(inputs: {
|
|
110
|
+
type MMRInputs = {
|
|
115
111
|
baseMMR: number;
|
|
116
112
|
baseIMR: number;
|
|
117
113
|
IMRFactor: number;
|
|
118
114
|
positionNotional: number;
|
|
119
115
|
IMR_factor_power: number;
|
|
120
|
-
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Calculates the maintenance margin requirement (MMR) of a position.
|
|
119
|
+
* @param inputs The inputs for calculating the MMR.
|
|
120
|
+
* @returns The MMR of the position.
|
|
121
|
+
*/
|
|
122
|
+
declare function MMR$1(inputs: MMRInputs): number;
|
|
121
123
|
|
|
122
124
|
type positions_LiqPriceInputs = LiqPriceInputs;
|
|
123
125
|
type positions_MMInputs = MMInputs;
|
|
124
|
-
|
|
126
|
+
type positions_MMRInputs = MMRInputs;
|
|
125
127
|
type positions_TotalUnsettlementPnLInputs = TotalUnsettlementPnLInputs;
|
|
126
128
|
type positions_UnrealPnLInputs = UnrealPnLInputs;
|
|
127
129
|
type positions_UnrealPnLROIInputs = UnrealPnLROIInputs;
|
|
@@ -139,7 +141,8 @@ declare namespace positions {
|
|
|
139
141
|
export {
|
|
140
142
|
positions_LiqPriceInputs as LiqPriceInputs,
|
|
141
143
|
positions_MMInputs as MMInputs,
|
|
142
|
-
|
|
144
|
+
MMR$1 as MMR,
|
|
145
|
+
positions_MMRInputs as MMRInputs,
|
|
143
146
|
positions_TotalUnsettlementPnLInputs as TotalUnsettlementPnLInputs,
|
|
144
147
|
positions_UnrealPnLInputs as UnrealPnLInputs,
|
|
145
148
|
positions_UnrealPnLROIInputs as UnrealPnLROIInputs,
|
|
@@ -156,10 +159,10 @@ declare namespace positions {
|
|
|
156
159
|
};
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
|
|
162
|
+
type ResultOptions = {
|
|
160
163
|
dp: number;
|
|
161
164
|
};
|
|
162
|
-
|
|
165
|
+
type TotalValueInputs = {
|
|
163
166
|
totalUnsettlementPnL: number;
|
|
164
167
|
USDCHolding: number;
|
|
165
168
|
nonUSDCHolding: {
|
|
@@ -178,7 +181,7 @@ declare function totalValue(inputs: TotalValueInputs): Decimal;
|
|
|
178
181
|
*
|
|
179
182
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Free-collateral}
|
|
180
183
|
*/
|
|
181
|
-
|
|
184
|
+
type FreeCollateralInputs = {
|
|
182
185
|
totalCollateral: Decimal;
|
|
183
186
|
totalInitialMarginWithOrders: number;
|
|
184
187
|
};
|
|
@@ -186,7 +189,7 @@ declare type FreeCollateralInputs = {
|
|
|
186
189
|
* 计算可用保证金
|
|
187
190
|
*/
|
|
188
191
|
declare function freeCollateral(inputs: FreeCollateralInputs): Decimal;
|
|
189
|
-
|
|
192
|
+
type TotalCollateralValueInputs = {
|
|
190
193
|
USDCHolding: number;
|
|
191
194
|
nonUSDCHolding: {
|
|
192
195
|
holding: number;
|
|
@@ -201,7 +204,7 @@ declare type TotalCollateralValueInputs = {
|
|
|
201
204
|
*/
|
|
202
205
|
declare function totalCollateral(inputs: TotalCollateralValueInputs): Decimal;
|
|
203
206
|
declare function initialMarginWithOrder(): void;
|
|
204
|
-
|
|
207
|
+
type PositionNotionalWithOrderInputs = {
|
|
205
208
|
markPrice: number;
|
|
206
209
|
positionQtyWithOrders: number;
|
|
207
210
|
};
|
|
@@ -209,7 +212,7 @@ declare type PositionNotionalWithOrderInputs = {
|
|
|
209
212
|
* 單一 Symbol position / orders notional 加總
|
|
210
213
|
*/
|
|
211
214
|
declare function positionNotionalWithOrder_by_symbol(inputs: PositionNotionalWithOrderInputs): Decimal;
|
|
212
|
-
|
|
215
|
+
type PositionQtyWithOrderInputs = {
|
|
213
216
|
positionQty: number;
|
|
214
217
|
buyOrdersQty: number;
|
|
215
218
|
sellOrdersQty: number;
|
|
@@ -218,7 +221,7 @@ declare type PositionQtyWithOrderInputs = {
|
|
|
218
221
|
* 單一 Symbol position / orders qty 加總
|
|
219
222
|
*/
|
|
220
223
|
declare function positionQtyWithOrders_by_symbol(inputs: PositionQtyWithOrderInputs): number;
|
|
221
|
-
|
|
224
|
+
type IMRInputs = {
|
|
222
225
|
maxLeverage: number;
|
|
223
226
|
baseIMR: number;
|
|
224
227
|
IMR_Factor: number;
|
|
@@ -247,7 +250,7 @@ declare function getPositonsAndOrdersNotionalBySymbol(inputs: {
|
|
|
247
250
|
symbol: string;
|
|
248
251
|
markPrice: number;
|
|
249
252
|
}): number;
|
|
250
|
-
|
|
253
|
+
type TotalInitialMarginWithOrdersInputs = {
|
|
251
254
|
positions: API.Position[];
|
|
252
255
|
orders: API.Order[];
|
|
253
256
|
markPrices: {
|
|
@@ -275,7 +278,7 @@ declare function groupOrdersBySymbol(orders: API.Order[]): {
|
|
|
275
278
|
* @returns An array of unique symbols.
|
|
276
279
|
*/
|
|
277
280
|
declare function extractSymbols(positions: Pick<API.Position, "symbol">[], orders: Pick<API.Order, "symbol">[]): string[];
|
|
278
|
-
|
|
281
|
+
type OtherIMsInputs = {
|
|
279
282
|
positions: API.Position[];
|
|
280
283
|
orders: API.Order[];
|
|
281
284
|
markPrices: {
|
|
@@ -291,7 +294,7 @@ declare type OtherIMsInputs = {
|
|
|
291
294
|
* 除当前symbol外的其他symbol已占用的总保证金
|
|
292
295
|
*/
|
|
293
296
|
declare function otherIMs(inputs: OtherIMsInputs): number;
|
|
294
|
-
|
|
297
|
+
type MaxQtyInputs = {
|
|
295
298
|
symbol: string;
|
|
296
299
|
baseMaxQty: number;
|
|
297
300
|
/**
|
|
@@ -317,9 +320,9 @@ declare type MaxQtyInputs = {
|
|
|
317
320
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Max-Order-QTY}
|
|
318
321
|
*/
|
|
319
322
|
declare function maxQty(side: OrderSide, inputs: MaxQtyInputs, options?: ResultOptions): number;
|
|
320
|
-
declare function maxQtyByLong(inputs: Omit<MaxQtyInputs, "side"
|
|
321
|
-
declare function maxQtyByShort(inputs: Omit<MaxQtyInputs, "side"
|
|
322
|
-
|
|
323
|
+
declare function maxQtyByLong(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
324
|
+
declare function maxQtyByShort(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
325
|
+
type TotalMarginRatioInputs = {
|
|
323
326
|
totalCollateral: number;
|
|
324
327
|
markPrices: {
|
|
325
328
|
[key: string]: number;
|
|
@@ -330,7 +333,7 @@ declare type TotalMarginRatioInputs = {
|
|
|
330
333
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Total-Margin-Ratio}
|
|
331
334
|
*/
|
|
332
335
|
declare function totalMarginRatio(inputs: TotalMarginRatioInputs, dp?: number): number;
|
|
333
|
-
|
|
336
|
+
type TotalUnrealizedROIInputs = {
|
|
334
337
|
totalUnrealizedPnL: number;
|
|
335
338
|
totalValue: number;
|
|
336
339
|
};
|
|
@@ -343,16 +346,32 @@ declare function totalUnrealizedROI(inputs: TotalUnrealizedROIInputs): number;
|
|
|
343
346
|
* @see {@link https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Current-account-leverage}
|
|
344
347
|
*/
|
|
345
348
|
declare function currentLeverage(totalMarginRatio: number): number;
|
|
346
|
-
|
|
349
|
+
type AvailableBalanceInputs = {
|
|
347
350
|
USDCHolding: number;
|
|
348
351
|
unsettlementPnL: number;
|
|
349
352
|
};
|
|
350
353
|
declare function availableBalance(inputs: AvailableBalanceInputs): number;
|
|
354
|
+
type AccountMMRInputs = {
|
|
355
|
+
positionsMMR: number;
|
|
356
|
+
/**
|
|
357
|
+
* Notional sum of all positions,
|
|
358
|
+
* positions.totalNotional()
|
|
359
|
+
*/
|
|
360
|
+
positionsNotional: number;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* total maintenance margin ratio
|
|
364
|
+
* @param inputs AccountMMRInputs
|
|
365
|
+
* @returns number|null
|
|
366
|
+
*/
|
|
367
|
+
declare function MMR(inputs: AccountMMRInputs): number | null;
|
|
351
368
|
|
|
369
|
+
type account_AccountMMRInputs = AccountMMRInputs;
|
|
352
370
|
type account_AvailableBalanceInputs = AvailableBalanceInputs;
|
|
353
371
|
type account_FreeCollateralInputs = FreeCollateralInputs;
|
|
354
372
|
declare const account_IMR: typeof IMR;
|
|
355
373
|
type account_IMRInputs = IMRInputs;
|
|
374
|
+
declare const account_MMR: typeof MMR;
|
|
356
375
|
type account_MaxQtyInputs = MaxQtyInputs;
|
|
357
376
|
type account_OtherIMsInputs = OtherIMsInputs;
|
|
358
377
|
type account_PositionNotionalWithOrderInputs = PositionNotionalWithOrderInputs;
|
|
@@ -387,10 +406,12 @@ declare const account_totalUnrealizedROI: typeof totalUnrealizedROI;
|
|
|
387
406
|
declare const account_totalValue: typeof totalValue;
|
|
388
407
|
declare namespace account {
|
|
389
408
|
export {
|
|
409
|
+
account_AccountMMRInputs as AccountMMRInputs,
|
|
390
410
|
account_AvailableBalanceInputs as AvailableBalanceInputs,
|
|
391
411
|
account_FreeCollateralInputs as FreeCollateralInputs,
|
|
392
412
|
account_IMR as IMR,
|
|
393
413
|
account_IMRInputs as IMRInputs,
|
|
414
|
+
account_MMR as MMR,
|
|
394
415
|
account_MaxQtyInputs as MaxQtyInputs,
|
|
395
416
|
account_OtherIMsInputs as OtherIMsInputs,
|
|
396
417
|
account_PositionNotionalWithOrderInputs as PositionNotionalWithOrderInputs,
|
|
@@ -427,22 +448,71 @@ declare namespace account {
|
|
|
427
448
|
}
|
|
428
449
|
|
|
429
450
|
/**
|
|
430
|
-
*
|
|
451
|
+
* Maximum price when placing an order
|
|
431
452
|
* @see https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Max-price
|
|
432
453
|
*/
|
|
433
454
|
declare function maxPrice(markprice: number, range: number): number;
|
|
434
455
|
/**
|
|
435
|
-
*
|
|
456
|
+
* Minimum price when placing an order
|
|
436
457
|
* @see https://wootraders.atlassian.net/wiki/spaces/WOOFI/pages/346030144/v2#Min-price
|
|
437
458
|
*/
|
|
438
459
|
declare function minPrice(markprice: number, range: number): number;
|
|
460
|
+
/**
|
|
461
|
+
* Scrope price when placing an order
|
|
462
|
+
* @returns number
|
|
463
|
+
*/
|
|
464
|
+
declare function scropePrice(price: number, scrope: number, side: "BUY" | "SELL"): number;
|
|
465
|
+
type EstimatedLiquidationPriceInputs = {
|
|
466
|
+
totalCollateral: number;
|
|
467
|
+
markPrice: number;
|
|
468
|
+
baseMMR: number;
|
|
469
|
+
baseIMR: number;
|
|
470
|
+
IMR_Factor: number;
|
|
471
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol" | "mmr">[];
|
|
472
|
+
newOrder: {
|
|
473
|
+
symbol: string;
|
|
474
|
+
qty: number;
|
|
475
|
+
price: number;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* Estimated liquidation price
|
|
480
|
+
* @param inputs
|
|
481
|
+
* @returns
|
|
482
|
+
*/
|
|
483
|
+
declare function estLiqPrice(inputs: EstimatedLiquidationPriceInputs): number;
|
|
484
|
+
type EstimatedLeverageInputs = {
|
|
485
|
+
totalCollateral: number;
|
|
486
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol">[];
|
|
487
|
+
newOrder: {
|
|
488
|
+
symbol: string;
|
|
489
|
+
qty: number;
|
|
490
|
+
price: number;
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Estimated leverage
|
|
495
|
+
* @param inputs EstimtedLeverageInputs
|
|
496
|
+
* @returns number
|
|
497
|
+
*/
|
|
498
|
+
declare function estLeverage(inputs: EstimatedLeverageInputs): number | null;
|
|
439
499
|
|
|
500
|
+
type order_EstimatedLeverageInputs = EstimatedLeverageInputs;
|
|
501
|
+
type order_EstimatedLiquidationPriceInputs = EstimatedLiquidationPriceInputs;
|
|
502
|
+
declare const order_estLeverage: typeof estLeverage;
|
|
503
|
+
declare const order_estLiqPrice: typeof estLiqPrice;
|
|
440
504
|
declare const order_maxPrice: typeof maxPrice;
|
|
441
505
|
declare const order_minPrice: typeof minPrice;
|
|
506
|
+
declare const order_scropePrice: typeof scropePrice;
|
|
442
507
|
declare namespace order {
|
|
443
508
|
export {
|
|
509
|
+
order_EstimatedLeverageInputs as EstimatedLeverageInputs,
|
|
510
|
+
order_EstimatedLiquidationPriceInputs as EstimatedLiquidationPriceInputs,
|
|
511
|
+
order_estLeverage as estLeverage,
|
|
512
|
+
order_estLiqPrice as estLiqPrice,
|
|
444
513
|
order_maxPrice as maxPrice,
|
|
445
514
|
order_minPrice as minPrice,
|
|
515
|
+
order_scropePrice as scropePrice,
|
|
446
516
|
};
|
|
447
517
|
}
|
|
448
518
|
|