@bancor/carbon-sdk
Advanced tools
Comparing version 0.0.86-DEV to 0.0.87-DEV
@@ -241,10 +241,9 @@ import { d as Decimal, t as tenPow, f as formatUnits, p as parseUnits, B as BigNumber, e as trimDecimal, m as mulDiv } from './numerics.js'; | ||
) { | ||
const totalPriceRange = sellPriceHigh.minus(buyPriceLow); | ||
const spread = totalPriceRange.mul(spreadPercentage).div(100); | ||
const buyPriceHigh = sellPriceHigh.minus(spread); | ||
const sellPriceLow = buyPriceLow.plus(spread); | ||
const spreadFactor = spreadPercentage.plus(1); | ||
const buyPriceHigh = sellPriceHigh.div(spreadFactor); | ||
const sellPriceLow = buyPriceLow.mul(spreadFactor); | ||
// buy marginal price is the market price minus 0.5 spread. But it can never be lower than buyPriceLow | ||
const buyPriceMarginal = Decimal.max(buyPriceLow, marketPrice.minus(spread.div(2))); | ||
const buyPriceMarginal = Decimal.max(buyPriceLow, marketPrice.div(spreadFactor.sqrt())); | ||
// sell marginal price is the market price plus 0.5 spread. But ir can never be higher than sellPriceHigh | ||
const sellPriceMarginal = Decimal.min(sellPriceHigh, marketPrice.plus(spread.div(2))); | ||
const sellPriceMarginal = Decimal.min(sellPriceHigh, marketPrice.mul(spreadFactor.sqrt())); | ||
return { | ||
@@ -255,3 +254,2 @@ buyPriceHigh, | ||
sellPriceMarginal, | ||
spread, | ||
}; | ||
@@ -268,12 +266,12 @@ } | ||
return new Decimal(0); | ||
const { buyPriceHigh, spread } = calculateOverlappingPriceRanges(buyPriceLow, sellPriceHigh, marketPrice, spreadPercentage); | ||
const { buyPriceHigh, sellPriceMarginal, buyPriceMarginal } = calculateOverlappingPriceRanges(buyPriceLow, sellPriceHigh, marketPrice, spreadPercentage); | ||
// if buy range takes the entire range then there's zero sell budget | ||
if (marketPrice.minus(spread.div(2)).gte(buyPriceHigh)) | ||
if (sellPriceMarginal.gte(sellPriceHigh)) | ||
return new Decimal(0); | ||
// if buy range is zero there's no point to this call | ||
if (marketPrice.minus(spread.div(2)).lte(buyPriceLow)) { | ||
if (buyPriceMarginal.lte(buyPriceLow)) { | ||
throw new Error('calculateOverlappingSellBudget called with zero buy range and non zero buy budget'); | ||
} | ||
const buyPriceRange = buyPriceHigh.minus(buyPriceLow); | ||
const buyLowRange = marketPrice.minus(buyPriceLow).minus(spread.div(2)); | ||
const buyLowRange = buyPriceMarginal.minus(buyPriceLow); | ||
const buyLowBudgetRatio = buyLowRange.div(buyPriceRange); | ||
@@ -296,12 +294,12 @@ const buyOrderYint = new Decimal(buyBudget).div(buyLowBudgetRatio); | ||
return new Decimal(0); | ||
const { sellPriceLow, spread } = calculateOverlappingPriceRanges(buyPriceLow, sellPriceHigh, marketPrice, spreadPercentage); | ||
const { sellPriceLow, sellPriceMarginal, buyPriceMarginal } = calculateOverlappingPriceRanges(buyPriceLow, sellPriceHigh, marketPrice, spreadPercentage); | ||
// if sell range takes the entire range then there's zero buy budget | ||
if (marketPrice.plus(spread.div(2)).lte(sellPriceLow)) | ||
if (buyPriceMarginal.lte(buyPriceLow)) | ||
return new Decimal(0); | ||
// if sell range is zero there's no point to this call | ||
if (marketPrice.plus(spread.div(2)).gte(sellPriceHigh)) { | ||
if (sellPriceMarginal.gte(sellPriceHigh)) { | ||
throw new Error('calculateOverlappingBuyBudget called with zero sell range and non zero sell budget'); | ||
} | ||
const sellPriceRange = sellPriceHigh.minus(sellPriceLow); | ||
const sellHighRange = sellPriceHigh.minus(marketPrice).minus(spread.div(2)); | ||
const sellHighRange = sellPriceHigh.minus(sellPriceMarginal); | ||
const sellHighBudgetRatio = sellHighRange.div(sellPriceRange); | ||
@@ -308,0 +306,0 @@ const sellOrderYint = new Decimal(sellBudget).div(sellHighBudgetRatio); |
@@ -45,3 +45,2 @@ import { BigNumber, BigNumberish, Decimal } from '../utils/numerics'; | ||
sellPriceMarginal: Decimal; | ||
spread: Decimal; | ||
}; | ||
@@ -48,0 +47,0 @@ export declare function calculateOverlappingSellBudget(buyPriceLow: Decimal, // in quote tkn per 1 base tkn |
@@ -5,3 +5,3 @@ { | ||
"source": "src/index.ts", | ||
"version": "0.0.86-DEV", | ||
"version": "0.0.87-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", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1054537
24477