@kodiak-finance/orderly-perp 4.7.4
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/README.md +1 -0
- package/dist/index.d.mts +599 -0
- package/dist/index.d.ts +599 -0
- package/dist/index.js +727 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +702 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import { API, OrderSide } from '@kodiak-finance/orderly-types';
|
|
2
|
+
import { Decimal } from '@kodiak-finance/orderly-utils';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__ORDERLY_VERSION__?: {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare const _default: "4.7.4";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the notional value of a single position.
|
|
15
|
+
* @param qty The quantity of the position.
|
|
16
|
+
* @param mark_price The price of the position.
|
|
17
|
+
* @returns The notional value of the position.
|
|
18
|
+
*/
|
|
19
|
+
declare function notional(qty: number, mark_price: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Calculates the total notional value of all positions.
|
|
22
|
+
* @param positions The array of positions.
|
|
23
|
+
* @returns The total notional value of all positions.
|
|
24
|
+
*/
|
|
25
|
+
declare function totalNotional(positions: API.Position[]): number;
|
|
26
|
+
type UnrealPnLInputs = {
|
|
27
|
+
markPrice: number;
|
|
28
|
+
openPrice: number;
|
|
29
|
+
qty: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Calculates the unrealized profit or loss of a single position.
|
|
33
|
+
* @param inputs The inputs for calculating the unrealized profit or loss.
|
|
34
|
+
* @returns The unrealized profit or loss of the position.
|
|
35
|
+
*/
|
|
36
|
+
declare function unrealizedPnL(inputs: UnrealPnLInputs): number;
|
|
37
|
+
type UnrealPnLROIInputs = {
|
|
38
|
+
positionQty: number;
|
|
39
|
+
openPrice: number;
|
|
40
|
+
IMR: number;
|
|
41
|
+
unrealizedPnL: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Calculates the return on investment (ROI) of a single position's unrealized profit or loss.
|
|
45
|
+
* @param inputs The inputs for calculating the ROI.
|
|
46
|
+
* @returns The ROI of the position's unrealized profit or loss.
|
|
47
|
+
*/
|
|
48
|
+
declare function unrealizedPnLROI(inputs: UnrealPnLROIInputs): number;
|
|
49
|
+
/**
|
|
50
|
+
* Calculates the total unrealized profit or loss of all positions.
|
|
51
|
+
* @param positions The array of positions.
|
|
52
|
+
* @returns The total unrealized profit or loss of all positions.
|
|
53
|
+
*/
|
|
54
|
+
declare function totalUnrealizedPnL(positions: API.Position[]): number;
|
|
55
|
+
type LiqPriceInputs = {
|
|
56
|
+
markPrice: number;
|
|
57
|
+
totalCollateral: number;
|
|
58
|
+
positionQty: number;
|
|
59
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "mmr">[];
|
|
60
|
+
MMR: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Calculates the liquidation price of a single position.
|
|
64
|
+
* @param inputs The inputs for calculating the liquidation price.
|
|
65
|
+
* @returns The liquidation price of the position.
|
|
66
|
+
*/
|
|
67
|
+
declare function liqPrice(inputs: LiqPriceInputs): number | null;
|
|
68
|
+
type MMInputs = {
|
|
69
|
+
positionQty: number;
|
|
70
|
+
markPrice: number;
|
|
71
|
+
MMR: number;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Calculates the maintenance margin of a position.
|
|
75
|
+
* @param inputs The inputs for calculating the maintenance margin.
|
|
76
|
+
* @returns The maintenance margin of the position.
|
|
77
|
+
*/
|
|
78
|
+
declare function maintenanceMargin(inputs: MMInputs): number;
|
|
79
|
+
type UnsettlementPnLInputs = {
|
|
80
|
+
positionQty: number;
|
|
81
|
+
markPrice: number;
|
|
82
|
+
costPosition: number;
|
|
83
|
+
sumUnitaryFunding: number;
|
|
84
|
+
lastSumUnitaryFunding: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Calculates the unrealized profit or loss of each position.
|
|
88
|
+
* @param inputs The inputs for calculating the unrealized profit or loss.
|
|
89
|
+
* @returns The unrealized profit or loss of each position.
|
|
90
|
+
*/
|
|
91
|
+
declare function unsettlementPnL(inputs: UnsettlementPnLInputs): number;
|
|
92
|
+
type TotalUnsettlementPnLInputs = {
|
|
93
|
+
positions: (API.Position & {
|
|
94
|
+
sum_unitary_funding: number;
|
|
95
|
+
})[];
|
|
96
|
+
sumUnitaryFunding: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Calculates the total unrealized profit or loss of all positions.
|
|
100
|
+
* @param positions The array of positions.
|
|
101
|
+
* @returns The total unrealized profit or loss of all positions.
|
|
102
|
+
*/
|
|
103
|
+
declare function totalUnsettlementPnL(positions: (API.Position & {
|
|
104
|
+
sum_unitary_funding: number;
|
|
105
|
+
})[]): number;
|
|
106
|
+
type MMRInputs = {
|
|
107
|
+
baseMMR: number;
|
|
108
|
+
baseIMR: number;
|
|
109
|
+
IMRFactor: number;
|
|
110
|
+
positionNotional: number;
|
|
111
|
+
IMR_factor_power: number;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Calculates the maintenance margin requirement (MMR) of a position.
|
|
115
|
+
* @param inputs The inputs for calculating the MMR.
|
|
116
|
+
* @returns The MMR of the position.
|
|
117
|
+
*/
|
|
118
|
+
declare function MMR$1(inputs: MMRInputs): number;
|
|
119
|
+
/**
|
|
120
|
+
* Calculates the profit or loss for take profit.
|
|
121
|
+
* @returns The profit or loss for take profit.
|
|
122
|
+
*/
|
|
123
|
+
declare function estPnLForTP(inputs: {
|
|
124
|
+
positionQty: number;
|
|
125
|
+
entryPrice: number;
|
|
126
|
+
price: number;
|
|
127
|
+
}): number;
|
|
128
|
+
/**
|
|
129
|
+
* Calculates the estimated price for take profit.
|
|
130
|
+
*/
|
|
131
|
+
declare function estPriceForTP(inputs: {
|
|
132
|
+
positionQty: number;
|
|
133
|
+
entryPrice: number;
|
|
134
|
+
pnl: number;
|
|
135
|
+
}): number;
|
|
136
|
+
/**
|
|
137
|
+
* Calculates the estimated offset for take profit.
|
|
138
|
+
*/
|
|
139
|
+
declare function estOffsetForTP(inputs: {
|
|
140
|
+
price: number;
|
|
141
|
+
entryPrice: number;
|
|
142
|
+
}): number;
|
|
143
|
+
/**
|
|
144
|
+
* Calculates the estimated price from offset for take profit.
|
|
145
|
+
*/
|
|
146
|
+
declare function estPriceFromOffsetForTP(inputs: {
|
|
147
|
+
offset: number;
|
|
148
|
+
entryPrice: number;
|
|
149
|
+
}): number;
|
|
150
|
+
/**
|
|
151
|
+
* Calculates the PnL for stop loss.
|
|
152
|
+
*/
|
|
153
|
+
declare function estPnLForSL(inputs: {
|
|
154
|
+
positionQty: number;
|
|
155
|
+
entryPrice: number;
|
|
156
|
+
}): number;
|
|
157
|
+
/**
|
|
158
|
+
* calculate the max position notional
|
|
159
|
+
* max_notional = ( (1/ (leverage * imr_factor) ) ^ (1/0.8)
|
|
160
|
+
*/
|
|
161
|
+
declare function maxPositionNotional(inputs: {
|
|
162
|
+
/** symbol leverage */
|
|
163
|
+
leverage: number;
|
|
164
|
+
IMRFactor: number;
|
|
165
|
+
}): number;
|
|
166
|
+
/**
|
|
167
|
+
* symbol_leverage_max = 1 / ( imr_factor * notional ^ 0.8 )
|
|
168
|
+
*/
|
|
169
|
+
declare function maxPositionLeverage(inputs: {
|
|
170
|
+
IMRFactor: number;
|
|
171
|
+
notional: number;
|
|
172
|
+
}): number;
|
|
173
|
+
|
|
174
|
+
type positions_LiqPriceInputs = LiqPriceInputs;
|
|
175
|
+
type positions_MMInputs = MMInputs;
|
|
176
|
+
type positions_MMRInputs = MMRInputs;
|
|
177
|
+
type positions_TotalUnsettlementPnLInputs = TotalUnsettlementPnLInputs;
|
|
178
|
+
type positions_UnrealPnLInputs = UnrealPnLInputs;
|
|
179
|
+
type positions_UnrealPnLROIInputs = UnrealPnLROIInputs;
|
|
180
|
+
type positions_UnsettlementPnLInputs = UnsettlementPnLInputs;
|
|
181
|
+
declare const positions_estOffsetForTP: typeof estOffsetForTP;
|
|
182
|
+
declare const positions_estPnLForSL: typeof estPnLForSL;
|
|
183
|
+
declare const positions_estPnLForTP: typeof estPnLForTP;
|
|
184
|
+
declare const positions_estPriceForTP: typeof estPriceForTP;
|
|
185
|
+
declare const positions_estPriceFromOffsetForTP: typeof estPriceFromOffsetForTP;
|
|
186
|
+
declare const positions_liqPrice: typeof liqPrice;
|
|
187
|
+
declare const positions_maintenanceMargin: typeof maintenanceMargin;
|
|
188
|
+
declare const positions_maxPositionLeverage: typeof maxPositionLeverage;
|
|
189
|
+
declare const positions_maxPositionNotional: typeof maxPositionNotional;
|
|
190
|
+
declare const positions_notional: typeof notional;
|
|
191
|
+
declare const positions_totalNotional: typeof totalNotional;
|
|
192
|
+
declare const positions_totalUnrealizedPnL: typeof totalUnrealizedPnL;
|
|
193
|
+
declare const positions_totalUnsettlementPnL: typeof totalUnsettlementPnL;
|
|
194
|
+
declare const positions_unrealizedPnL: typeof unrealizedPnL;
|
|
195
|
+
declare const positions_unrealizedPnLROI: typeof unrealizedPnLROI;
|
|
196
|
+
declare const positions_unsettlementPnL: typeof unsettlementPnL;
|
|
197
|
+
declare namespace positions {
|
|
198
|
+
export { type positions_LiqPriceInputs as LiqPriceInputs, type positions_MMInputs as MMInputs, MMR$1 as MMR, type positions_MMRInputs as MMRInputs, type positions_TotalUnsettlementPnLInputs as TotalUnsettlementPnLInputs, type positions_UnrealPnLInputs as UnrealPnLInputs, type positions_UnrealPnLROIInputs as UnrealPnLROIInputs, type positions_UnsettlementPnLInputs as UnsettlementPnLInputs, positions_estOffsetForTP as estOffsetForTP, positions_estPnLForSL as estPnLForSL, positions_estPnLForTP as estPnLForTP, positions_estPriceForTP as estPriceForTP, positions_estPriceFromOffsetForTP as estPriceFromOffsetForTP, positions_liqPrice as liqPrice, positions_maintenanceMargin as maintenanceMargin, positions_maxPositionLeverage as maxPositionLeverage, positions_maxPositionNotional as maxPositionNotional, positions_notional as notional, positions_totalNotional as totalNotional, positions_totalUnrealizedPnL as totalUnrealizedPnL, positions_totalUnsettlementPnL as totalUnsettlementPnL, positions_unrealizedPnL as unrealizedPnL, positions_unrealizedPnLROI as unrealizedPnLROI, positions_unsettlementPnL as unsettlementPnL };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type ResultOptions = {
|
|
202
|
+
dp: number;
|
|
203
|
+
};
|
|
204
|
+
type TotalValueInputs = {
|
|
205
|
+
totalUnsettlementPnL: number;
|
|
206
|
+
USDCHolding: number;
|
|
207
|
+
nonUSDCHolding: {
|
|
208
|
+
holding: number;
|
|
209
|
+
indexPrice: number;
|
|
210
|
+
}[];
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* User's total asset value (denominated in USDC), including assets that cannot be used as collateral.
|
|
214
|
+
*/
|
|
215
|
+
declare function totalValue(inputs: TotalValueInputs): Decimal;
|
|
216
|
+
/**
|
|
217
|
+
* Total value of available collateral in the user's account (denominated in USDC).
|
|
218
|
+
*/
|
|
219
|
+
type FreeCollateralInputs = {
|
|
220
|
+
totalCollateral: Decimal;
|
|
221
|
+
totalInitialMarginWithOrders: number;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Calculate free collateral.
|
|
225
|
+
*/
|
|
226
|
+
declare function freeCollateral(inputs: FreeCollateralInputs): Decimal;
|
|
227
|
+
type TotalCollateralValueInputs = {
|
|
228
|
+
USDCHolding: number;
|
|
229
|
+
nonUSDCHolding: {
|
|
230
|
+
holding: number;
|
|
231
|
+
indexPrice: number;
|
|
232
|
+
collateralCap: number;
|
|
233
|
+
collateralRatio: Decimal;
|
|
234
|
+
}[];
|
|
235
|
+
unsettlementPnL: number;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Calculate total collateral.
|
|
239
|
+
*/
|
|
240
|
+
declare function totalCollateral(inputs: TotalCollateralValueInputs): Decimal;
|
|
241
|
+
declare function initialMarginWithOrder(): void;
|
|
242
|
+
type PositionNotionalWithOrderInputs = {
|
|
243
|
+
markPrice: number;
|
|
244
|
+
positionQtyWithOrders: number;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Sum of notional value for a symbol's position and orders.
|
|
248
|
+
*/
|
|
249
|
+
declare function positionNotionalWithOrder_by_symbol(inputs: PositionNotionalWithOrderInputs): Decimal;
|
|
250
|
+
type PositionQtyWithOrderInputs = {
|
|
251
|
+
positionQty: number;
|
|
252
|
+
buyOrdersQty: number;
|
|
253
|
+
sellOrdersQty: number;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Sum of position quantity and orders quantity for a symbol.
|
|
257
|
+
*/
|
|
258
|
+
declare function positionQtyWithOrders_by_symbol(inputs: PositionQtyWithOrderInputs): number;
|
|
259
|
+
type IMRInputs = {
|
|
260
|
+
/**
|
|
261
|
+
* effective max leverage
|
|
262
|
+
*/
|
|
263
|
+
maxLeverage: number;
|
|
264
|
+
baseIMR: number;
|
|
265
|
+
IMR_Factor: number;
|
|
266
|
+
positionNotional: number;
|
|
267
|
+
ordersNotional: number;
|
|
268
|
+
IMR_factor_power?: number;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Initial margin rate for a symbol.
|
|
272
|
+
* Max(1 / Max Account Leverage, Base IMR i, IMR Factor i * Abs(Position Notional i + Order Notional i)^(4/5))
|
|
273
|
+
*/
|
|
274
|
+
declare function IMR(inputs: IMRInputs): number;
|
|
275
|
+
declare function buyOrdersFilter_by_symbol(orders: API.Order[], symbol: string): API.Order[];
|
|
276
|
+
declare function sellOrdersFilter_by_symbol(orders: API.Order[], symbol: string): API.Order[];
|
|
277
|
+
/**
|
|
278
|
+
* Get the quantity of a specified symbol from the list of positions.
|
|
279
|
+
*/
|
|
280
|
+
declare function getQtyFromPositions(positions: API.Position[], symbol: string): number;
|
|
281
|
+
/**
|
|
282
|
+
* Get the quantity of long and short orders for a specified symbol from the list of orders.
|
|
283
|
+
*/
|
|
284
|
+
declare function getQtyFromOrdersBySide(orders: API.Order[], symbol: string, side: OrderSide): number;
|
|
285
|
+
declare function getPositonsAndOrdersNotionalBySymbol(inputs: {
|
|
286
|
+
positions: API.Position[];
|
|
287
|
+
orders: API.Order[];
|
|
288
|
+
symbol: string;
|
|
289
|
+
markPrice: number;
|
|
290
|
+
}): number;
|
|
291
|
+
type TotalInitialMarginWithOrdersInputs = {
|
|
292
|
+
positions: API.Position[];
|
|
293
|
+
orders: API.Order[];
|
|
294
|
+
markPrices: {
|
|
295
|
+
[key: string]: number;
|
|
296
|
+
};
|
|
297
|
+
symbolInfo: any;
|
|
298
|
+
IMR_Factors: {
|
|
299
|
+
[key: string]: number;
|
|
300
|
+
};
|
|
301
|
+
} & Pick<IMRInputs, "maxLeverage">;
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated
|
|
304
|
+
* Calculate the total initial margin used by the user (including positions and orders).
|
|
305
|
+
*/
|
|
306
|
+
declare function totalInitialMarginWithOrders(inputs: TotalInitialMarginWithOrdersInputs): number;
|
|
307
|
+
declare function totalInitialMarginWithQty(inputs: {
|
|
308
|
+
positions: API.Position[];
|
|
309
|
+
markPrices: {
|
|
310
|
+
[key: string]: number;
|
|
311
|
+
};
|
|
312
|
+
symbolInfo: any;
|
|
313
|
+
IMR_Factors: {
|
|
314
|
+
[key: string]: number;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* account max leverage
|
|
318
|
+
*/
|
|
319
|
+
maxLeverage: number;
|
|
320
|
+
}): number;
|
|
321
|
+
/**
|
|
322
|
+
* Group orders by symbol, as a symbol can have multiple orders.
|
|
323
|
+
*/
|
|
324
|
+
declare function groupOrdersBySymbol(orders: API.Order[]): {
|
|
325
|
+
[key: string]: API.Order[];
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Extracts all unique symbols from positions and orders.
|
|
329
|
+
* @param positions - An array of position objects.
|
|
330
|
+
* @param orders - An array of order objects.
|
|
331
|
+
* @returns An array of unique symbols.
|
|
332
|
+
*/
|
|
333
|
+
declare function extractSymbols(positions: Pick<API.Position, "symbol">[], orders: Pick<API.Order, "symbol">[]): string[];
|
|
334
|
+
type OtherIMsInputs = {
|
|
335
|
+
positions: API.Position[];
|
|
336
|
+
markPrices: {
|
|
337
|
+
[key: string]: number;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* account max leverage
|
|
341
|
+
*/
|
|
342
|
+
maxLeverage: number;
|
|
343
|
+
symbolInfo: any;
|
|
344
|
+
IMR_Factors: {
|
|
345
|
+
[key: string]: number;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* Total margin used by other symbols (except the current symbol).
|
|
350
|
+
*/
|
|
351
|
+
declare function otherIMs(inputs: OtherIMsInputs): number;
|
|
352
|
+
type MaxQtyInputs = {
|
|
353
|
+
symbol: string;
|
|
354
|
+
baseMaxQty: number;
|
|
355
|
+
/**
|
|
356
|
+
* Total collateral of the user (denominated in USDC), can be calculated from totalCollateral.
|
|
357
|
+
* @see totalCollateral
|
|
358
|
+
*/
|
|
359
|
+
totalCollateral: number;
|
|
360
|
+
maxLeverage: number;
|
|
361
|
+
baseIMR: number;
|
|
362
|
+
/**
|
|
363
|
+
* @see otherIMs
|
|
364
|
+
*/
|
|
365
|
+
otherIMs: number;
|
|
366
|
+
markPrice: number;
|
|
367
|
+
positionQty: number;
|
|
368
|
+
buyOrdersQty: number;
|
|
369
|
+
sellOrdersQty: number;
|
|
370
|
+
IMR_Factor: number;
|
|
371
|
+
takerFeeRate: number;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Maximum order quantity.
|
|
375
|
+
*/
|
|
376
|
+
declare function maxQty(side: OrderSide, inputs: MaxQtyInputs, options?: ResultOptions): number;
|
|
377
|
+
declare function maxQtyByLong(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
378
|
+
declare function maxQtyByShort(inputs: Omit<MaxQtyInputs, "side">, options?: ResultOptions): number;
|
|
379
|
+
type TotalMarginRatioInputs = {
|
|
380
|
+
totalCollateral: number;
|
|
381
|
+
markPrices: {
|
|
382
|
+
[key: string]: number;
|
|
383
|
+
};
|
|
384
|
+
positions: API.Position[];
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* total margin ratio
|
|
388
|
+
*/
|
|
389
|
+
declare function totalMarginRatio(inputs: TotalMarginRatioInputs, dp?: number): number;
|
|
390
|
+
type TotalUnrealizedROIInputs = {
|
|
391
|
+
totalUnrealizedPnL: number;
|
|
392
|
+
totalValue: number;
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* totalUnrealizedROI
|
|
396
|
+
*/
|
|
397
|
+
declare function totalUnrealizedROI(inputs: TotalUnrealizedROIInputs): number;
|
|
398
|
+
/**
|
|
399
|
+
* current account leverage
|
|
400
|
+
*/
|
|
401
|
+
declare function currentLeverage(totalMarginRatio: number): number;
|
|
402
|
+
type AvailableBalanceInputs = {
|
|
403
|
+
USDCHolding: number;
|
|
404
|
+
unsettlementPnL: number;
|
|
405
|
+
};
|
|
406
|
+
declare function availableBalance(inputs: AvailableBalanceInputs): number;
|
|
407
|
+
type AccountMMRInputs = {
|
|
408
|
+
positionsMMR: number;
|
|
409
|
+
/**
|
|
410
|
+
* Notional sum of all positions,
|
|
411
|
+
* positions.totalNotional()
|
|
412
|
+
*/
|
|
413
|
+
positionsNotional: number;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* total maintenance margin ratio
|
|
417
|
+
* @param inputs AccountMMRInputs
|
|
418
|
+
* @returns number|null
|
|
419
|
+
*/
|
|
420
|
+
declare function MMR(inputs: AccountMMRInputs): number | null;
|
|
421
|
+
declare const collateralRatio: (params: {
|
|
422
|
+
baseWeight: number;
|
|
423
|
+
discountFactor: number | null;
|
|
424
|
+
collateralQty: number;
|
|
425
|
+
collateralCap: number;
|
|
426
|
+
indexPrice: number;
|
|
427
|
+
}) => Decimal;
|
|
428
|
+
/** collateral_value_i = min(collateral_qty_i , collateral_cap_i) * weight_i * index_price_i */
|
|
429
|
+
declare const collateralContribution: (params: {
|
|
430
|
+
collateralQty: number;
|
|
431
|
+
collateralCap: number;
|
|
432
|
+
collateralRatio: number;
|
|
433
|
+
indexPrice: number;
|
|
434
|
+
}) => number;
|
|
435
|
+
declare const LTV: (params: {
|
|
436
|
+
usdcBalance: number;
|
|
437
|
+
upnl: number;
|
|
438
|
+
assets: Array<{
|
|
439
|
+
qty: number;
|
|
440
|
+
indexPrice: number;
|
|
441
|
+
weight: number;
|
|
442
|
+
}>;
|
|
443
|
+
}) => number;
|
|
444
|
+
/**
|
|
445
|
+
* max(0, min(USDC_balance, free_collateral - max(upnl, 0)))
|
|
446
|
+
*/
|
|
447
|
+
declare const maxWithdrawalUSDC: (inputs: {
|
|
448
|
+
USDCBalance: number;
|
|
449
|
+
freeCollateral: Decimal;
|
|
450
|
+
upnl: number;
|
|
451
|
+
}) => number;
|
|
452
|
+
/**
|
|
453
|
+
*
|
|
454
|
+
* Other collateral: min(collateral_qty_i, free_collateral / (index_price_i × weight_i)
|
|
455
|
+
* Other collateral with negative USDC: min(collateral_qty_i, free_collateral / (index_price_i × (1 + buffer) × weight_i)
|
|
456
|
+
* buffer: 0.2%
|
|
457
|
+
*/
|
|
458
|
+
declare const maxWithdrawalOtherCollateral: (inputs: {
|
|
459
|
+
USDCBalance: number;
|
|
460
|
+
collateralQty: number;
|
|
461
|
+
freeCollateral: Decimal;
|
|
462
|
+
indexPrice: number;
|
|
463
|
+
weight: Decimal;
|
|
464
|
+
}) => Decimal;
|
|
465
|
+
declare const calcMinimumReceived: (inputs: {
|
|
466
|
+
amount: number;
|
|
467
|
+
slippage: number;
|
|
468
|
+
}) => number;
|
|
469
|
+
/**
|
|
470
|
+
* @deprecated This method will be removed soon. Please update your code to use symbolLeverage directly.
|
|
471
|
+
*/
|
|
472
|
+
declare const maxLeverage: (inputs: {
|
|
473
|
+
symbolLeverage?: number;
|
|
474
|
+
accountLeverage: number;
|
|
475
|
+
}) => number;
|
|
476
|
+
|
|
477
|
+
type account_AccountMMRInputs = AccountMMRInputs;
|
|
478
|
+
type account_AvailableBalanceInputs = AvailableBalanceInputs;
|
|
479
|
+
type account_FreeCollateralInputs = FreeCollateralInputs;
|
|
480
|
+
declare const account_IMR: typeof IMR;
|
|
481
|
+
type account_IMRInputs = IMRInputs;
|
|
482
|
+
declare const account_LTV: typeof LTV;
|
|
483
|
+
declare const account_MMR: typeof MMR;
|
|
484
|
+
type account_MaxQtyInputs = MaxQtyInputs;
|
|
485
|
+
type account_OtherIMsInputs = OtherIMsInputs;
|
|
486
|
+
type account_PositionNotionalWithOrderInputs = PositionNotionalWithOrderInputs;
|
|
487
|
+
type account_PositionQtyWithOrderInputs = PositionQtyWithOrderInputs;
|
|
488
|
+
type account_ResultOptions = ResultOptions;
|
|
489
|
+
type account_TotalCollateralValueInputs = TotalCollateralValueInputs;
|
|
490
|
+
type account_TotalInitialMarginWithOrdersInputs = TotalInitialMarginWithOrdersInputs;
|
|
491
|
+
type account_TotalMarginRatioInputs = TotalMarginRatioInputs;
|
|
492
|
+
type account_TotalUnrealizedROIInputs = TotalUnrealizedROIInputs;
|
|
493
|
+
type account_TotalValueInputs = TotalValueInputs;
|
|
494
|
+
declare const account_availableBalance: typeof availableBalance;
|
|
495
|
+
declare const account_buyOrdersFilter_by_symbol: typeof buyOrdersFilter_by_symbol;
|
|
496
|
+
declare const account_calcMinimumReceived: typeof calcMinimumReceived;
|
|
497
|
+
declare const account_collateralContribution: typeof collateralContribution;
|
|
498
|
+
declare const account_collateralRatio: typeof collateralRatio;
|
|
499
|
+
declare const account_currentLeverage: typeof currentLeverage;
|
|
500
|
+
declare const account_extractSymbols: typeof extractSymbols;
|
|
501
|
+
declare const account_freeCollateral: typeof freeCollateral;
|
|
502
|
+
declare const account_getPositonsAndOrdersNotionalBySymbol: typeof getPositonsAndOrdersNotionalBySymbol;
|
|
503
|
+
declare const account_getQtyFromOrdersBySide: typeof getQtyFromOrdersBySide;
|
|
504
|
+
declare const account_getQtyFromPositions: typeof getQtyFromPositions;
|
|
505
|
+
declare const account_groupOrdersBySymbol: typeof groupOrdersBySymbol;
|
|
506
|
+
declare const account_initialMarginWithOrder: typeof initialMarginWithOrder;
|
|
507
|
+
declare const account_maxLeverage: typeof maxLeverage;
|
|
508
|
+
declare const account_maxQty: typeof maxQty;
|
|
509
|
+
declare const account_maxQtyByLong: typeof maxQtyByLong;
|
|
510
|
+
declare const account_maxQtyByShort: typeof maxQtyByShort;
|
|
511
|
+
declare const account_maxWithdrawalOtherCollateral: typeof maxWithdrawalOtherCollateral;
|
|
512
|
+
declare const account_maxWithdrawalUSDC: typeof maxWithdrawalUSDC;
|
|
513
|
+
declare const account_otherIMs: typeof otherIMs;
|
|
514
|
+
declare const account_positionNotionalWithOrder_by_symbol: typeof positionNotionalWithOrder_by_symbol;
|
|
515
|
+
declare const account_positionQtyWithOrders_by_symbol: typeof positionQtyWithOrders_by_symbol;
|
|
516
|
+
declare const account_sellOrdersFilter_by_symbol: typeof sellOrdersFilter_by_symbol;
|
|
517
|
+
declare const account_totalCollateral: typeof totalCollateral;
|
|
518
|
+
declare const account_totalInitialMarginWithOrders: typeof totalInitialMarginWithOrders;
|
|
519
|
+
declare const account_totalInitialMarginWithQty: typeof totalInitialMarginWithQty;
|
|
520
|
+
declare const account_totalMarginRatio: typeof totalMarginRatio;
|
|
521
|
+
declare const account_totalUnrealizedROI: typeof totalUnrealizedROI;
|
|
522
|
+
declare const account_totalValue: typeof totalValue;
|
|
523
|
+
declare namespace account {
|
|
524
|
+
export { type account_AccountMMRInputs as AccountMMRInputs, type account_AvailableBalanceInputs as AvailableBalanceInputs, type account_FreeCollateralInputs as FreeCollateralInputs, account_IMR as IMR, type account_IMRInputs as IMRInputs, account_LTV as LTV, account_MMR as MMR, type account_MaxQtyInputs as MaxQtyInputs, type account_OtherIMsInputs as OtherIMsInputs, type account_PositionNotionalWithOrderInputs as PositionNotionalWithOrderInputs, type account_PositionQtyWithOrderInputs as PositionQtyWithOrderInputs, type account_ResultOptions as ResultOptions, type account_TotalCollateralValueInputs as TotalCollateralValueInputs, type account_TotalInitialMarginWithOrdersInputs as TotalInitialMarginWithOrdersInputs, type account_TotalMarginRatioInputs as TotalMarginRatioInputs, type account_TotalUnrealizedROIInputs as TotalUnrealizedROIInputs, type account_TotalValueInputs as TotalValueInputs, account_availableBalance as availableBalance, account_buyOrdersFilter_by_symbol as buyOrdersFilter_by_symbol, account_calcMinimumReceived as calcMinimumReceived, account_collateralContribution as collateralContribution, account_collateralRatio as collateralRatio, account_currentLeverage as currentLeverage, account_extractSymbols as extractSymbols, account_freeCollateral as freeCollateral, account_getPositonsAndOrdersNotionalBySymbol as getPositonsAndOrdersNotionalBySymbol, account_getQtyFromOrdersBySide as getQtyFromOrdersBySide, account_getQtyFromPositions as getQtyFromPositions, account_groupOrdersBySymbol as groupOrdersBySymbol, account_initialMarginWithOrder as initialMarginWithOrder, account_maxLeverage as maxLeverage, account_maxQty as maxQty, account_maxQtyByLong as maxQtyByLong, account_maxQtyByShort as maxQtyByShort, account_maxWithdrawalOtherCollateral as maxWithdrawalOtherCollateral, account_maxWithdrawalUSDC as maxWithdrawalUSDC, account_otherIMs as otherIMs, account_positionNotionalWithOrder_by_symbol as positionNotionalWithOrder_by_symbol, account_positionQtyWithOrders_by_symbol as positionQtyWithOrders_by_symbol, account_sellOrdersFilter_by_symbol as sellOrdersFilter_by_symbol, account_totalCollateral as totalCollateral, account_totalInitialMarginWithOrders as totalInitialMarginWithOrders, account_totalInitialMarginWithQty as totalInitialMarginWithQty, account_totalMarginRatio as totalMarginRatio, account_totalUnrealizedROI as totalUnrealizedROI, account_totalValue as totalValue };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Maximum price when placing an order
|
|
529
|
+
*/
|
|
530
|
+
declare function maxPrice(markprice: number, range: number): number;
|
|
531
|
+
/**
|
|
532
|
+
* Minimum price when placing an order
|
|
533
|
+
*/
|
|
534
|
+
declare function minPrice(markprice: number, range: number): number;
|
|
535
|
+
/**
|
|
536
|
+
* Scope price when placing an order
|
|
537
|
+
* @returns number
|
|
538
|
+
*/
|
|
539
|
+
declare function scopePrice(price: number, scope: number, side: "BUY" | "SELL"): number;
|
|
540
|
+
/**
|
|
541
|
+
* Calculate the order fee
|
|
542
|
+
*/
|
|
543
|
+
declare function orderFee(inputs: {
|
|
544
|
+
/**
|
|
545
|
+
* Order quantity
|
|
546
|
+
*/
|
|
547
|
+
qty: number;
|
|
548
|
+
price: number;
|
|
549
|
+
futuresTakeFeeRate: number;
|
|
550
|
+
}): number;
|
|
551
|
+
type EstimatedLiquidationPriceInputs = {
|
|
552
|
+
totalCollateral: number;
|
|
553
|
+
markPrice: number;
|
|
554
|
+
baseMMR: number;
|
|
555
|
+
baseIMR: number;
|
|
556
|
+
IMR_Factor: number;
|
|
557
|
+
orderFee: number;
|
|
558
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol" | "mmr">[];
|
|
559
|
+
newOrder: {
|
|
560
|
+
symbol: string;
|
|
561
|
+
qty: number;
|
|
562
|
+
price: number;
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
/**
|
|
566
|
+
* Estimated liquidation price
|
|
567
|
+
* @param inputs
|
|
568
|
+
* @returns
|
|
569
|
+
*/
|
|
570
|
+
declare function estLiqPrice(inputs: EstimatedLiquidationPriceInputs): number;
|
|
571
|
+
type EstimatedLeverageInputs = {
|
|
572
|
+
totalCollateral: number;
|
|
573
|
+
positions: Pick<API.PositionExt, "position_qty" | "mark_price" | "symbol">[];
|
|
574
|
+
newOrder: {
|
|
575
|
+
symbol: string;
|
|
576
|
+
qty: number;
|
|
577
|
+
price: number;
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
581
|
+
* Estimated leverage
|
|
582
|
+
* @param inputs EstimtedLeverageInputs
|
|
583
|
+
* @returns number
|
|
584
|
+
*/
|
|
585
|
+
declare function estLeverage(inputs: EstimatedLeverageInputs): number | null;
|
|
586
|
+
|
|
587
|
+
type order_EstimatedLeverageInputs = EstimatedLeverageInputs;
|
|
588
|
+
type order_EstimatedLiquidationPriceInputs = EstimatedLiquidationPriceInputs;
|
|
589
|
+
declare const order_estLeverage: typeof estLeverage;
|
|
590
|
+
declare const order_estLiqPrice: typeof estLiqPrice;
|
|
591
|
+
declare const order_maxPrice: typeof maxPrice;
|
|
592
|
+
declare const order_minPrice: typeof minPrice;
|
|
593
|
+
declare const order_orderFee: typeof orderFee;
|
|
594
|
+
declare const order_scopePrice: typeof scopePrice;
|
|
595
|
+
declare namespace order {
|
|
596
|
+
export { type order_EstimatedLeverageInputs as EstimatedLeverageInputs, type order_EstimatedLiquidationPriceInputs as EstimatedLiquidationPriceInputs, order_estLeverage as estLeverage, order_estLiqPrice as estLiqPrice, order_maxPrice as maxPrice, order_minPrice as minPrice, order_orderFee as orderFee, order_scopePrice as scopePrice };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export { account, order, order as orderUtils, positions, _default as version };
|