calculateNextBestBuyAmount = (
  data,
  { currentPrice, lastBuyPrice, sellTrigger }
) => {
  const {
    symbolConfiguration: {
      buy: { gridTrade: buyGridTrade }
    }
  } = data;

  const { hasObviousManualTrade, isSingleSellGrid } =
    nextBestBuyAmountCalculationConditions(data);

  const totalBought = buyGridTrade
    .filter(trade => trade.executed)
    .map(order => ({
      cummulativeQuoteQty: parseFloat(order.executedOrder.cummulativeQuoteQty),
      executedQty: parseFloat(order.executedOrder.executedQty)
    }))
    .reduce(
      (acc, o) => {
        acc.amount += o.cummulativeQuoteQty;
        acc.qty += o.executedQty;
        return acc;
      },
      {
        amount: 0,
        qty: 0
      }
    );

  const buyTrigger = 1 + (currentPrice - lastBuyPrice) / lastBuyPrice;

  let amount = null;

  if (!hasObviousManualTrade && isSingleSellGrid) {
    amount =
      (totalBought.amount -
        totalBought.qty * buyTrigger * lastBuyPrice * sellTrigger) /
      (sellTrigger - 1);
  }

  const calculation = {
    currentPrice,
    lastBuyPrice,
    totalBoughtAmount: totalBought.amount,
    totalBoughtQty: totalBought.qty,
    buyTrigger,
    sellTrigger,
    hasObviousManualTrade,
    isSingleSellGrid
  };

  return { amount, calculation };
}
Calculate nextBestBuyAmount

@param {*} currentPrice
@param {*} lastBuyPrice
@param {*} sellTrigger