local caption = getScriptPath()
local is_run = true
local id = nil
local gui_param =
{
[1]= {"Инструмент", true, QTABLE_CACHED_STRING_TYPE, 12, 0},
[2]= {"До эксп.", true, QTABLE_DOUBLE_TYPE, 8, 1},
[3]= {"bid", true, QTABLE_DOUBLE_TYPE, 8, 1},
[4]= {"ask", true, QTABLE_DOUBLE_TYPE, 8, 1},
colls =
{
ticker = 1,
dtmd = 2,
bid = 3,
ask = 4,
},
rows = {},
coord = {y= 50, x= 600, dy= 500, dx= 293},
}
local function gui_insert()
Clear(id)
for ticker in string.gmatch(getClassSecurities("SPBFUT"), "(%w+)") do
local dtmd = tonumber(getParamEx("SPBFUT", ticker, "days_to_mat_date").param_value)
if dtmd > -1 then
local r = InsertRow(id, -1)
gui_param.rows[ticker] = {row = r, dtmd = dtmd}
SetCell(id, r, gui_param.colls.ticker, ticker)
SetCell(id, r, gui_param.colls.dtmd, tostring(dtmd), dtmd)
local bid = tonumber(getParamEx("SPBFUT", ticker, "bid").param_value) or 0
local ask = tonumber(getParamEx("SPBFUT", ticker, "offer").param_value) or 0
SetCell(id, r, gui_param.colls.bid, tostring(bid), bid)
SetCell(id, r, gui_param.colls.ask, tostring(ask), ask)
end
end
end
local function CallbackGui(t_id, msg, row, col)
if row ~= 0 and msg == QTABLE_LBUTTONUP then
if col < 0 then return end
local col_name = gui_param[col][1]
local val = GetCell(t_id, row, col).image
if col == 1 then
message("row= "..row.."\ncol= "..col.."\n"..col_name..": "..tostring(val),2)
else
local ticker = GetCell(t_id, row, gui_param.colls.ticker).image
message("row= "..row.."\ncol= "..col.."\nИнструмент: "..ticker.."\n"..col_name.."= "..tostring(val),2)
end
end
if (row == 0 and col < 0) or (msg == QTABLE_CLOSE) then
local top, left, bottom, right = GetWindowRect(t_id)
local height = bottom - top
local width = right - left
gui_param.coord =
{
y = top,
x = left,
dy = height,
dx = width,
}
message("\n y = "..top.."\n x = "..left.."\n dy= "..height.."\n dx= "..width,2)
end
end
function main()
id = AllocTable()
for i=1, #gui_param do
local p = gui_param[i]
AddColumn(id, i, p[1], p[2], p[3], p[4])
end
SetTableNotificationCallback(id, CallbackGui)
while is_run do
if IsWindowClosed(id) then
CreateWindow(id)
SetWindowCaption(id, caption)
local coord = gui_param.coord
SetWindowPos(id, coord.x, coord.y, coord.dx, coord.dy)
gui_insert()
end
sleep(1)
end
end
function OnParam(class, sec)
local rows = gui_param.rows[sec]
if rows then
local bid = tonumber(getParamEx(class, sec, "bid").param_value) or 0
local ask = tonumber(getParamEx(class, sec, "offer").param_value) or 0
SetCell(id, rows.row, gui_param.colls.bid, tostring(bid), bid)
SetCell(id, rows.row, gui_param.colls.ask, tostring(ask), ask)
end
end
function OnStop()
is_run = nil
DestroyTable(id)
return 1000
end