@gainsnetwork/sdk 0.2.12-rc11 → 0.2.12-rc12
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/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/trade/spread.d.ts +5 -2
- package/lib/trade/spread.js +16 -2
- package/package.json +1 -1
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_PROTECTION_CLOSE_FACTOR = exports.delistedGroupsIxs = exports.delistedPairIxs = exports.stockSplits = exports.tickerChanges = exports.getAssetClassFromGroupIndex = exports.pairs = void 0;
|
|
3
|
+
exports.DEFAULT_CUMULATIVE_FACTOR = exports.DEFAULT_PROTECTION_CLOSE_FACTOR = exports.delistedGroupsIxs = exports.delistedPairIxs = exports.stockSplits = exports.tickerChanges = exports.getAssetClassFromGroupIndex = exports.pairs = void 0;
|
|
4
4
|
const CRYPTO = "crypto";
|
|
5
5
|
const FOREX = "forex";
|
|
6
6
|
const STOCKS = "stocks";
|
|
@@ -300,3 +300,4 @@ exports.delistedPairIxs = new Set([
|
|
|
300
300
|
]);
|
|
301
301
|
exports.delistedGroupsIxs = new Set([6, 7]);
|
|
302
302
|
exports.DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
|
|
303
|
+
exports.DEFAULT_CUMULATIVE_FACTOR = 1;
|
package/lib/trade/spread.d.ts
CHANGED
|
@@ -5,11 +5,14 @@ export type SpreadContext = {
|
|
|
5
5
|
isPnlPositive?: boolean;
|
|
6
6
|
protectionCloseFactor?: number;
|
|
7
7
|
protectionCloseFactorBlocks?: number;
|
|
8
|
+
cumulativeFactor?: number;
|
|
8
9
|
createdBlock?: number;
|
|
9
10
|
liquidationParams?: LiquidationParams | undefined;
|
|
10
|
-
currentBlock
|
|
11
|
-
contractsVersion
|
|
11
|
+
currentBlock?: number | undefined;
|
|
12
|
+
contractsVersion?: ContractsVersion | undefined;
|
|
12
13
|
};
|
|
13
14
|
export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
15
|
+
export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
16
|
+
export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
14
17
|
export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, pairDepth: PairDepth | undefined, oiWindowsSettings?: OiWindowsSettings | undefined, oiWindows?: OiWindows | undefined, spreadCtx?: SpreadContext | undefined) => number;
|
|
15
18
|
export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined) => number;
|
package/lib/trade/spread.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getProtectionCloseFactor = void 0;
|
|
3
|
+
exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.getProtectionCloseFactor = void 0;
|
|
4
4
|
const oiWindows_1 = require("./oiWindows");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const types_1 = require("../contracts/types");
|
|
@@ -24,6 +24,17 @@ const getProtectionCloseFactor = (spreadCtx) => {
|
|
|
24
24
|
return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
|
|
25
25
|
};
|
|
26
26
|
exports.getProtectionCloseFactor = getProtectionCloseFactor;
|
|
27
|
+
const getCumulativeFactor = (spreadCtx) => {
|
|
28
|
+
if (spreadCtx === undefined || spreadCtx.cumulativeFactor === undefined) {
|
|
29
|
+
return constants_1.DEFAULT_CUMULATIVE_FACTOR;
|
|
30
|
+
}
|
|
31
|
+
return spreadCtx.cumulativeFactor;
|
|
32
|
+
};
|
|
33
|
+
exports.getCumulativeFactor = getCumulativeFactor;
|
|
34
|
+
const getLegacyFactor = (spreadCtx) => {
|
|
35
|
+
return (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2 ? 1 : 2;
|
|
36
|
+
};
|
|
37
|
+
exports.getLegacyFactor = getLegacyFactor;
|
|
27
38
|
const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
|
|
28
39
|
if (pairSpreadP === undefined) {
|
|
29
40
|
return 0;
|
|
@@ -50,7 +61,10 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
|
|
|
50
61
|
return pairSpreadP / 2;
|
|
51
62
|
}
|
|
52
63
|
return ((0, exports.getSpreadP)(pairSpreadP) +
|
|
53
|
-
((activeOi + (collateral * leverage) / 2) /
|
|
64
|
+
((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
|
|
65
|
+
onePercentDepth /
|
|
66
|
+
100 /
|
|
67
|
+
(0, exports.getLegacyFactor)(spreadCtx)) *
|
|
54
68
|
(0, exports.getProtectionCloseFactor)(spreadCtx));
|
|
55
69
|
};
|
|
56
70
|
exports.getSpreadWithPriceImpactP = getSpreadWithPriceImpactP;
|