calculateGridTradeProfit = (
  buyGridTrade = [],
  sellGridTrade = [],
  stopLossOrder = {},
  manualTrade = []
) => {
  const buyGridTradeQuoteQty =
    _.isEmpty(buyGridTrade) === false
      ? buyGridTrade.reduce(
          (acc, t) =>
            acc +
            (t.executed
              ? parseFloat(t.executedOrder?.cummulativeQuoteQty || 0)
              : 0),
          0
        )
      : 0;

  const buyManualQuoteQty =
    _.isEmpty(manualTrade) === false
      ? manualTrade.reduce(
          (acc, t) =>
            acc +
            (t.side.toLowerCase() === 'buy'
              ? parseFloat(t.cummulativeQuoteQty || 0)
              : 0),
          0
        )
      : 0;

  const sellGridTradeQuoteQty =
    _.isEmpty(sellGridTrade) === false
      ? sellGridTrade.reduce(
          (acc, t) =>
            acc +
            (t.executed
              ? parseFloat(t.executedOrder?.cummulativeQuoteQty || 0)
              : 0),
          0
        )
      : 0;

  const sellManualQuoteQty =
    _.isEmpty(manualTrade) === false
      ? manualTrade.reduce(
          (acc, t) =>
            acc +
            (t.side.toLowerCase() === 'sell'
              ? parseFloat(t.cummulativeQuoteQty || 0)
              : 0),
          0
        )
      : 0;

  const stopLossQuoteQty = parseFloat(stopLossOrder?.cummulativeQuoteQty || 0);

  const totalBuyQuoteQty = buyGridTradeQuoteQty + buyManualQuoteQty;
  const totalSellQuoteQty =
    sellGridTradeQuoteQty + sellManualQuoteQty + stopLossQuoteQty;

  const profit = totalSellQuoteQty - totalBuyQuoteQty;

  const profitPercentage =
    profit !== 0 && totalBuyQuoteQty !== 0
      ? (profit / totalBuyQuoteQty) * 100
      : 0;

  const buyGridTradeExecuted =
    _.isEmpty(buyGridTrade) === false
      ? buyGridTrade.some(t => t.executed === true)
      : false;

  const allBuyGridTradeExecuted =
    _.isEmpty(buyGridTrade) === false
      ? buyGridTrade.every(t => t.executed === true)
      : false;

  const sellGridTradeExecuted =
    _.isEmpty(sellGridTrade) === false
      ? sellGridTrade.some(t => t.executed === true)
      : false;

  const allSellGridTradeExecuted =
    _.isEmpty(sellGridTrade) === false
      ? sellGridTrade.every(t => t.executed === true)
      : false;

  return {
    buyGridTradeExecuted,
    sellGridTradeExecuted,
    allExecuted: allBuyGridTradeExecuted && allSellGridTradeExecuted,
    totalBuyQuoteQty,
    totalSellQuoteQty,
    buyGridTradeQuoteQty,
    buyManualQuoteQty,
    sellGridTradeQuoteQty,
    sellManualQuoteQty,
    stopLossQuoteQty,
    profit,
    profitPercentage
  };
}
Calculate grid trade profit

@param {*} buyGridTrade
@param {*} sellGridTrade
@param {*} stopLossOrder
@param {*} manualTrade

@returns