@reyaxyz/api-sdk 0.157.0 → 0.159.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/clients/api-client.js +0 -60
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/modules/account/index.js +33 -94
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/account/types.js.map +1 -1
- package/dist/clients/modules/auth/types.js.map +1 -1
- package/dist/clients/modules/conditional-orders/types.js.map +1 -1
- package/dist/clients/modules/deposit-existing-MA.simulation/types.js.map +1 -1
- package/dist/clients/modules/edit-collateral.simulation/types.js.map +1 -1
- package/dist/clients/modules/markets/index.js +0 -15
- package/dist/clients/modules/markets/index.js.map +1 -1
- package/dist/clients/modules/owner/index.js +0 -36
- package/dist/clients/modules/owner/index.js.map +1 -1
- package/dist/clients/modules/transfer-MA-Pool.simulation/types.js.map +1 -1
- package/dist/clients/modules/transfer-margin-between-MAs.simulation/types.js.map +1 -1
- package/dist/clients/modules/withdraw-MA.simulation/types.js.map +1 -1
- package/dist/clients/types.js +0 -3
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/api-client.d.ts +0 -42
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +2 -10
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/account/types.d.ts +24 -24
- package/dist/types/clients/modules/account/types.d.ts.map +1 -1
- package/dist/types/clients/modules/auth/types.d.ts +1 -2
- package/dist/types/clients/modules/auth/types.d.ts.map +1 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts +3 -3
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +1 -1
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/deposit-existing-MA.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts +4 -4
- package/dist/types/clients/modules/edit-collateral.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/markets/index.d.ts +1 -2
- package/dist/types/clients/modules/markets/index.d.ts.map +1 -1
- package/dist/types/clients/modules/owner/index.d.ts +1 -5
- package/dist/types/clients/modules/owner/index.d.ts.map +1 -1
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/transfer-MA-Pool.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts +7 -7
- package/dist/types/clients/modules/transfer-margin-between-MAs.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts +3 -3
- package/dist/types/clients/modules/withdraw-MA.simulation/types.d.ts.map +1 -1
- package/dist/types/clients/socket-client.d.ts +1 -1
- package/dist/types/clients/types.d.ts +1 -4
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/clients/api-client.ts +0 -58
- package/src/clients/modules/account/index.ts +34 -90
- package/src/clients/modules/account/types.ts +25 -24
- package/src/clients/modules/auth/types.ts +1 -2
- package/src/clients/modules/conditional-orders/types.ts +3 -3
- package/src/clients/modules/deposit-existing-MA.simulation/types.ts +3 -3
- package/src/clients/modules/edit-collateral.simulation/types.ts +4 -4
- package/src/clients/modules/markets/index.ts +1 -12
- package/src/clients/modules/owner/index.ts +0 -36
- package/src/clients/modules/transfer-MA-Pool.simulation/types.ts +3 -3
- package/src/clients/modules/transfer-margin-between-MAs.simulation/types.ts +7 -7
- package/src/clients/modules/withdraw-MA.simulation/types.ts +3 -3
- package/src/clients/types.ts +1 -4
- package/dist/clients/modules/isolated-order.simulation/index.js +0 -302
- package/dist/clients/modules/isolated-order.simulation/index.js.map +0 -1
- package/dist/clients/modules/isolated-order.simulation/types.js +0 -3
- package/dist/clients/modules/isolated-order.simulation/types.js.map +0 -1
- package/dist/clients/modules/rage-trade/index.js +0 -99
- package/dist/clients/modules/rage-trade/index.js.map +0 -1
- package/dist/clients/modules/rage-trade/types.js +0 -3
- package/dist/clients/modules/rage-trade/types.js.map +0 -1
- package/dist/clients/modules/trade.simulation/index.js +0 -331
- package/dist/clients/modules/trade.simulation/index.js.map +0 -1
- package/dist/clients/modules/trade.simulation/types.js +0 -3
- package/dist/clients/modules/trade.simulation/types.js.map +0 -1
- package/dist/clients/modules/trade.simulation/utils.js +0 -35
- package/dist/clients/modules/trade.simulation/utils.js.map +0 -1
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts +0 -24
- package/dist/types/clients/modules/isolated-order.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts +0 -44
- package/dist/types/clients/modules/isolated-order.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/rage-trade/index.d.ts +0 -9
- package/dist/types/clients/modules/rage-trade/index.d.ts.map +0 -1
- package/dist/types/clients/modules/rage-trade/types.d.ts +0 -80
- package/dist/types/clients/modules/rage-trade/types.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/index.d.ts +0 -22
- package/dist/types/clients/modules/trade.simulation/index.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/types.d.ts +0 -85
- package/dist/types/clients/modules/trade.simulation/types.d.ts.map +0 -1
- package/dist/types/clients/modules/trade.simulation/utils.d.ts +0 -8
- package/dist/types/clients/modules/trade.simulation/utils.d.ts.map +0 -1
- package/src/clients/modules/isolated-order.simulation/index.ts +0 -490
- package/src/clients/modules/isolated-order.simulation/types.ts +0 -55
- package/src/clients/modules/rage-trade/index.ts +0 -38
- package/src/clients/modules/rage-trade/types.ts +0 -91
- package/src/clients/modules/trade.simulation/index.ts +0 -534
- package/src/clients/modules/trade.simulation/types.ts +0 -98
- package/src/clients/modules/trade.simulation/utils.ts +0 -52
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/rage-trade/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wCAAwC,GAAG;IACrD,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,oBAAoB,EAAE,6BAA6B,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,wCAAwC,GAAG;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,6CAA6C,GAAG;IAC1D,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,6CAA6C,GAAG;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iCAAiC,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { EstimatedPriceParams, EstimatedPriceResult, LimitTradeMaxOrderSizeParams, LimitTradeMaxOrderSizeResult, SimulateLimitTradeEntity, SimulateTradeEntity, TradeSimulationConvertValueEstimatedPriceParams, TradeSimulationConvertValueParams, TradeSimulationConvertValueResult, TradeSimulationLoadDataParams, TradeSimulationSimulateLimitParams, TradeSimulationSimulateParams } from './types';
|
|
2
|
-
import AccountClient from '../account';
|
|
3
|
-
export default class TradeSimulationClient {
|
|
4
|
-
private marketId;
|
|
5
|
-
private accountId;
|
|
6
|
-
private loadedData;
|
|
7
|
-
private accountClient;
|
|
8
|
-
constructor(accountClient: AccountClient);
|
|
9
|
-
arm(params: TradeSimulationLoadDataParams): Promise<void>;
|
|
10
|
-
private fetchMarketData;
|
|
11
|
-
simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity;
|
|
12
|
-
getRiskMatrixElement(): number;
|
|
13
|
-
simulateLimit(params: TradeSimulationSimulateLimitParams): SimulateLimitTradeEntity;
|
|
14
|
-
getMaxAmountForLimitOrder(params: LimitTradeMaxOrderSizeParams): LimitTradeMaxOrderSizeResult;
|
|
15
|
-
convertValue(params: TradeSimulationConvertValueParams): TradeSimulationConvertValueResult;
|
|
16
|
-
convertValueEstimatedPrice(params: TradeSimulationConvertValueEstimatedPriceParams): TradeSimulationConvertValueResult;
|
|
17
|
-
customLeverage(): number | null;
|
|
18
|
-
estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult;
|
|
19
|
-
roundToBaseSpacing(amount: number, baseSpacing: number): number;
|
|
20
|
-
updatePrice(price: number): void;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACnB,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,kCAAkC,EAClC,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,YAAY,CAAC;AAYvC,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAIF;IAChB,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAMlC,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAsDjD,eAAe;IAW7B,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB;IA0IpE,oBAAoB,IAAI,MAAM;IAyB9B,aAAa,CACX,MAAM,EAAE,kCAAkC,GACzC,wBAAwB;IA0F3B,yBAAyB,CACvB,MAAM,EAAE,4BAA4B,GACnC,4BAA4B;IAoC/B,YAAY,CACV,MAAM,EAAE,iCAAiC,GACxC,iCAAiC;IAyBpC,0BAA0B,CACxB,MAAM,EAAE,+CAA+C,GACtD,iCAAiC;IAkCpC,cAAc,IAAI,MAAM,GAAG,IAAI;IAU/B,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB;IA+BlE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAc/D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAejC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
|
|
2
|
-
export type TradeSimulationLoadDataParams = {
|
|
3
|
-
marketId: MarketEntity['id'];
|
|
4
|
-
marginAccountId: MarginAccountEntity['id'];
|
|
5
|
-
};
|
|
6
|
-
export type TradeSimulationSimulateParams = {
|
|
7
|
-
amount: number;
|
|
8
|
-
fromBase?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type TradeSimulationConvertValueParams = {
|
|
11
|
-
amount: number;
|
|
12
|
-
fromBase: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type EstimatedPriceParams = {
|
|
15
|
-
amount: number;
|
|
16
|
-
};
|
|
17
|
-
export type EstimatedPriceResult = {
|
|
18
|
-
estimatedPrice: number;
|
|
19
|
-
markPrice: number;
|
|
20
|
-
};
|
|
21
|
-
export type TradeSimulationConvertValueEstimatedPriceParams = {
|
|
22
|
-
amount: number;
|
|
23
|
-
fromBase: boolean;
|
|
24
|
-
};
|
|
25
|
-
export type TradeSimulationConvertValueEstimatedPriceResult = number;
|
|
26
|
-
export type SimulateTradeFeeEntity = {
|
|
27
|
-
feeTier: number;
|
|
28
|
-
feePercentage: number;
|
|
29
|
-
rebalancingFeePercentage: number;
|
|
30
|
-
fee: number;
|
|
31
|
-
imbalancingFee: number;
|
|
32
|
-
rebalancingFee: number;
|
|
33
|
-
};
|
|
34
|
-
export type SimulateTradeEntity = {
|
|
35
|
-
liquidationPrice: number;
|
|
36
|
-
fees: number;
|
|
37
|
-
takerFeesPercentage: number;
|
|
38
|
-
feesV2: SimulateTradeFeeEntity;
|
|
39
|
-
estimatedPrice: number;
|
|
40
|
-
estimatedSlippage: number;
|
|
41
|
-
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
42
|
-
marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
|
|
43
|
-
availableMargin: number;
|
|
44
|
-
marginBalance: number;
|
|
45
|
-
requiredMargin: number;
|
|
46
|
-
snappedAmount: number;
|
|
47
|
-
snappedAmountInBase: number;
|
|
48
|
-
xpEarnRange?: {
|
|
49
|
-
min: number;
|
|
50
|
-
max: number;
|
|
51
|
-
};
|
|
52
|
-
maxSlippage: number;
|
|
53
|
-
};
|
|
54
|
-
export type TradeSimulationSimulateLimitParams = {
|
|
55
|
-
triggerPrice: number;
|
|
56
|
-
amount: number;
|
|
57
|
-
fromBase?: boolean;
|
|
58
|
-
};
|
|
59
|
-
export type SimulateLimitTradeEntity = {
|
|
60
|
-
fees: number;
|
|
61
|
-
takerFeesPercentage: number;
|
|
62
|
-
snappedAmount: number;
|
|
63
|
-
snappedAmountInBase: number;
|
|
64
|
-
estimatedPrice: number;
|
|
65
|
-
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
66
|
-
marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
|
|
67
|
-
availableMargin: number;
|
|
68
|
-
marginBalance: number;
|
|
69
|
-
requiredMargin: number;
|
|
70
|
-
xpEarnRange: {
|
|
71
|
-
min: number;
|
|
72
|
-
max: number;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export type LimitTradeMaxOrderSizeParams = {
|
|
76
|
-
triggerPrice: number;
|
|
77
|
-
};
|
|
78
|
-
export type LimitTradeMaxOrderSizeResult = {
|
|
79
|
-
maxAmountBase: number;
|
|
80
|
-
maxAmountSize: number;
|
|
81
|
-
minAmountBase: number;
|
|
82
|
-
minAmountSize: number;
|
|
83
|
-
};
|
|
84
|
-
export type TradeSimulationConvertValueResult = number;
|
|
85
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TradeSimulationState } from '@reyaxyz/common';
|
|
2
|
-
import { SimulateTradeFeeEntity } from './types';
|
|
3
|
-
export declare const computeFee: ({ tradeSimulationState, marketId, orderBase, }: {
|
|
4
|
-
marketId: number;
|
|
5
|
-
tradeSimulationState: TradeSimulationState;
|
|
6
|
-
orderBase: number;
|
|
7
|
-
}) => SimulateTradeFeeEntity;
|
|
8
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,UAAU;cAKX,MAAM;0BACM,oBAAoB;eAC/B,MAAM;MACf,sBAwCH,CAAC"}
|
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SimulateIsolatedOrderEntity,
|
|
3
|
-
IsolatedOrderSimulationConvertValueParams,
|
|
4
|
-
IsolatedOrderSimulationConvertValueResult,
|
|
5
|
-
IsolatedOrderSimulationLoadDataParams,
|
|
6
|
-
IsolatedOrderSimulationSimulateParams,
|
|
7
|
-
LeverageBoundsAndAvailableMarginResult,
|
|
8
|
-
LeverageBoundsAndAvailableMarginParams,
|
|
9
|
-
} from './types';
|
|
10
|
-
import AccountClient from '../account';
|
|
11
|
-
import {
|
|
12
|
-
amountNormalizer,
|
|
13
|
-
ExposureCommand,
|
|
14
|
-
ExposureCommandState,
|
|
15
|
-
RiskMatrix,
|
|
16
|
-
TradeSimulationState,
|
|
17
|
-
} from '@reyaxyz/common';
|
|
18
|
-
import BigNumber from 'bignumber.js';
|
|
19
|
-
import { EditCollateralAction } from '@reyaxyz/common';
|
|
20
|
-
import {
|
|
21
|
-
EstimatedPriceParams,
|
|
22
|
-
EstimatedPriceResult,
|
|
23
|
-
TradeSimulationConvertValueEstimatedPriceParams,
|
|
24
|
-
TradeSimulationConvertValueResult,
|
|
25
|
-
} from '../trade.simulation/types';
|
|
26
|
-
import { INSTANT_TRADING_RATE_XP } from '@reyaxyz/common';
|
|
27
|
-
import { computeFee } from '../trade.simulation/utils';
|
|
28
|
-
|
|
29
|
-
export default class IsolatedOrderSimulationClient {
|
|
30
|
-
private loadedData: TradeSimulationState | null = null;
|
|
31
|
-
private accountClient: AccountClient;
|
|
32
|
-
private marketId: number | null = null;
|
|
33
|
-
|
|
34
|
-
constructor(accountClient: AccountClient) {
|
|
35
|
-
// Constructor added
|
|
36
|
-
this.accountClient = accountClient;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Method to asynchronously load data based on marketId and accountId
|
|
40
|
-
async arm(params: IsolatedOrderSimulationLoadDataParams): Promise<void> {
|
|
41
|
-
this.marketId = params.marketId;
|
|
42
|
-
this.loadedData = await this.fetchMarketData(
|
|
43
|
-
params.marketId,
|
|
44
|
-
params.marginAccountId,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static genExposureCommandObject(
|
|
49
|
-
exposureCommandState: ExposureCommandState,
|
|
50
|
-
): ExposureCommand {
|
|
51
|
-
return new ExposureCommand(
|
|
52
|
-
exposureCommandState.accountId,
|
|
53
|
-
exposureCommandState.rootCollateralPoolId,
|
|
54
|
-
exposureCommandState.oraclePricePerMarket,
|
|
55
|
-
exposureCommandState.accountBalancePerAsset,
|
|
56
|
-
exposureCommandState.groupedByCollateral,
|
|
57
|
-
exposureCommandState.riskMultipliers,
|
|
58
|
-
exposureCommandState.riskMatrices,
|
|
59
|
-
exposureCommandState.exchangeInfoPerAsset,
|
|
60
|
-
exposureCommandState.positionInfoMarketConfiguration,
|
|
61
|
-
exposureCommandState.uniqueTokenAddresses,
|
|
62
|
-
exposureCommandState.uniqueQuoteCollaterals,
|
|
63
|
-
exposureCommandState.tokenMarginInfoPerAsset,
|
|
64
|
-
exposureCommandState.realizedPnLSum,
|
|
65
|
-
exposureCommandState.unrealizedPnLSum,
|
|
66
|
-
exposureCommandState.mtmRpnlSum,
|
|
67
|
-
exposureCommandState.collateralAddressToExchangePrice,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private async fetchMarketData(
|
|
72
|
-
marketId: number,
|
|
73
|
-
accountId: number,
|
|
74
|
-
): Promise<TradeSimulationState> {
|
|
75
|
-
return this.accountClient.getTransactionSimulationInitialData({
|
|
76
|
-
marginAccountId: accountId,
|
|
77
|
-
marketId: marketId,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Synchronous method to simulate operations
|
|
82
|
-
simulate(
|
|
83
|
-
params: IsolatedOrderSimulationSimulateParams,
|
|
84
|
-
): SimulateIsolatedOrderEntity {
|
|
85
|
-
if (!this.loadedData || !this.marketId) {
|
|
86
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const oraclePrice =
|
|
90
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
91
|
-
this.loadedData.marketConfiguration.market_id
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
let amount;
|
|
95
|
-
if (params.fromBase) {
|
|
96
|
-
amount = params.amount;
|
|
97
|
-
} else {
|
|
98
|
-
amount = BigNumber(params.amount).div(oraclePrice).toNumber();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const userAccountExposure =
|
|
102
|
-
IsolatedOrderSimulationClient.genExposureCommandObject(
|
|
103
|
-
this.loadedData.exposureDataAccount,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const passivePoolExposure =
|
|
107
|
-
IsolatedOrderSimulationClient.genExposureCommandObject(
|
|
108
|
-
this.loadedData.exposureDataPassivePool,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const slippage = passivePoolExposure.getSlippage(
|
|
112
|
-
BigNumber(amount).negated().toNumber(),
|
|
113
|
-
this.loadedData.marketConfiguration,
|
|
114
|
-
this.loadedData.marketStorage,
|
|
115
|
-
);
|
|
116
|
-
const estimatedPrice = ExposureCommand.calculateEstimatedPrice(
|
|
117
|
-
oraclePrice,
|
|
118
|
-
slippage,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const amountSize = estimatedPrice * amount;
|
|
122
|
-
|
|
123
|
-
const feesV2 = computeFee({
|
|
124
|
-
tradeSimulationState: this.loadedData,
|
|
125
|
-
marketId: this.marketId,
|
|
126
|
-
orderBase: amount,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
/*
|
|
130
|
-
amount of margin in rUSD terms that needs to be transferred from the source account to the destination account,
|
|
131
|
-
this value is equal to absolute size in rUSD terms / leverage
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
const requiredMargin = BigNumber(amountSize)
|
|
135
|
-
.abs()
|
|
136
|
-
.div(BigNumber(params.isolatedPositionLeverage))
|
|
137
|
-
.toNumber();
|
|
138
|
-
|
|
139
|
-
const editCollateralActions: EditCollateralAction[] =
|
|
140
|
-
userAccountExposure.getEditCollateralActionsToCoverMargin(requiredMargin);
|
|
141
|
-
|
|
142
|
-
const newMarginInfoSource =
|
|
143
|
-
userAccountExposure.getUsdNodeMarginInfoPostEditCollaterals(
|
|
144
|
-
editCollateralActions,
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
/*
|
|
148
|
-
* Compute Isolated Account Liquidation Margin Requirement Post Transfer + Trade
|
|
149
|
-
* */
|
|
150
|
-
|
|
151
|
-
const isolatedLMR = this.calculateIsolatedLMR(amountSize);
|
|
152
|
-
|
|
153
|
-
/*
|
|
154
|
-
* margin balance of the destination account is the requiredMargin which is expected to be transferred
|
|
155
|
-
* to the destination account that performs the isolated trade
|
|
156
|
-
* the liquidation price in this case is trying to estimate what the liquidation price would be all else equal for
|
|
157
|
-
* the market where the trade is being made by the isolated account that is going to be created as part of isolated
|
|
158
|
-
* trade operation
|
|
159
|
-
* */
|
|
160
|
-
const liquidationPrice = ExposureCommand.calculateLiquidation(
|
|
161
|
-
requiredMargin,
|
|
162
|
-
isolatedLMR,
|
|
163
|
-
oraclePrice,
|
|
164
|
-
amount,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
// todo: p1: margin ratio seems to be wrong on ui
|
|
168
|
-
const marginRatio = ExposureCommand.getMarginRatio(newMarginInfoSource);
|
|
169
|
-
|
|
170
|
-
const marginRatioHealth = ExposureCommand.evaluateHealthStatus(
|
|
171
|
-
marginRatio * 100,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const baseSpacing = amountNormalizer(
|
|
175
|
-
this.loadedData.marketConfiguration.base_spacing,
|
|
176
|
-
).toNumber();
|
|
177
|
-
|
|
178
|
-
const snappedAmountInBase = this.roundToBaseSpacing(amount, baseSpacing);
|
|
179
|
-
const snappedAmount = snappedAmountInBase * estimatedPrice;
|
|
180
|
-
const xpEarnRangeMin = Math.round(
|
|
181
|
-
Math.abs(snappedAmount) / INSTANT_TRADING_RATE_XP,
|
|
182
|
-
);
|
|
183
|
-
const xpEarnRangeMax = Math.round(
|
|
184
|
-
(100 * Math.abs(snappedAmount)) / INSTANT_TRADING_RATE_XP,
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
estimatedPrice: estimatedPrice,
|
|
189
|
-
estimatedSlippage: slippage * 100,
|
|
190
|
-
fees: feesV2.fee,
|
|
191
|
-
takerFeesPercentage: feesV2.feePercentage,
|
|
192
|
-
feesV2,
|
|
193
|
-
liquidationPrice: liquidationPrice.toNumber(),
|
|
194
|
-
marginRatio: marginRatio * 100,
|
|
195
|
-
marginRatioHealth: marginRatioHealth,
|
|
196
|
-
snappedAmount,
|
|
197
|
-
snappedAmountInBase,
|
|
198
|
-
requiredMargin: requiredMargin,
|
|
199
|
-
editCollateralActions: editCollateralActions,
|
|
200
|
-
xpEarnRange: {
|
|
201
|
-
min: xpEarnRangeMin,
|
|
202
|
-
max: xpEarnRangeMax,
|
|
203
|
-
},
|
|
204
|
-
maxSlippage: 1,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
convertValue(
|
|
209
|
-
params: IsolatedOrderSimulationConvertValueParams,
|
|
210
|
-
): IsolatedOrderSimulationConvertValueResult {
|
|
211
|
-
if (!this.loadedData) {
|
|
212
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (!params.fromBase)
|
|
216
|
-
return BigNumber(params.amount)
|
|
217
|
-
.div(
|
|
218
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
219
|
-
this.loadedData.marketConfiguration.market_id
|
|
220
|
-
],
|
|
221
|
-
)
|
|
222
|
-
.toNumber();
|
|
223
|
-
else
|
|
224
|
-
return BigNumber(params.amount)
|
|
225
|
-
.times(
|
|
226
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
227
|
-
this.loadedData.marketConfiguration.market_id
|
|
228
|
-
],
|
|
229
|
-
)
|
|
230
|
-
.toNumber();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
convertValueEstimatedPrice(
|
|
234
|
-
params: TradeSimulationConvertValueEstimatedPriceParams,
|
|
235
|
-
): TradeSimulationConvertValueResult {
|
|
236
|
-
if (!this.loadedData) {
|
|
237
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const passivePoolExposure = new ExposureCommand(
|
|
241
|
-
this.loadedData.exposureDataPassivePool.accountId,
|
|
242
|
-
this.loadedData.exposureDataPassivePool.rootCollateralPoolId,
|
|
243
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket,
|
|
244
|
-
this.loadedData.exposureDataPassivePool.accountBalancePerAsset,
|
|
245
|
-
this.loadedData.exposureDataPassivePool.groupedByCollateral,
|
|
246
|
-
this.loadedData.exposureDataPassivePool.riskMultipliers,
|
|
247
|
-
this.loadedData.exposureDataPassivePool.riskMatrices,
|
|
248
|
-
this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,
|
|
249
|
-
this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,
|
|
250
|
-
this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,
|
|
251
|
-
this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,
|
|
252
|
-
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
253
|
-
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
254
|
-
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
255
|
-
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
256
|
-
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const amountForSlippage = params.fromBase
|
|
260
|
-
? params.amount
|
|
261
|
-
: BigNumber(params.amount)
|
|
262
|
-
.div(
|
|
263
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
264
|
-
this.loadedData.marketConfiguration.market_id
|
|
265
|
-
],
|
|
266
|
-
)
|
|
267
|
-
.toNumber();
|
|
268
|
-
|
|
269
|
-
const slippage = passivePoolExposure.getSlippage(
|
|
270
|
-
BigNumber(amountForSlippage).negated().toNumber(),
|
|
271
|
-
this.loadedData.marketConfiguration,
|
|
272
|
-
this.loadedData.marketStorage,
|
|
273
|
-
);
|
|
274
|
-
const estimatedPrice = ExposureCommand.calculateEstimatedPrice(
|
|
275
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
276
|
-
this.loadedData.marketConfiguration.market_id
|
|
277
|
-
],
|
|
278
|
-
slippage,
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
if (!params.fromBase)
|
|
282
|
-
return BigNumber(params.amount).div(estimatedPrice).toNumber();
|
|
283
|
-
else return BigNumber(params.amount).times(estimatedPrice).toNumber();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
customLeverage(): number | null {
|
|
287
|
-
if (!this.loadedData) {
|
|
288
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
289
|
-
}
|
|
290
|
-
const { customLeverage } = this.loadedData;
|
|
291
|
-
|
|
292
|
-
return customLeverage;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
estimatedPrice(params: EstimatedPriceParams): EstimatedPriceResult {
|
|
296
|
-
if (!this.loadedData) {
|
|
297
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const passivePoolExposure = new ExposureCommand(
|
|
301
|
-
this.loadedData.exposureDataPassivePool.accountId,
|
|
302
|
-
this.loadedData.exposureDataPassivePool.rootCollateralPoolId,
|
|
303
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket,
|
|
304
|
-
this.loadedData.exposureDataPassivePool.accountBalancePerAsset,
|
|
305
|
-
this.loadedData.exposureDataPassivePool.groupedByCollateral,
|
|
306
|
-
this.loadedData.exposureDataPassivePool.riskMultipliers,
|
|
307
|
-
this.loadedData.exposureDataPassivePool.riskMatrices,
|
|
308
|
-
this.loadedData.exposureDataPassivePool.exchangeInfoPerAsset,
|
|
309
|
-
this.loadedData.exposureDataPassivePool.positionInfoMarketConfiguration,
|
|
310
|
-
this.loadedData.exposureDataPassivePool.uniqueTokenAddresses,
|
|
311
|
-
this.loadedData.exposureDataPassivePool.uniqueQuoteCollaterals,
|
|
312
|
-
this.loadedData.exposureDataPassivePool.tokenMarginInfoPerAsset,
|
|
313
|
-
this.loadedData.exposureDataPassivePool.realizedPnLSum,
|
|
314
|
-
this.loadedData.exposureDataPassivePool.unrealizedPnLSum,
|
|
315
|
-
this.loadedData.exposureDataPassivePool.mtmRpnlSum,
|
|
316
|
-
this.loadedData.exposureDataPassivePool.collateralAddressToExchangePrice,
|
|
317
|
-
);
|
|
318
|
-
const slippage = passivePoolExposure.getSlippage(
|
|
319
|
-
BigNumber(params.amount).negated().toNumber(),
|
|
320
|
-
this.loadedData.marketConfiguration,
|
|
321
|
-
this.loadedData.marketStorage,
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
const price =
|
|
325
|
-
this.loadedData.exposureDataAccount.oraclePricePerMarket[
|
|
326
|
-
this.loadedData.marketConfiguration.market_id
|
|
327
|
-
];
|
|
328
|
-
|
|
329
|
-
const estimatedPrice = ExposureCommand.calculateEstimatedPrice(
|
|
330
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
331
|
-
this.loadedData.marketConfiguration.market_id
|
|
332
|
-
],
|
|
333
|
-
slippage,
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
return {
|
|
337
|
-
estimatedPrice,
|
|
338
|
-
markPrice: price,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
roundToBaseSpacing(amount: number, baseSpacing: number): number {
|
|
343
|
-
const snappedAmount = BigNumber(amount)
|
|
344
|
-
.abs()
|
|
345
|
-
.dividedBy(baseSpacing)
|
|
346
|
-
.integerValue(BigNumber.ROUND_FLOOR)
|
|
347
|
-
.multipliedBy(baseSpacing)
|
|
348
|
-
.toNumber();
|
|
349
|
-
|
|
350
|
-
if (amount < 0) {
|
|
351
|
-
return -snappedAmount;
|
|
352
|
-
}
|
|
353
|
-
return snappedAmount;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
amountToSnappedAmount(
|
|
357
|
-
amountInRusd: number,
|
|
358
|
-
spotPrice: number,
|
|
359
|
-
baseSpacing: number,
|
|
360
|
-
): number {
|
|
361
|
-
const amountInBase = BigNumber(amountInRusd)
|
|
362
|
-
.div(BigNumber(spotPrice))
|
|
363
|
-
.toNumber();
|
|
364
|
-
|
|
365
|
-
return this.roundToBaseSpacing(amountInBase, baseSpacing) * spotPrice;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
calculateIsolatedLMR(isolatedExposure: number): number {
|
|
369
|
-
// todo: p2: consider removing the need to load the entire data just to get a few vars to calc leverage bounds
|
|
370
|
-
if (!this.loadedData) {
|
|
371
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (!this.loadedData.marketStorage) {
|
|
375
|
-
throw new Error('Market storage not loaded');
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// todo: p2: carefully test
|
|
379
|
-
const marketRiskMatrix =
|
|
380
|
-
this.loadedData.exposureDataAccount.riskMatrices.find(
|
|
381
|
-
(riskMatrix: RiskMatrix) => {
|
|
382
|
-
return (
|
|
383
|
-
riskMatrix.risk_block_id ===
|
|
384
|
-
BigNumber(
|
|
385
|
-
String(this.loadedData?.marketStorage.risk_block_id),
|
|
386
|
-
).toNumber()
|
|
387
|
-
);
|
|
388
|
-
},
|
|
389
|
-
);
|
|
390
|
-
|
|
391
|
-
if (!marketRiskMatrix) {
|
|
392
|
-
throw new Error('Failed to load risk matrix');
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const marketDiagonalRiskParam =
|
|
396
|
-
marketRiskMatrix.matrix[
|
|
397
|
-
this.loadedData.marketConfiguration.risk_matrix_index
|
|
398
|
-
][this.loadedData.marketConfiguration.risk_matrix_index];
|
|
399
|
-
const isolatedRiskMatrix: BigNumber[][] = [[marketDiagonalRiskParam]];
|
|
400
|
-
const isolatedFilledExposures: BigNumber[] = [BigNumber(isolatedExposure)];
|
|
401
|
-
|
|
402
|
-
return ExposureCommand.computeLiquidationMarginRequirement(
|
|
403
|
-
isolatedRiskMatrix,
|
|
404
|
-
isolatedFilledExposures,
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
leverageBoundsAndAvailableMargin({
|
|
409
|
-
amountTradedInRusd,
|
|
410
|
-
}: LeverageBoundsAndAvailableMarginParams): LeverageBoundsAndAvailableMarginResult {
|
|
411
|
-
if (!this.loadedData) {
|
|
412
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const spotPrice =
|
|
416
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[
|
|
417
|
-
this.loadedData.marketConfiguration.market_id
|
|
418
|
-
];
|
|
419
|
-
const baseSpacing = amountNormalizer(
|
|
420
|
-
this.loadedData.marketConfiguration.base_spacing,
|
|
421
|
-
).toNumber();
|
|
422
|
-
const snappedAmountInRusd = this.amountToSnappedAmount(
|
|
423
|
-
amountTradedInRusd,
|
|
424
|
-
spotPrice,
|
|
425
|
-
baseSpacing,
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
/*
|
|
429
|
-
todo: p2: consider introducing buffer to the leverage (e.g. to account for the effect of trade on upnl
|
|
430
|
-
and actually depending on the size of the trade the estimated price would change -> different upnl
|
|
431
|
-
as upnl is calculated against oracle prioce + rpnl is also affected through the fees
|
|
432
|
-
* once the trader knows their trade size (in base & rusd terms), they should be able to toggle isolated trade flow
|
|
433
|
-
* which will prompt the user to choose a desired leverage value
|
|
434
|
-
* 0.1 can be hardcoded to be the min bound
|
|
435
|
-
* to get the maximum bound we need to calculate leverage that can be achieved when IMR is reached for position
|
|
436
|
-
* with 1 rUSD exposure in the market -> max leverage = 1/IMR
|
|
437
|
-
* */
|
|
438
|
-
|
|
439
|
-
// set max bound
|
|
440
|
-
|
|
441
|
-
const lmrUnitExposure = this.calculateIsolatedLMR(1);
|
|
442
|
-
|
|
443
|
-
const imrUnitExposure: BigNumber = amountNormalizer(
|
|
444
|
-
String(this.loadedData.exposureDataAccount.riskMultipliers.im_multiplier),
|
|
445
|
-
).multipliedBy(lmrUnitExposure);
|
|
446
|
-
|
|
447
|
-
const maxBound = BigNumber(1).dividedBy(imrUnitExposure).toNumber();
|
|
448
|
-
|
|
449
|
-
// set min bound
|
|
450
|
-
|
|
451
|
-
const userAccountExposure =
|
|
452
|
-
IsolatedOrderSimulationClient.genExposureCommandObject(
|
|
453
|
-
this.loadedData.exposureDataAccount,
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
/*
|
|
457
|
-
max amount of margin in rUSD terms that can be transferred from the source account to the destination account
|
|
458
|
-
that performs the isolated position trade
|
|
459
|
-
*/
|
|
460
|
-
|
|
461
|
-
const availableMargin =
|
|
462
|
-
userAccountExposure.getUsdNodeMarginInfo.initialDelta;
|
|
463
|
-
|
|
464
|
-
const minBound = BigNumber(snappedAmountInRusd)
|
|
465
|
-
.abs()
|
|
466
|
-
.dividedBy(availableMargin)
|
|
467
|
-
.toNumber();
|
|
468
|
-
|
|
469
|
-
if (minBound > maxBound) {
|
|
470
|
-
throw Error('Min leverage bound higher than max');
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
return {
|
|
474
|
-
minBound: minBound,
|
|
475
|
-
maxBound: maxBound,
|
|
476
|
-
availableMargin: availableMargin,
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
updatePrice(price: number): void {
|
|
481
|
-
if (!this.loadedData || !this.marketId) {
|
|
482
|
-
throw new Error('Data not loaded. Call arm() first.');
|
|
483
|
-
}
|
|
484
|
-
// update price
|
|
485
|
-
const marketId = this.marketId;
|
|
486
|
-
this.loadedData.exposureDataPassivePool.oraclePricePerMarket[marketId] =
|
|
487
|
-
price;
|
|
488
|
-
this.loadedData.exposureDataAccount.oraclePricePerMarket[marketId] = price;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MarginAccountEntity,
|
|
3
|
-
MarketEntity,
|
|
4
|
-
EditCollateralAction,
|
|
5
|
-
} from '@reyaxyz/common';
|
|
6
|
-
import { SimulateTradeFeeEntity } from '../trade.simulation/types';
|
|
7
|
-
|
|
8
|
-
export type IsolatedOrderSimulationLoadDataParams = {
|
|
9
|
-
marketId: MarketEntity['id'];
|
|
10
|
-
marginAccountId: MarginAccountEntity['id'];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type IsolatedOrderSimulationSimulateParams = {
|
|
14
|
-
amount: number; // position size in rUSD / base terms, + for long | - for short
|
|
15
|
-
isolatedPositionLeverage: number; // leverage chosen for isolated position trade
|
|
16
|
-
fromBase?: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type IsolatedOrderSimulationConvertValueParams = {
|
|
20
|
-
amount: number;
|
|
21
|
-
fromBase: boolean;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type SimulateIsolatedOrderEntity = {
|
|
25
|
-
liquidationPrice: number;
|
|
26
|
-
fees: number;
|
|
27
|
-
takerFeesPercentage: number;
|
|
28
|
-
feesV2: SimulateTradeFeeEntity;
|
|
29
|
-
estimatedPrice: number;
|
|
30
|
-
estimatedSlippage: number;
|
|
31
|
-
marginRatio: MarginAccountEntity['marginRatioPercentage'];
|
|
32
|
-
marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
|
|
33
|
-
snappedAmount: number;
|
|
34
|
-
snappedAmountInBase: number;
|
|
35
|
-
requiredMargin: number;
|
|
36
|
-
editCollateralActions: EditCollateralAction[];
|
|
37
|
-
maxSlippage: number;
|
|
38
|
-
xpEarnRange?: {
|
|
39
|
-
min: number;
|
|
40
|
-
max: number;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type IsolatedOrderSimulationConvertValueResult = number;
|
|
45
|
-
|
|
46
|
-
export type LeverageBoundsAndAvailableMarginResult = {
|
|
47
|
-
minBound: number;
|
|
48
|
-
maxBound: number;
|
|
49
|
-
availableMargin: number;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type LeverageBoundsAndAvailableMarginParams = {
|
|
53
|
-
// Note, this amount is not expected to be snapped
|
|
54
|
-
amountTradedInRusd: number;
|
|
55
|
-
};
|