@reyaxyz/api-sdk 0.151.21 → 0.151.22
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 -1
- package/dist/clients/modules/depth-chart.simulation/index.js +13 -11
- package/dist/clients/modules/depth-chart.simulation/index.js.map +1 -1
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/modules/depth-chart.simulation/index.ts +18 -10
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |  |
|
|
10
10
|
|
|
@@ -80,28 +80,30 @@ var DepthChartSimulationClient = /** @class */ (function () {
|
|
|
80
80
|
}
|
|
81
81
|
// Adjust initial step size based on max exposures
|
|
82
82
|
var maxExposure = Math.max(this.loadedData.maxOrderSizeLong, Math.abs(this.loadedData.maxOrderSizeShort));
|
|
83
|
-
var
|
|
83
|
+
var maxPriceImpact = 0.035; // 3.5%
|
|
84
|
+
var maxSize = (0, bignumber_js_1.default)(this.loadedData.netExposure)
|
|
85
|
+
.plus((0, bignumber_js_1.default)(maxExposure)
|
|
86
|
+
.times((0, common_1.amountNormalizer)(this.loadedData.depthFactor))
|
|
87
|
+
.times(maxPriceImpact)
|
|
88
|
+
.div(1 + maxPriceImpact))
|
|
89
|
+
.toNumber();
|
|
90
|
+
var maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;
|
|
91
|
+
var initialStepSize = maxDisplayedSize / ((params === null || params === void 0 ? void 0 : params.initialSteps) || 100);
|
|
84
92
|
var step = (params === null || params === void 0 ? void 0 : params.step) || initialStepSize;
|
|
85
|
-
var percentageChange = (params === null || params === void 0 ? void 0 : params.percentageChange) || 50;
|
|
86
|
-
var currentStep = step;
|
|
87
93
|
var leftResults = [];
|
|
88
94
|
var rightResults = [];
|
|
89
95
|
// Simplified loop conditions to focus on reaching maxExposure limits efficiently
|
|
90
96
|
var delta = 0;
|
|
91
|
-
while (Math.abs(delta) <
|
|
92
|
-
delta -=
|
|
97
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
98
|
+
delta -= step;
|
|
93
99
|
var result = this.calculate(delta);
|
|
94
|
-
if (result.priceImpact >= percentageChange)
|
|
95
|
-
break;
|
|
96
100
|
leftResults.push(result);
|
|
97
101
|
// Adjust currentStep based on your liquidity model or other factors
|
|
98
102
|
}
|
|
99
103
|
delta = 0; // Reset for the right side
|
|
100
|
-
while (Math.abs(delta) <
|
|
101
|
-
delta +=
|
|
104
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
105
|
+
delta += step;
|
|
102
106
|
var result = this.calculate(delta);
|
|
103
|
-
if (result.priceImpact >= percentageChange)
|
|
104
|
-
break;
|
|
105
107
|
rightResults.push(result);
|
|
106
108
|
// Adjust currentStep similarly
|
|
107
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,0CAAyE;AACzE,8DAAqC;AAErC;IAIE,oCAAY,QAAkB;QAHtB,aAAQ,GAAkB,IAAI,CAAC;QAC/B,eAAU,GAAgC,IAAI,CAAC;QAGrD,oBAAoB;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,uDAAuD;IACjD,wCAAG,GAAT,UAAU,MAAqC;;;;;;wBAC7C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAEhC,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAA;;wBAAzD,GAAK,UAAU,GAAG,SAAuC,CAAC;;;;;KAC3D;IAEa,k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AI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAClE,CACF,CACF,CACF,CAAC;QAEF,IAAM,IAAI,GAAG,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC;QAEnE,OAAO;YACL,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE;YAC9B,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;YAC1B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;YAC9C,WAAW,EAAE,0BAA0B,CAAC,8BAA8B,CACpE,IAAI,CAAC,UAAU,CAAC,SAAS,EACzB,YAAY,CAAC,QAAQ,EAAE,CACxB;SACF,CAAC;IACJ,CAAC;IAEM,yDAA8B,GAArC,UACE,KAAa,EACb,cAAsB;QAEtB,iCAAiC;QACjC,IAAM,eAAe,GAAG,cAAc,GAAG,KAAK,CAAC;QAE/C,IAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACrD,kCAAkC;QAClC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;IACtD,CAAC;IACH,iCAAC;AAAD,CAAC,AAvHD,IAuHC","sourcesContent":["import {\n GetDepthChartParams,\n GetDepthChartResult,\n DepthSimulationLoadDataParams,\n SimulateDepthEntity,\n} from './types';\n\nimport LpClient from '../lp';\nimport { DepthSimulationState, amountNormalizer } from '@reyaxyz/common';\nimport BigNumber from 'bignumber.js';\n\nexport default class DepthChartSimulationClient {\n private marketId: number | null = null;\n private loadedData: DepthSimulationState | null = null;\n private lpClient: LpClient;\n constructor(lpClient: LpClient) {\n // Constructor added\n this.lpClient = lpClient;\n }\n\n // Method to asynchronously load data based on marketId\n async arm(params: DepthSimulationLoadDataParams): Promise<void> {\n this.marketId = params.marketId;\n\n this.loadedData = await this.fetchPoolData(this.marketId);\n }\n\n private async fetchPoolData(marketId: number): Promise<DepthSimulationState> {\n return this.lpClient.getLpPoolDepthChartSimulationData({\n marketId: marketId,\n });\n }\n\n getDepthChart(params?: GetDepthChartParams): GetDepthChartResult {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n // Adjust initial step size based on max exposures\n const maxExposure = Math.max(\n this.loadedData.maxOrderSizeLong,\n Math.abs(this.loadedData.maxOrderSizeShort),\n );\n\n const maxPriceImpact = 0.035; // 3.5%\n const maxSize = BigNumber(this.loadedData.netExposure)\n .plus(\n BigNumber(maxExposure)\n .times(amountNormalizer(this.loadedData.depthFactor))\n .times(maxPriceImpact)\n .div(1 + maxPriceImpact),\n )\n .toNumber();\n\n const maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;\n\n const initialStepSize = maxDisplayedSize / (params?.initialSteps || 100);\n\n const step = params?.step || initialStepSize;\n\n const leftResults: SimulateDepthEntity[] = [];\n const rightResults: SimulateDepthEntity[] = [];\n\n // Simplified loop conditions to focus on reaching maxExposure limits efficiently\n let delta = 0;\n while (Math.abs(delta) < maxDisplayedSize) {\n delta -= step;\n const result = this.calculate(delta);\n leftResults.push(result);\n // Adjust currentStep based on your liquidity model or other factors\n }\n\n delta = 0; // Reset for the right side\n while (Math.abs(delta) < maxDisplayedSize) {\n delta += step;\n const result = this.calculate(delta);\n rightResults.push(result);\n // Adjust currentStep similarly\n }\n\n return {\n leftChart: leftResults.reverse(),\n rightChart: rightResults,\n };\n }\n\n private calculate(delta: number): SimulateDepthEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call arm() first.');\n }\n\n const n0Delta = BigNumber(this.loadedData.netExposure).plus(delta);\n const maxOrderSize = n0Delta.gt(0)\n ? BigNumber(this.loadedData.maxOrderSizeLong)\n : BigNumber(this.loadedData.maxOrderSizeShort);\n\n const currentPrice = BigNumber(this.loadedData.spotPrice).times(\n BigNumber(1).minus(\n n0Delta.div(\n BigNumber(n0Delta).plus(\n maxOrderSize.times(amountNormalizer(this.loadedData.depthFactor)),\n ),\n ),\n ),\n );\n\n const size = BigNumber(delta).div(this.loadedData.spotPrice).abs();\n\n return {\n price: currentPrice.toNumber(),\n totalSize: size.toNumber(),\n totalCost: size.times(currentPrice).toNumber(),\n priceImpact: DepthChartSimulationClient.calculatePriceChangePercentage(\n this.loadedData.spotPrice,\n currentPrice.toNumber(),\n ),\n };\n }\n\n static calculatePriceChangePercentage(\n price: number,\n estimatedPrice: number,\n ): number {\n // Calculate the price difference\n const priceDifference = estimatedPrice - price;\n\n const absPriceDifference = Math.abs(priceDifference);\n // Calculate the percentage change\n return (absPriceDifference / Math.abs(price)) * 100;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,MAAM,OAAO,CAAC;AAI7B,MAAM,CAAC,OAAO,OAAO,0BAA0B;IAC7C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,QAAQ,CAAW;gBACf,QAAQ,EAAE,QAAQ;IAMxB,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAMjD,aAAa;IAM3B,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,mBAAmB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/depth-chart.simulation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,MAAM,OAAO,CAAC;AAI7B,MAAM,CAAC,OAAO,OAAO,0BAA0B;IAC7C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,QAAQ,CAAW;gBACf,QAAQ,EAAE,QAAQ;IAMxB,GAAG,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YAMjD,aAAa;IAM3B,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,mBAAmB;IAqDhE,OAAO,CAAC,SAAS;IAiCjB,MAAM,CAAC,8BAA8B,CACnC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,GACrB,MAAM;CAQV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.151.
|
|
3
|
+
"version": "0.151.22",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ws": "^8.16.0"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "9d56102759478c904bd1d7248257b11427259018",
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@reyaxyz/database": "0.123.6"
|
|
48
48
|
}
|
|
@@ -41,31 +41,39 @@ export default class DepthChartSimulationClient {
|
|
|
41
41
|
this.loadedData.maxOrderSizeLong,
|
|
42
42
|
Math.abs(this.loadedData.maxOrderSizeShort),
|
|
43
43
|
);
|
|
44
|
-
const initialStepSize = maxExposure / (params?.initialSteps || 100) || 10; // Customize this based on your needs
|
|
45
44
|
|
|
46
|
-
const
|
|
47
|
-
const
|
|
45
|
+
const maxPriceImpact = 0.035; // 3.5%
|
|
46
|
+
const maxSize = BigNumber(this.loadedData.netExposure)
|
|
47
|
+
.plus(
|
|
48
|
+
BigNumber(maxExposure)
|
|
49
|
+
.times(amountNormalizer(this.loadedData.depthFactor))
|
|
50
|
+
.times(maxPriceImpact)
|
|
51
|
+
.div(1 + maxPriceImpact),
|
|
52
|
+
)
|
|
53
|
+
.toNumber();
|
|
54
|
+
|
|
55
|
+
const maxDisplayedSize = maxExposure < maxSize ? maxExposure : maxSize;
|
|
48
56
|
|
|
49
|
-
const
|
|
57
|
+
const initialStepSize = maxDisplayedSize / (params?.initialSteps || 100);
|
|
58
|
+
|
|
59
|
+
const step = params?.step || initialStepSize;
|
|
50
60
|
|
|
51
61
|
const leftResults: SimulateDepthEntity[] = [];
|
|
52
62
|
const rightResults: SimulateDepthEntity[] = [];
|
|
53
63
|
|
|
54
64
|
// Simplified loop conditions to focus on reaching maxExposure limits efficiently
|
|
55
65
|
let delta = 0;
|
|
56
|
-
while (Math.abs(delta) <
|
|
57
|
-
delta -=
|
|
66
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
67
|
+
delta -= step;
|
|
58
68
|
const result = this.calculate(delta);
|
|
59
|
-
if (result.priceImpact >= percentageChange) break;
|
|
60
69
|
leftResults.push(result);
|
|
61
70
|
// Adjust currentStep based on your liquidity model or other factors
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
delta = 0; // Reset for the right side
|
|
65
|
-
while (Math.abs(delta) <
|
|
66
|
-
delta +=
|
|
74
|
+
while (Math.abs(delta) < maxDisplayedSize) {
|
|
75
|
+
delta += step;
|
|
67
76
|
const result = this.calculate(delta);
|
|
68
|
-
if (result.priceImpact >= percentageChange) break;
|
|
69
77
|
rightResults.push(result);
|
|
70
78
|
// Adjust currentStep similarly
|
|
71
79
|
}
|