nextBestBuyAmountCalculationConditions = data => {
  const {
    symbolConfiguration: {
      buy: {
        currentGridTradeIndex: currentBuyGridTradeIndex,
        gridTrade: buyGridTrade
      },
      sell: {
        currentGridTradeIndex: currentSellGridTradeIndex,
        gridTrade: sellGridTrade
      }
    }
  } = data;

  // Find the first non-executed trade.
  //    -1 means all buy trades are executed.
  //    0 or more means the index of trades for first non-executed trade.
  const firstNonExecutedTradeIndex = buyGridTrade.findIndex(
    trade => trade.executed === false
  );
  // Find the first executed trade.
  //    -1 means no buy trade is executed.
  //    0 or more means the index of trades for first executed trade.
  const firstExecutedTradeIndex = buyGridTrade.findIndex(
    trade => trade.executed === true
  );
  const hasObviousManualTrade =
    // If there is non-executed trade and does not have executed trade
    (firstNonExecutedTradeIndex !== -1 && firstExecutedTradeIndex === -1) ||
    // Or there is non-executed trade and the non-executed trade index is lower than the executed trade index
    // or the index of current buy grid trade.
    // It usually happens when the last buy price is set manually.
    (firstNonExecutedTradeIndex !== -1 &&
      firstNonExecutedTradeIndex < firstExecutedTradeIndex) ||
    (firstNonExecutedTradeIndex !== -1 &&
      firstNonExecutedTradeIndex < currentBuyGridTradeIndex);

  // Check whether it's a single sell grid trade and whether it's executed.
  const isSingleSellGrid =
    currentSellGridTradeIndex >= 0 && sellGridTrade.length === 1;

  // Return true if there is no manual trade and it has executed single sell grid trade.
  // Store the manual trade and single trade status for the frontend
  return {
    hasObviousManualTrade,
    isSingleSellGrid
  };
}
Determine the grid state for nextBestBuyAmount calculation
- isSingleSellGrid
- hasObviousManualTrade