TRADE_ACC = "123"
CLIENT_CODE = "321"
SEC = "PIKK"
CLASS = "TQBR"
percent = 1
portfolio = 1
uniq_trans_id = 0x18000
Block_sell_Case = 1
security_info = getSecurityInfo(CLASS, SEC)
NAME = security_info.short_name
PRICE_STEP = security_info.min_price_step
PRICE_SCALE = security_info.scale
LOT_SIZE = security_info.lot_size
Open = 0
High = 0
Low = 0
Close = 0
Volume = 0
Order = 0
Case = 0
buy_price = 0
sell_price = 0
Total = 0
Date_Time = 0
Total_perc = 0
average_price = 0
block_sell = 0
stopped = false
cur_state = ""
t_id = 0
cur_order = 1
order_stat = 0
mask_bits = 7
function OnStop(s)
stopped = true
DestroyTable(t_id)
message("Скрипт остановлен пользователем, робот отключен")
end
function OnInit()
local NO = getNumberOf("orders")
Column_Table = {
{"Инструмент",QTABLE_STRING_TYPE,15,function() return NAME end},
{"Шаг цены",QTABLE_DOUBLE_TYPE, 12,function() return tostring(PRICE_STEP) end},
{"Точность",QTABLE_INT_TYPE, 12,function() return tostring (PRICE_SCALE) end},
{"Заявка", QTABLE_STRING_TYPE, 10,function() return tostring(Order) end},
{"Портфель", QTABLE_INT_TYPE, 10,function() return tostring(Case) end},
{"Цена покупки", QTABLE_DOUBLE_TYPE, 15,function() return tostring(buy_price * LOT_SIZE) end},
{"Цена продажи", QTABLE_DOUBLE_TYPE, 15,function() return tostring(sell_price * LOT_SIZE) end},
{"Итого", QTABLE_DOUBLE_TYPE, 15,function() return tostring(Total) end},
{"Дата время", QTABLE_DOUBLE_TYPE, 15,function() return tostring(Date_Time) end},
{"Статус", QTABLE_STRING_TYPE, 10,function() return tostring(cur_state) end},
}
t_id = Table_init(Column_Table)
end;
function main()
while not stopped do
if IsWindowClosed(t_id) then
stopped = true
message("Таблица закрыта пользователем, робот остановлен", 1)
end
Table_row(cur_order)
sleep(500)
end
end
function File_Write()
f = io.open(getScriptPath().."\\Robot\\log\\" .. SEC .. ".lua","r+");
message("Пытаюсь открыть файл \\Robot\\log\\" .. SEC .. ".lua")
if f == nil then
message("Файл не существует!")
f = io.open(getScriptPath().."\\Robot\\log\\" .. SEC .. ".lua","w");
f:close();
f = io.open(getScriptPath().."\\Robot\\log\\" .. SEC .. ".lua","r+");
message("Файл создан!")
local i = 0
for i=1,#Column_Table,1 do
f:write(Column_Table[i][1])
f:write(string.rep(" ", Column_Table[i][3] - string.len(Column_Table[i][1]) - 2) .. "|" .. " ")
end
f:write("\n")
end;
f:seek("end",0);
for i=1,#Column_Table,1 do
f:write(Column_Table[i][4]())
f:write(string.rep(" ", Column_Table[i][3] - string.len(Column_Table[i][4]()) - 2) .. "|" .. " ")
end
f:write("\n")
f:flush()
f:close()
end
function Table_init(t)
local i = 0
local Table = AllocTable()
for i=1,#t,1 do
AddColumn(Table, i, t[i][1], true, t[i][2], t[i][3])
end
CreateWindow(Table)
SetWindowCaption(Table, "Рабочая таблица робота " .. NAME)
InsertRow(Table, -1)
return Table
end
function Table_row(row, color)
local i = 0
for i=1,#Column_Table,1 do
SetCell(t_id,row,i,Column_Table[i][4]())
end
end
function Add_row()
InsertRow(t_id, cur_order)
end