From fc25ea3a4dd851a168c07e1eab23589e217d4364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=A7=D0=B5=D1=87=D0=B5?= =?UTF-8?q?=D1=82?= Date: Thu, 13 Jan 2022 11:45:05 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20data=5Fsource=5Fca?= =?UTF-8?q?llback=20=D0=BD=D0=B0=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D0=B8=D0=B7=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20QuikSharp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QUIK/lua/qsfunctions.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/QUIK/lua/qsfunctions.lua b/QUIK/lua/qsfunctions.lua index 9ff621d..6feea7f 100644 --- a/QUIK/lua/qsfunctions.lua +++ b/QUIK/lua/qsfunctions.lua @@ -50,8 +50,7 @@ end --- Test error handling function qsfunctions.divide_string_by_zero(msg) - --noinspection LuaDivideByZero - msg.data = "asd" / 0 + msg.data = "asd" / 0 return msg end @@ -136,7 +135,7 @@ end function qsfunctions.addLabel(msg) local spl = split(msg.data, "|") local price, curdate, curtime, qty, path, id, algmnt, bgnd = spl[1], spl[2], spl[3], spl[4], spl[5], spl[6], spl[7], spl[8] - local label = { + label = { TEXT = "", IMAGE_PATH = path, ALIGNMENT = algmnt, @@ -528,7 +527,7 @@ end function qsfunctions.get_orders(msg) if msg.data ~= "" then local spl = split(msg.data, "|") - local class_code, sec_code = spl[1], spl[2] + class_code, sec_code = spl[1], spl[2] end local orders = {} @@ -546,7 +545,7 @@ end function qsfunctions.getOrder_by_ID(msg) if msg.data ~= "" then local spl = split(msg.data, "|") - local class_code, sec_code, trans_id = spl[1], spl[2], spl[3] + class_code, sec_code, trans_id = spl[1], spl[2], spl[3] end local order_num = 0 @@ -604,7 +603,7 @@ end function qsfunctions.get_trades(msg) if msg.data ~= "" then local spl = split(msg.data, "|") - local class_code, sec_code = spl[1], spl[2] + class_code, sec_code = spl[1], spl[2] end local trades = {} @@ -653,7 +652,7 @@ end function qsfunctions.get_all_trades(msg) if msg.data ~= "" then local spl = split(msg.data, "|") - local class_code, sec_code = spl[1], spl[2] + class_code, sec_code = spl[1], spl[2] end local trades = {} @@ -727,7 +726,7 @@ end function qsfunctions.get_stop_orders(msg) if msg.data ~= "" then local spl = split(msg.data, "|") - local class_code, sec_code = spl[1], spl[2] + class_code, sec_code = spl[1], spl[2] end local count = getNumberOf("stop_orders") @@ -839,6 +838,7 @@ end --- Словарь открытых подписок (datasources) на свечи data_sources = {} last_indexes = {} + --- Подписаться на получения свечей по заданному инструмент и интервалу function qsfunctions.subscribe_to_candles(msg) local ds, is_error = create_data_source(msg) @@ -855,13 +855,12 @@ function qsfunctions.subscribe_to_candles(msg) return msg end ---- (ichechet) Функция обработки новой свечки function data_source_callback(index, class, sec, interval) local key = get_key(class, sec, interval) - if index ~= last_indexes[key] then -- Номер свечки изменился. Не всегда номер свечки монотонно возрастает https://forum.quik.ru/forum10/topic2530/ - log(index, 0) - local candle = fetch_candle(data_sources[key], last_indexes[key]) -- Получаем только что сформированную прошлую свечку - last_indexes[key] = index -- Запоминаем новый номер свечки + if index ~= last_indexes[key] then + last_indexes[key] = index + + local candle = fetch_candle(data_sources[key], index - 1) candle.sec = sec candle.class = class candle.interval = interval