Синхронизация скриптов LUA с QUIKSharp. Внесение в ReadMe информации об ошибках core.dll / LUA скриптов
This commit is contained in:
@@ -156,6 +156,102 @@ function qsfunctions.addLabel(msg)
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Выводит на график метку
|
||||
-- Функция возвращает числовой идентификатор метки. В случае неуспешного завершения функция возвращает «nil».
|
||||
function qsfunctions.addLabel2(msg)
|
||||
local spl = split2(msg.data, "|");
|
||||
local chartTag, yValue, strDate, strTime, text, imagePath, alignment, hint, r, g, b, transparency, tranBackgrnd, fontName, fontHeight =
|
||||
spl[1], spl[2], spl[3], spl[4], spl[5], spl[6], spl[7], spl[8], spl[9], spl[10], spl[11], spl[12], spl[13], spl[14], spl[15];
|
||||
|
||||
-- значения по умолчанию
|
||||
if text == "" then text = nil else r = 255 end
|
||||
if imagePath == "" then imagePath = nil end
|
||||
if alignment == "" then alignment = nil end
|
||||
if hint == "" then hint = nil end
|
||||
if r == "-1" then r = nil end
|
||||
if g == "-1" then g = nil end
|
||||
if b == "-1" then b = nil end
|
||||
if transparency == "-1" then transparency = nil end
|
||||
if tranBackgrnd == "-1" then tranBackgrnd = nil end
|
||||
if fontName == "" then fontName = nil end
|
||||
if fontHeight == "-1" then fontHeight = nil end
|
||||
|
||||
local labelParams = {
|
||||
YVALUE = yValue:gsub(",", "."),
|
||||
DATE = strDate,
|
||||
TIME = strTime,
|
||||
TEXT = text,
|
||||
IMAGE_PATH = imagePath,
|
||||
ALIGNMENT = alignment,
|
||||
HINT = hint,
|
||||
R = r,
|
||||
G = g,
|
||||
B = b,
|
||||
TRANSPARENCY = transparency,
|
||||
TRANSPARENT_BACKGROUND = tranBackgrnd,
|
||||
FONT_FACE_NAME = fontName,
|
||||
FONT_HEIGHT = fontHeight,
|
||||
}
|
||||
|
||||
local res = AddLabel(chartTag, labelParams);
|
||||
|
||||
msg.data = res;
|
||||
return msg;
|
||||
end
|
||||
|
||||
-- Функция задает параметры для метки с указанным идентификатором.
|
||||
-- В случае успешного завершения функция возвращает «true», иначе – «false».
|
||||
function qsfunctions.setLabelParams(msg)
|
||||
local spl = split2(msg.data, "|");
|
||||
local chartTag, labelId, yValue, strDate, strTime, text, imagePath, alignment, hint, r, g, b, transparency, tranBackgrnd, fontName, fontHeight =
|
||||
spl[1], spl[2], spl[3], spl[4], spl[5], spl[6], spl[7], spl[8], spl[9], spl[10], spl[11], spl[12], spl[13], spl[14], spl[15], spl[16];
|
||||
|
||||
-- значения по умолчанию
|
||||
if text == "" then text = nil else r = 255 end
|
||||
if imagePath == "" then imagePath = nil end
|
||||
if alignment == "" then alignment = nil end
|
||||
if hint == "" then hint = nil end
|
||||
if r == "-1" then r = nil end
|
||||
if g == "-1" then g = nil end
|
||||
if b == "-1" then b = nil end
|
||||
if transparency == "-1" then transparency = nil end
|
||||
if tranBackgrnd == "-1" then tranBackgrnd = nil end
|
||||
if fontName == "" then fontName = nil end
|
||||
if fontHeight == "-1" then fontHeight = nil end
|
||||
|
||||
local labelParams = {
|
||||
YVALUE = yValue,
|
||||
DATE = strDate,
|
||||
TIME = strTime,
|
||||
TEXT = text,
|
||||
IMAGE_PATH = imagePath,
|
||||
ALIGNMENT = alignment,
|
||||
HINT = hint,
|
||||
R = r,
|
||||
G = g,
|
||||
B = b,
|
||||
TRANSPARENCY = transparency,
|
||||
TRANSPARENT_BACKGROUND = tranBackgrnd,
|
||||
FONT_FACE_NAME = fontName,
|
||||
FONT_HEIGHT = fontHeight,
|
||||
}
|
||||
|
||||
local res = SetLabelParams(chartTag, tonumber(labelId), labelParams);
|
||||
msg.data = tostring(res);
|
||||
return msg;
|
||||
end
|
||||
|
||||
-- позволяет получить параметры метки
|
||||
-- Функция возвращает таблицу с параметрами метки. В случае неуспешного завершения функция возвращает «nil».
|
||||
function qsfunctions.getLabelParams(msg)
|
||||
local spl = split2(msg.data, "|");
|
||||
local chartTag, labelId = spl[1], spl[2];
|
||||
|
||||
local res = GetLabelParams(chartTag, tonumber(labelId));
|
||||
msg.data = res;
|
||||
return msg;
|
||||
end
|
||||
|
||||
-- Удаляем выбранную метку
|
||||
function qsfunctions.delLabel(msg)
|
||||
local spl = split(msg.data, "|")
|
||||
@@ -207,7 +303,7 @@ function qsfunctions.getSecurityInfo(msg)
|
||||
return msg
|
||||
end
|
||||
|
||||
--- Функция берет на вход список из элементов в формате class_code|sec_code и возвращает список ответов функции getSecurityInfo.
|
||||
--- Функция берет на вход список из элементов в формате class_code|sec_code и возвращает список ответов функции getSecurityInfo.
|
||||
-- Если какая-то из бумаг не будет найдена, вместо ее значения придет null
|
||||
function qsfunctions.getSecurityInfoBulk(msg)
|
||||
local result = {}
|
||||
@@ -262,7 +358,15 @@ function qsfunctions.getClientCodes(msg)
|
||||
for i=0,getNumberOf("MONEY_LIMITS")-1 do
|
||||
local clientcode = getItem("MONEY_LIMITS",i).client_code
|
||||
if clientcode ~= nil then
|
||||
table.insert(client_codes, clientcode)
|
||||
fnd = false
|
||||
for index, value in ipairs(client_codes) do
|
||||
if value == clientcode then
|
||||
fnd = true
|
||||
end
|
||||
end
|
||||
if fnd == false then
|
||||
table.insert(client_codes, clientcode)
|
||||
end
|
||||
end
|
||||
end
|
||||
msg.data = client_codes
|
||||
@@ -345,6 +449,33 @@ end
|
||||
-- Trading functions --
|
||||
-----------------------
|
||||
|
||||
--- Функция предназначена для расчета максимально возможного количества лотов в заявке.
|
||||
-- При заданном параметре is_market=true, необходимо передать параметр price=0, иначе будет рассчитано максимально возможное количество лотов в заявке по цене price.
|
||||
function qsfunctions.calc_buy_sell(msg)
|
||||
local bs = CalcBuySell
|
||||
local spl = split(msg.data, "|")
|
||||
local class_code, sec_code, clientCode, account, price, is_buy, is_market = spl[1], spl[2], spl[3], spl[4], spl[5], spl[6], spl[7]
|
||||
if is_buy == "True" then
|
||||
is_buy = true
|
||||
else
|
||||
is_buy = false
|
||||
end
|
||||
if is_market == "True" then
|
||||
is_market = true
|
||||
else
|
||||
is_market = false
|
||||
end
|
||||
local qty, comiss = bs(class_code, sec_code, clientCode, account, tonumber(price), is_buy, is_market)
|
||||
if qty ~= "" then
|
||||
msg.data = {}
|
||||
msg.data.qty = qty
|
||||
msg.data.comission = comiss
|
||||
else
|
||||
message("Ошибка функции CalcBuySell", 1)
|
||||
end
|
||||
return msg
|
||||
end
|
||||
|
||||
--- отправляет транзакцию на сервер и возвращает пустое сообщение, которое
|
||||
-- будет проигноировано. Вместо него, отправитель будет ждать события
|
||||
-- OnTransReply, из которого по TRANS_ID он получит результат отправленной транзакции
|
||||
@@ -370,7 +501,7 @@ function qsfunctions.paramRequest(msg)
|
||||
return msg
|
||||
end
|
||||
|
||||
--- Функция принимает список строк (JSON Array) в формате class_code|sec_code|param_name, вызывает функцию paramRequest для каждой строки.
|
||||
--- Функция принимает список строк (JSON Array) в формате class_code|sec_code|param_name, вызывает функцию paramRequest для каждой строки.
|
||||
-- Возвращает список ответов в том же порядке
|
||||
function qsfunctions.paramRequestBulk(msg)
|
||||
local result = {}
|
||||
@@ -523,6 +654,17 @@ function qsfunctions.getFuturesHolding(msg)
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Функция для получения информации по всем фьючерсным позициям
|
||||
function qsfunctions.getFuturesClientHoldings(msg)
|
||||
local holdings = {}
|
||||
for i=0,getNumberOf("futures_client_holding")-1 do
|
||||
local holding = getItem("futures_client_holding",i)
|
||||
table.insert(holdings, holding)
|
||||
end
|
||||
msg.data = holdings
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Функция возвращает таблицу заявок (всю или по заданному инструменту)
|
||||
function qsfunctions.get_orders(msg)
|
||||
if msg.data ~= "" then
|
||||
|
||||
@@ -127,7 +127,7 @@ function log(msg, level)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Doesn't work if string contains empty values, eg. 'foo,,bar'. You get {'foo','bar'} instead of {'foo', '', 'bar'}
|
||||
function split(inputstr, sep)
|
||||
if sep == nil then
|
||||
sep = "%s"
|
||||
@@ -141,6 +141,18 @@ function split(inputstr, sep)
|
||||
return t
|
||||
end
|
||||
|
||||
-- https://stackoverflow.com/questions/1426954/split-string-in-lua#comment73602874_7615129
|
||||
function split2(inputstr, sep)
|
||||
sep = sep or '%s'
|
||||
local t = {}
|
||||
for field, s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
|
||||
table.insert(t, field)
|
||||
if s == "" then
|
||||
return t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function from_json(str)
|
||||
local status, msg= pcall(json.decode, str, 1, json.null) -- dkjson
|
||||
if status then
|
||||
|
||||
Reference in New Issue
Block a user