@imbingox/acex 0.3.0-beta.4 → 0.3.0-beta.5
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/docs/api.md
CHANGED
|
@@ -618,7 +618,9 @@ const btcPosition = client.account.getPosition({
|
|
|
618
618
|
const risk = client.account.getRiskSnapshot("main-binance");
|
|
619
619
|
```
|
|
620
620
|
|
|
621
|
-
所有数量字段(`free` / `used` / `total` / `size` / `entryPrice` / `
|
|
621
|
+
所有数量字段(`free` / `used` / `total` / `size` / `entryPrice` / `netEquity` / `riskEquity` / ...)都是 `BigNumber`。
|
|
622
|
+
|
|
623
|
+
`RiskSnapshot.netEquity` 表示不含风控折算的净资产价值;`riskEquity` 表示抵押系数或清算阈值折算后的风控净权益。Binance 使用 `actualEquity` / `accountEquity` 映射这两个字段;Juplend 使用 `totalCollateralUsd - totalDebtUsd` / `Σ(suppliedValue × liquidationThreshold) - totalDebtUsd`。
|
|
622
624
|
|
|
623
625
|
> **注意**:`AccountSnapshot.balances` 是 `Record<string, BalanceSnapshot>`,不是数组;需要数组视图用 `getBalances()`。
|
|
624
626
|
|
|
@@ -1222,9 +1224,10 @@ interface PositionSnapshot {
|
|
|
1222
1224
|
interface RiskSnapshot {
|
|
1223
1225
|
accountId: string;
|
|
1224
1226
|
venue: Venue;
|
|
1225
|
-
|
|
1227
|
+
netEquity?: BigNumber;
|
|
1228
|
+
riskEquity?: BigNumber;
|
|
1226
1229
|
riskRatio?: BigNumber;
|
|
1227
|
-
|
|
1230
|
+
riskLeverage?: BigNumber;
|
|
1228
1231
|
initialMargin?: BigNumber;
|
|
1229
1232
|
maintenanceMargin?: BigNumber;
|
|
1230
1233
|
exchangeTs?: number;
|
package/package.json
CHANGED
|
@@ -38,6 +38,7 @@ interface BinancePapiBalance {
|
|
|
38
38
|
|
|
39
39
|
interface BinancePapiAccount {
|
|
40
40
|
accountEquity?: string;
|
|
41
|
+
actualEquity?: string;
|
|
41
42
|
totalEquity?: string;
|
|
42
43
|
accountInitialMargin?: string;
|
|
43
44
|
totalInitialMargin?: string;
|
|
@@ -292,12 +293,14 @@ function mapAccountRisk(
|
|
|
292
293
|
const riskRatio = uniMmr
|
|
293
294
|
? new BigNumber(1).dividedBy(uniMmr).toString(10)
|
|
294
295
|
: undefined;
|
|
295
|
-
const
|
|
296
|
-
const
|
|
296
|
+
const netEquity = firstString(input.actualEquity);
|
|
297
|
+
const riskEquity = firstString(input.accountEquity, input.totalEquity);
|
|
298
|
+
const riskLeverage = calculateRiskLeverage(riskEquity, positions);
|
|
297
299
|
const risk: RawRiskUpdate = {
|
|
298
|
-
|
|
300
|
+
netEquity,
|
|
301
|
+
riskEquity,
|
|
299
302
|
riskRatio,
|
|
300
|
-
|
|
303
|
+
riskLeverage,
|
|
301
304
|
initialMargin: firstString(
|
|
302
305
|
input.accountInitialMargin,
|
|
303
306
|
input.totalInitialMargin,
|
|
@@ -311,9 +314,10 @@ function mapAccountRisk(
|
|
|
311
314
|
};
|
|
312
315
|
|
|
313
316
|
if (
|
|
314
|
-
!risk.
|
|
317
|
+
!risk.netEquity &&
|
|
318
|
+
!risk.riskEquity &&
|
|
315
319
|
!risk.riskRatio &&
|
|
316
|
-
!risk.
|
|
320
|
+
!risk.riskLeverage &&
|
|
317
321
|
!risk.initialMargin &&
|
|
318
322
|
!risk.maintenanceMargin
|
|
319
323
|
) {
|
|
@@ -323,16 +327,16 @@ function mapAccountRisk(
|
|
|
323
327
|
return risk;
|
|
324
328
|
}
|
|
325
329
|
|
|
326
|
-
function
|
|
327
|
-
|
|
330
|
+
function calculateRiskLeverage(
|
|
331
|
+
riskEquity: string | undefined,
|
|
328
332
|
positions: BinancePapiUmPosition[],
|
|
329
333
|
): string | undefined {
|
|
330
|
-
if (!
|
|
334
|
+
if (!riskEquity) {
|
|
331
335
|
return undefined;
|
|
332
336
|
}
|
|
333
337
|
|
|
334
|
-
const
|
|
335
|
-
if (!
|
|
338
|
+
const riskEquityValue = new BigNumber(riskEquity);
|
|
339
|
+
if (!riskEquityValue.isFinite() || riskEquityValue.isZero()) {
|
|
336
340
|
return undefined;
|
|
337
341
|
}
|
|
338
342
|
|
|
@@ -348,7 +352,7 @@ function calculateActualLeverage(
|
|
|
348
352
|
|
|
349
353
|
return grossExposure.isZero()
|
|
350
354
|
? undefined
|
|
351
|
-
: grossExposure.dividedBy(
|
|
355
|
+
: grossExposure.dividedBy(riskEquityValue).toString(10);
|
|
352
356
|
}
|
|
353
357
|
|
|
354
358
|
function mapUmPosition(
|
|
@@ -222,7 +222,8 @@ function buildRisk(input: {
|
|
|
222
222
|
: undefined;
|
|
223
223
|
|
|
224
224
|
return {
|
|
225
|
-
|
|
225
|
+
netEquity: totalCollateralUsd.minus(totalDebtUsd).toString(10),
|
|
226
|
+
riskEquity: weightedLiquidationValueUsd.minus(totalDebtUsd).toString(10),
|
|
226
227
|
riskRatio,
|
|
227
228
|
receivedAt: input.receivedAt,
|
|
228
229
|
lending: {
|
package/src/adapters/types.ts
CHANGED
|
@@ -119,9 +119,10 @@ export interface RawPositionUpdate {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface RawRiskUpdate {
|
|
122
|
-
|
|
122
|
+
netEquity?: string;
|
|
123
|
+
riskEquity?: string;
|
|
123
124
|
riskRatio?: string;
|
|
124
|
-
|
|
125
|
+
riskLeverage?: string;
|
|
125
126
|
initialMargin?: string;
|
|
126
127
|
maintenanceMargin?: string;
|
|
127
128
|
exchangeTs?: number;
|
|
@@ -589,18 +589,22 @@ export class AccountManagerImpl
|
|
|
589
589
|
return {
|
|
590
590
|
accountId,
|
|
591
591
|
venue,
|
|
592
|
-
|
|
593
|
-
input.
|
|
594
|
-
? previous?.
|
|
595
|
-
: new BigNumber(input.
|
|
592
|
+
netEquity:
|
|
593
|
+
input.netEquity === undefined
|
|
594
|
+
? previous?.netEquity
|
|
595
|
+
: new BigNumber(input.netEquity),
|
|
596
|
+
riskEquity:
|
|
597
|
+
input.riskEquity === undefined
|
|
598
|
+
? previous?.riskEquity
|
|
599
|
+
: new BigNumber(input.riskEquity),
|
|
596
600
|
riskRatio:
|
|
597
601
|
input.riskRatio === undefined
|
|
598
602
|
? previous?.riskRatio
|
|
599
603
|
: new BigNumber(input.riskRatio),
|
|
600
|
-
|
|
601
|
-
input.
|
|
602
|
-
? previous?.
|
|
603
|
-
: new BigNumber(input.
|
|
604
|
+
riskLeverage:
|
|
605
|
+
input.riskLeverage === undefined
|
|
606
|
+
? previous?.riskLeverage
|
|
607
|
+
: new BigNumber(input.riskLeverage),
|
|
604
608
|
initialMargin:
|
|
605
609
|
input.initialMargin === undefined
|
|
606
610
|
? previous?.initialMargin
|
package/src/types/account.ts
CHANGED
|
@@ -91,9 +91,10 @@ export interface PositionSnapshot {
|
|
|
91
91
|
export interface RiskSnapshot {
|
|
92
92
|
accountId: string;
|
|
93
93
|
venue: Venue;
|
|
94
|
-
|
|
94
|
+
netEquity?: BigNumber;
|
|
95
|
+
riskEquity?: BigNumber;
|
|
95
96
|
riskRatio?: BigNumber;
|
|
96
|
-
|
|
97
|
+
riskLeverage?: BigNumber;
|
|
97
98
|
initialMargin?: BigNumber;
|
|
98
99
|
maintenanceMargin?: BigNumber;
|
|
99
100
|
exchangeTs?: number;
|