/
CountZero
/
quik-cscalp-lua
Обзор
Документация
Войти
/
CountZero
/
quik-cscalp-lua
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
qscallbacks.lua
197 строк
5 KB
CountZero
Update
05 авг 2026, 20:59
05 авг 2026, 20:59
500bdaf
Код
Авторство
О чём код?
-- QLua callback boundary. Every public function is global because QUIK calls -- it by name; all implementation state remains owned by qsbridge. local bridge = require("qsbridge").instance() local qscallbacks = {} local function traceback(error_value) if debug and type(debug.traceback) == "function" then return debug.traceback(tostring(error_value), 2) end return tostring(error_value) end local function report_callback_error(name, error_value) local text = tostring(name) .. " failed: " .. tostring(error_value) log(text, "error") bridge:emit("lua_error", "Lua error: " .. text) end local function guarded(name, callback) local ok, result = xpcall(callback, traceback) if not ok then report_callback_error(name, result) return nil end return result end function OnQuikSharpConnected() guarded("OnQuikSharpConnected", function() bridge:on_local_connected() end) end function OnQuikSharpDisconnected(reason) guarded("OnQuikSharpDisconnected", function() bridge:on_local_disconnected(reason or "local transport disconnected") end) end function OnError(error_message) guarded("OnError", function() bridge:emit("lua_error", "Lua error: " .. tostring(error_message)) end) end function OnDisconnected() guarded("OnDisconnected", function() bridge:on_quik_disconnected("QLua OnDisconnected") end) end function OnConnected() guarded("OnConnected", function() bridge:on_quik_connected("QLua OnConnected") end) end function OnAllTrade(all_trade) guarded("OnAllTrade", function() if bridge.market then bridge.market:on_all_trade(all_trade) end end) end function OnClose() guarded("OnClose", function() bridge:emit("OnClose", "") bridge:stop("QLua OnClose") is_started = false log("QUIK# closed", "info") flushLog(true) end) end function OnInit(path) guarded("OnInit", function() bridge:initialize() log("QUIK# initialized from " .. tostring(path), "info") bridge:emit("OnInit", path) end) end function OnOrder(order) guarded("OnOrder", function() bridge:forward_record("OnOrder", order) end) end function OnQuote(class_code, sec_code) guarded("OnQuote", function() if bridge.market then bridge.market:on_quote(class_code, sec_code) end end) end function OnStop(signal) local result = guarded("OnStop", function() is_started = false bridge:emit("OnStop", signal) bridge:stop("QLua OnStop") log("QUIK# stopped", "info") flushLog(true) return 1000 end) return result or 1000 end function OnTrade(trade) guarded("OnTrade", function() bridge:forward_record("OnTrade", trade) end) end function OnTransReply(reply) guarded("OnTransReply", function() bridge:forward_record("OnTransReply", reply) end) end function OnStopOrder(stop_order) guarded("OnStopOrder", function() bridge:forward_record("OnStopOrder", stop_order) end) end function OnParam(class_code, sec_code) guarded("OnParam", function() if bridge.market then bridge.market:on_param(class_code, sec_code) end end) end function OnAccountBalance(balance) guarded("OnAccountBalance", function() bridge:forward_record("OnAccountBalance", balance) end) end function OnAccountPosition(position) guarded("OnAccountPosition", function() bridge:forward_record("OnAccountPosition", position) end) end function OnDepoLimit(limit) guarded("OnDepoLimit", function() bridge:forward_record("OnDepoLimit", limit) end) end function OnDepoLimitDelete(limit) guarded("OnDepoLimitDelete", function() bridge:forward_record("OnDepoLimitDelete", limit) end) end function OnFirm(firm) guarded("OnFirm", function() bridge:emit("OnFirm", firm) end) end function OnFuturesClientHolding(position) guarded("OnFuturesClientHolding", function() bridge:forward_record("OnFuturesClientHolding", position) end) end function OnFuturesLimitChange(limit) guarded("OnFuturesLimitChange", function() bridge:forward_record("OnFuturesLimitChange", limit) end) end function OnFuturesLimitDelete(limit) guarded("OnFuturesLimitDelete", function() bridge:forward_record("OnFuturesLimitDelete", limit) end) end function OnMoneyLimit(limit) guarded("OnMoneyLimit", function() bridge:forward_record("OnMoneyLimit", limit) end) end function OnMoneyLimitDelete(limit) guarded("OnMoneyLimitDelete", function() bridge:forward_record("OnMoneyLimitDelete", limit) end) end return qscallbacks