Buongiorno, vorrei che tu riscriva questo codice con le seguenti modifiche: 1 corretta indentazione del codice 2 rifattorizzazione in base all'ordine logico di apparizione di variabili, funzioni e codice principale. Non serve aggiungere commenti. var CONFIG = {
ORDER_SIDE: 'BID',
SIZE: 1,
MAX_OPERATIONS: 8,
LEVELS: { BID: 6, ASK: 6 },
SECONDS: 5,
MONITORING_MODE: 'MONITORA_yourlevel'
};
var separator = "---------------------------------------------------\r\n";
function priceUpdate(side, book) {
var context = UserContext;
var status = context.status;
var pricesSide = context.prices[side];
var targetPriceLevel = context.targetPriceLevels[side];
var targetPrice = BookUtils.getData(book, side, targetPriceLevel, 'Price');
var oldPrice = pricesSide.oldLevel;
code
if (targetPrice !== oldPrice) {
var newOrder = OrderUtils.processOrModOrder(side, ps, targetPrice);
if (newOrder) {
pricesSide.current = targetPrice;
var direction = Helper.priceDirection(targetPrice, oldPrice);
var levelDiff = CONFIG.LEVELS[side] + direction;
Helper.log('LevelChange', { lastLevel: levelDiff, priceLevel: targetPriceLevel });
status.secondCount = 0;
status.numOperazione++;
}
}
}
function checkOps() {
var status = UserContext.status;
var currentOrder = UserContext.order.current;
if (status.numOperazione >= CONFIG.MAX_OPERATIONS) {
if (currentOrder) {
var deletedOrder = OrderUtils.deleteOrder(currentOrder.OrderCode);
Helper.log('Order Deleted', { orderCode: deletedOrder.OrderCode });
status.run = false;
return true;
}
}
return false;
}
function manageCycle() {
var status = UserContext.status;
if (checkOps()) return;
if (status.secondCount < CONFIG.SECONDS) return;
var side = CONFIG.ORDER_SIDE;
var book = UserContext.book;
priceUpdate(side, book);
status.secondCount = 0;
}
function marketEvent() {
if (!UserContext.status.run) return;
code
var eventType = SystemContext.EventType;
if (eventType === TSEventType.Price) {
var currentPrice = Val(ps, "LAST");
var context = UserContext;
if (context.lastPrice !== currentPrice) {
var currentTime = Now().ToString("HH:mm:ss.ff");
Helper.log('PriceChange', {
previousPrice: context.lastPrice,
currentPrice: currentPrice,
currentTime: currentTime
});
context.lastPrice = currentPrice;
}
} else if (eventType === TSEventType.Time) {
UserContext.status.secondCount++;
manageCycle();
}
}
if (SystemContext.IsFirst) {
setupTradeContext();
}