Skip to content

Commit

Permalink
feat: price equivalents in breakeven calculator (chrisleekr#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
rando128 authored Feb 8, 2023
1 parent d517846 commit 2450f23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 6 additions & 8 deletions public/js/CoinWrapperBuySignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,10 @@ class CoinWrapperBuySignal extends React.Component {
const sellGridTrade = symbolConfiguration.sell.gridTrade;

const currentPrice = parseFloat(buy.currentPrice);

const lastBuyPrice = parseFloat(sell.lastBuyPrice);

if (
isNaN(lastBuyPrice) ||
sellGridTrade.length !== 1 ||
currentPrice >= lastBuyPrice
)
return '';
if (isNaN(lastBuyPrice) || sellGridTrade.length !== 1) return '';

const totalBoughtQty = gridTrade
.filter(trade => trade.executed)
Expand All @@ -376,7 +372,7 @@ class CoinWrapperBuySignal extends React.Component {
(symbolConfiguration.sell.currentGridTradeIndex >= 0) &
(sellGridTrade.length === 1);

return (nextGridAmount > 0) & !hasManualTrade & isSingleSellGrid ? (
return !hasManualTrade && isSingleSellGrid ? (
<React.Fragment key={'coin-wrapper-buy-next-grid-row-' + symbol}>
<div className='coin-info-column coin-info-column-price'>
<span className='coin-info-label'>
Expand All @@ -388,7 +384,9 @@ class CoinWrapperBuySignal extends React.Component {
/>
</span>
<span className='coin-info-value'>
{nextGridAmount.toFixed(precision)} {quoteAsset}
{nextGridAmount > 0
? `${nextGridAmount.toFixed(precision)} ${quoteAsset}`
: 'N/A'}
</span>
</div>
</React.Fragment>
Expand Down
15 changes: 10 additions & 5 deletions public/js/SymbolGridCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ class SymbolGridCalculator extends React.Component {
const buyTrigger =
parseFloat(this.state.scenario.buyTrigger) || currentBuyPercentage;

const buyPriceEquivalent = lastBuyPrice * parseFloat(buyTrigger);

const sellTrigger =
parseFloat(this.state.scenario.sellTrigger) || currentSellPercentage;

const priceEquivalent = currentPrice * parseFloat(sellTrigger);
const sellPriceEquivalent = currentPrice * parseFloat(sellTrigger);

const differenceFromCurrentPrice =
(100 * (buyTrigger * lastBuyPrice - currentPrice)) / currentPrice;
Expand Down Expand Up @@ -152,9 +154,12 @@ class SymbolGridCalculator extends React.Component {
onChange={this.handleInputChange}
/>
<Form.Text className='ml-2 text-muted'>
Equivalent market price:{' '}
{buyPriceEquivalent.toFixed(precision)} <br />
Difference from current price:{' '}
{differenceFromCurrentPrice.toFixed(3)}% — Buy trigger with
current price: {currentBuyPercentage.toFixed(3)}
{differenceFromCurrentPrice.toFixed(3)}%<br />
Buy trigger with current price:{' '}
{currentBuyPercentage.toFixed(3)}
</Form.Text>
</Form.Group>
<Form.Group className='mb-2'>
Expand All @@ -174,7 +179,7 @@ class SymbolGridCalculator extends React.Component {
/>
<Form.Text className='ml-2 text-muted'>
{currentSellPercentage
? `Equivalent market price: ${priceEquivalent.toFixed(
? `Equivalent market price: ${sellPriceEquivalent.toFixed(
precision
)}`
: '\u00A0'}
Expand All @@ -196,7 +201,7 @@ class SymbolGridCalculator extends React.Component {
{' '}
{sellTrigger === 1
? ' - '
: breakevenAmount.toFixed(2)}{' '}
: breakevenAmount.toFixed(precision)}{' '}
{quoteAsset}
</code>
, would allow you to break-even if the market price rebounds
Expand Down

0 comments on commit 2450f23

Please sign in to comment.