From f1f34e3b3210a994844f1efd466a2b99acf18048 Mon Sep 17 00:00:00 2001 From: Doron Zavelevsky Date: Sun, 3 Dec 2023 09:21:39 +0000 Subject: [PATCH] fixing bad calculation in spread factor --- package.json | 2 +- src/strategy-management/utils.ts | 2 +- tests/toolkit.spec.ts | 6 +++--- tests/utils.spec.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8c5df28..b012cd1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@bancor/carbon-sdk", "type": "module", "source": "src/index.ts", - "version": "0.0.87-DEV", + "version": "0.0.88-DEV", "description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades", "main": "dist/index.js", "module": "dist/index.js", diff --git a/src/strategy-management/utils.ts b/src/strategy-management/utils.ts index 9aa1655..284d038 100644 --- a/src/strategy-management/utils.ts +++ b/src/strategy-management/utils.ts @@ -324,7 +324,7 @@ export function calculateOverlappingPriceRanges( sellPriceLow: Decimal; sellPriceMarginal: Decimal; } { - const spreadFactor = spreadPercentage.plus(1); + const spreadFactor = spreadPercentage.div(100).plus(1); const buyPriceHigh = sellPriceHigh.div(spreadFactor); const sellPriceLow = buyPriceLow.mul(spreadFactor); diff --git a/tests/toolkit.spec.ts b/tests/toolkit.spec.ts index 1cb1dbf..4f0fba1 100644 --- a/tests/toolkit.spec.ts +++ b/tests/toolkit.spec.ts @@ -106,7 +106,7 @@ describe('Toolkit', () => { '1500', '2000', '1845', - '0.01' + '1' ); expect(result).to.deep.equal({ buyPriceHigh: '1980.198019801980198019', @@ -122,7 +122,7 @@ describe('Toolkit', () => { '1500', '2000', '1845', - '0.01', + '1', '100' ); expect(result).to.equal('0.024939801923642185'); @@ -134,7 +134,7 @@ describe('Toolkit', () => { '1500', '2000', '1845', - '0.01', + '1', '0.024939801923642185' ); expect(result).to.equal('100.999999'); diff --git a/tests/utils.spec.ts b/tests/utils.spec.ts index e833371..4e620b4 100644 --- a/tests/utils.spec.ts +++ b/tests/utils.spec.ts @@ -26,7 +26,7 @@ describe('utils', () => { buyPriceLow: new Decimal('1500'), sellPriceHigh: new Decimal('2000'), marketPrice: new Decimal('1845'), - spreadPercentage: new Decimal('0.01'), + spreadPercentage: new Decimal('1'), buyBudget: new Decimal('100'), buyPriceHigh: new Decimal( '1980.19801980198019801980198019801980198019801980198019801980198019801980198019801980198019801980198'