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.
Ho scritto questo listato in JavaScript ES5 e preferirei non utilizzare le funzionalità moderne di ES6. Vorrei un’analisi di questo listato in lingua italiana, con particolare attenzione ai seguenti punti  e lasciando stare considerazioni su var sideUpper, toUpperCase sideLower e sideUpper che gia’ conosco var CONFIG = {
    ORDER_SIDE: 'BID',
    SIZE: 1,
    MAX_OPERATIONS: 8,
    LEVELS: {
        BID: 6, // stay at level
        ASK: 6
    },
    SECONDS: 5,
    MONITORING_MODE: 'MONITORA_yourlevel' // or 'MONITORA_1Level'
};

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

var lookup = {
    BID: { side: 'BID', level: CONFIG.LEVELS.BID },
    ASK: { side: 'ASK', level: CONFIG.LEVELS.ASK }
};

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

    getData: function (book, side, type, level) {
        var sideData = this.getSideData(book, side);
        return type === 'Price' ? sideData.Price(level) : sideData.Quantity(level);
    },
    
    getBookState: function (book) {
        var bid = book.Bid;
        var ask = book.Ask;
        return {
            bidPrice: bid.Price(0),
            bidQuantity: bid.Quantity(0),
            askPrice: ask.Price(0),
            askQuantity: ask.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;
    },

    processOrModOrder: function (side, stock, price) {
        var currentOrder = UserContext.order.current;
        if (currentOrder) {
            if (currentOrder.Price === price) {
                return currentOrder;
            } else {
                var orderToUpdate = OrderManager.Modify(currentOrder.OrderCode, price);
                return this.updateOrderContext(orderToUpdate, side, price);
            }
        } else {
            var newOrder = this.execOrder(side, stock, price, CONFIG.SIZE);
            return this.updateOrderContext(newOrder, side, price);
        }
    },

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

var Helper = {
    cachedPriceDirections: {},

    priceDirection: function (targetPrice, oldPrice) {
        return targetPrice > oldPrice ? 1 : (targetPrice < oldPrice ? -1 : 0);
    },

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

    log: function (type, data) {
        var message = "";
        if (type === 'action') {
            message = getActionMessage(data.actionType, data.payload) + 
                      this.formatState(BookUtils.getBookState(UserContext.book));
        } else if (type === 'message') {
            message = data + "\r\n" + separator;
        } else if (type === 'priceChange') {
            message = formatPriceChange(data);
        }
        Log(separator + message);
    }
};

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

function getActionMessage(actionType, data) {
    return actionMessages[actionType] ? actionMessages[actionType](data , "") : "";
}

function formatPriceChange(data) {
    return "ULTIMO PREZZO: " + data.currentPrice + ", " +
           "Precedente: " + data.previousPrice + ", " +
           "Ora: " + data.currentTime + "\r\n" + separator;
}

function initializeTradeContext(book) {
    this.book = book;
    this.order = { current: null, modified: false };
    this.status = { run: true, secondCount: 0, numOperazione: 1 };
    this.prices = {
        bid: { current: BookUtils.getData(book, 'BID', 'Price', 0), oldLevel: 0 },
        ask: { current: BookUtils.getData(book, 'ASK', 'Price', 0), oldLevel: 0 }
    };
    this.initialPriceLevel = lookup[CONFIG.ORDER_SIDE].level;
}

function getTargetPriceLevel(side, priceLevel) {
    return (CONFIG.MONITORING_MODE === 'MONITORA_1Level' ? priceLevel : CONFIG.LEVELS[side]) - 1;
}

function priceUpdate(side, book) {
    var sideLC = side.toLowerCase();
    var priceData = UserContext.prices[sideLC];
    var lookupData = lookup[side];
    var targetPriceLevel = getTargetPriceLevel(side, lookupData.level);
    var targetPrice = BookUtils.getData(book, lookupData.side, 'Price', targetPriceLevel);
    var oldPrice = priceData.oldLevel;

    if (targetPrice !== oldPrice) {
        var newOrder = OrderUtils.processOrModOrder(side, stock, targetPrice);
        if (newOrder) {
            priceData.current = targetPrice;

            Helper.log('action', { 
                actionType: "Price Variation", 
                payload: { 
                    order: newOrder, 
                    lastLevel: lookupData.level + Helper.priceDirection(targetPrice, oldPrice), 
                    priceLevel: targetPriceLevel 
                }
            });
            UserContext.status.secondCount = 0;
            UserContext.status.numOperazione++;
        }
    }
}

function checkOps() {
    var status = UserContext.status;
    var currentOrder = UserContext.order.current;
    if (status.numOperazione >= CONFIG.MAX_OPERATIONS && currentOrder) {
        var deletedOrder = OrderUtils.deleteOrder(currentOrder.OrderCode);
        Helper.log('action', { 
            actionType: "Order Deleted", 
            payload: { order: deletedOrder } 
        });
        status.run = false;
        return true;
    }
    return false;
}

function manageCycle(priceLevel) {
    var status = UserContext.status;
    if (!status.run || checkOps()) return;
    if (status.secondCount >= CONFIG.SECONDS || typeof priceLevel !== 'undefined') {
        priceUpdate(CONFIG.ORDER_SIDE, UserContext.book);
    }
}

function setupTradeContext() {
    var book = Book(ps);
    UserContext = new initializeTradeContext(book);
    Helper.log('action', { 
        actionType: "Initialization Complete", 
        payload: null 
    });
    manageCycle(UserContext.initialPriceLevel);
}

function marketEvent() {
    if (!UserContext.status.run) return;
    var eventType = SystemContext.EventType;
    var book = UserContext.book || Book(ps);
    UserContext.book = book;
    
    switch(eventType) {
        case TSEventType.Price:
            var currentPrice = Val(ps, "LAST");
            if (UserContext.lastPrice !== currentPrice) {
                var currentTime = Now().ToString("HH:mm:ss.ff");
                Helper.log('priceChange', { 
                    currentPrice: currentPrice, 
                    previousPrice: UserContext.lastPrice, 
                    currentTime: currentTime 
                });
                UserContext.lastPrice = currentPrice;
            }
            break;
        case TSEventType.Time:
            UserContext.status.secondCount++;
            manageCycle();
            break;
    }
}

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

marketEvent();