Ho scritto questo listato in Java Script ES5,  e non vorrei programmare nelle funzionalita’ moderne di ES6.  Vorrei un’analisi di questo listato in lingua italiana, in particolare segnalando 1 ridondanza di codice oppure di controlli logici, 2 ottimizzazioni, 3 compattazioni, 4 ricerca di maggiore efficienza e velocita’ di esecuzione del codice. Inoltre per ogni punto da 1 a 4 se vorrai darmi un suggerimento specifico sara’ gradito. var CONST = {
    ORDER_SIDE: 'BID',
    SIZE: 1,
    MAX_OPERATIONS: 8,
    STAY_AT_LEVEL_BID: 6,
    STAY_AT_LEVEL_ASK: 6,
    SECONDS: 5,
    MONITORING_MODE: 'yourLevel' // Può essere '1Level' o 'yourLevel'
};

var separator = "---------------------------------------------------\r\n";

var lookup = {
    BID: { side: 'Bid', level: CONST.STAY_AT_LEVEL_BID },
    ASK: { side: 'Ask', level: CONST.STAY_AT_LEVEL_ASK }
};

function formatMessage(type, data) {
    var messages = {
        "Initialization Complete": function() {
            return "Inizializzazione completata: \nBid Price 0: " + UserContext.prices.bid.current + "\nAsk Price 0: " + UserContext.prices.ask.current + "\n";
        },
        "Order Action": function() {
            return 'Ordine ' + data.action + ': ' + data.order.OrderCode + "\n";
        },
        "Price Variation": function() {
            return 'Livello da ' + data.lastLevel + " all'attuale livello " + data.priceLevel + "\n";
        }
    };
    return messages[type] ? messages[type]() : "";
}

var BookUtils = {
    getSideData: function (book, side) {
        return side === 'Bid' ? book.Bid : book.Ask;
    },

  BookData: function (book, side, type, level) {
    return this.getSideData(book, side)[type](level);
},

    getBookState: function (book) {
        var bidSideData = book.Bid;
        var askSideData = book.Ask;
        return {
            bidPrice: bidSideData.Price(0),
            bidQuantity: bidSideData.Quantity(0),
            askPrice: askSideData.Price(0),
            askQuantity: askSideData.Quantity(0)
        };
    }
};

var OrderUtils = {
    execOrder: function (side, stock, price, size) {
        return side === 'BID' ? OrderManager.Buy(stock, price, size) : OrderManager.Sell(stock, price, size);
    },

    updateOrderContext: function (order, side, price) {
        UserContext.order.current = order;
        UserContext.prices[side.toLowerCase()].oldLevel = price;
        return order;
    },

    procModOrder: function (side, stock, price) {
        var currentOrder = UserContext.order.current;
        if (currentOrder && currentOrder.Price === price) {
            return currentOrder;
        }
        var order = currentOrder
            ? OrderManager.Modify(currentOrder.OrderCode, price)
            : this.execOrder(side, stock, price, CONST.SIZE);
        return this.updateOrderContext(order, side, price);
    },

    delOrder: function (orderCode) {
        return OrderManager.Delete(orderCode);
    }
};

var Helper = {
    PriceDirection: function (targetPrice, oldPrice) {
        return targetPrice > oldPrice ? 1 : (targetPrice < oldPrice ? -1 : 0);
    },

    formatState: function (bookState) {
        var header = "Bid Price \tBid Quant.   \tAsk Price \tAsk Quant. \r\n";
        var data = bookState.bidPrice + "\t\t" + bookState.bidQuantity + "\t\t" + bookState.askPrice + "\t\t" + bookState.askQuantity + "\r\n";
        var opCount = "Numero Operazione: " + UserContext.status.numOperazione + "\r\n";
        return separator + header + separator + data + separator + opCount + separator;
    },

    logAction: function (actionType, data) {
        var message = formatMessage(actionType, data) + this.formatState(BookUtils.getBookState(UserContext.book));
        Log(message);
    },

    logPriceChange: function (currentPrice, previousPrice, currentTime) {
        Log(separator +
            "ULTIMO PREZZO: " + currentPrice + ", " +
            "Precedente: " + previousPrice + ", " +
            "Ora: " + currentTime + "\r\n" +
            separator);
    }
};

function InitTradeContext(book, initialBidPrice, initialAskPrice) {
    this.book = book;
    this.order = { current: null, modified: false };
    this.status = { run: true, secondCount: 0, numOperazione: 1 };
    this.prices = { bid: { current: initialBidPrice, oldLevel: 0 }, ask: { current: initialAskPrice, oldLevel: 0 } };
    this.lastPrice = null;
    this.initialPriceLevel = lookup[CONST.ORDER_SIDE].level;
}

function getTargetLevel(side, priceLevel) {
    var targetLevel = lookup[side.toUpperCase()].level - 1;
    return CONST.MONITORING_MODE === '1Level' ? priceLevel - 1 : targetLevel;
}

function PriceUpdate(side, book, priceLevel) {
    var sideUpper = side.toUpperCase();
    var sideLower = side.toLowerCase();
    var targetPriceLevel = getTargetLevel(side, priceLevel);
    var sideData = BookUtils.getSideData(book, lookup[sideUpper].side);
    var targetPrice = sideData.Price(targetPriceLevel);
    var userPrices = UserContext.prices[sideLower];
    var oldPrice = userPrices.oldLevel;

    if (targetPrice !== oldPrice) {
        var newOrder = OrderUtils.procModOrder(side, stock, targetPrice);
        if (newOrder) {
            userPrices.current = targetPrice;
            Helper.logAction("Price Variation", {
                order: newOrder,
                lastLevel: priceLevel + Helper.PriceDirection(targetPrice, oldPrice),
                priceLevel: targetPriceLevel
            });
            UserContext.status.secondCount = 0;
            UserContext.status.numOperazione++;
        }
    }
}

function DetectPriceChange(side, book) {
    var sideUpper = side.toUpperCase();
    var sideLookup = lookup[sideUpper];
    PriceUpdate(sideUpper, book, sideLookup.level);
}

function checkOps() {
    var currentOrder = UserContext.order.current;
    if (UserContext.status.numOperazione >= CONST.MAX_OPERATIONS && currentOrder) {
        Helper.logAction("Order Deleted", {
            order: OrderUtils.delOrder(currentOrder.OrderCode)
        });
        Log("Ordine cancellato: " + currentOrder.OrderCode);
        return !(UserContext.status.run = false); 
    }
    return false;
}

function ManageCycle(priceLevel) {
    var status = UserContext.status;
    var currentOrder = UserContext.order.current;
    if (!status.run || checkOps()) return;
    if (status.secondCount >= CONST.SECONDS || (priceLevel !== undefined && priceLevel !== UserContext.lastProcessedPriceLevel)) {
        DetectPriceChange(CONST.ORDER_SIDE, UserContext.book);
        UserContext.lastProcessedPriceLevel = priceLevel;
    }
}

function SetupTradeContext() {
    var book = Book(ps);
    var prices = BookUtils.getBookState(book);
    UserContext = new InitTradeContext(book, prices.bidPrice, prices.askPrice);
    Helper.logAction("Initialization Complete");
    ManageCycle(UserContext.initialPriceLevel);
}

function updatePrice() {
    var currentPrice = Val(ps, "LAST");
    if (UserContext.lastPrice !== currentPrice) {
        Helper.logPriceChange(currentPrice, UserContext.lastPrice, Now().ToString("HH:mm:ss.ff"));
        UserContext.lastPrice = currentPrice;
    }
}

function MarketEvent() {
    if (!UserContext.status.run) return;
    var eventType = SystemContext.EventType;
    var book = UserContext.book || Book(ps);

    switch (eventType) {
        case TSEventType.Time:
            UserContext.status.secondCount++;
            ManageCycle();
            break;
        case TSEventType.Price:
            updatePrice();
            break;
    }
}

if (SystemContext.IsFirst) {
    SetupTradeContext();
}

MarketEvent();