Сначала решил проверить на вашем тестовом контуре в вечений клиринг. Кулено 2 контракта SRU0.
Вот простейший скрипт:
Код |
---|
local isRun = true
local logFile
local function log_tostring(...)
local n = select('#', ...)
if n == 1 then
return tostring(select(1, ...))
end
local t = {}
for i = 1, n do
t[#t + 1] = tostring((select(i, ...)))
end
return table.concat(t, " ")
end
local function myLog(...)
if logFile==nil then return end
logFile:write(tostring(os.date("%c",os.time())).." "..log_tostring(...).."\n");
logFile:flush();
end
local function GetFuturesHolding(Sec)
local futures_client_holding = _G.getFuturesHolding(Sec.FIRM_ID, Sec.ACCOUNT, Sec.SEC_CODE, 0)
if futures_client_holding then
return futures_client_holding.totalnet
end
return 0
end
local function GetTotalnet(Sec)
local num = getNumberOf('futures_client_holding')
for i = 0, num - 1 do
local futures_client_holding = getItem('futures_client_holding',i)
if futures_client_holding and futures_client_holding.sec_code == Sec.SEC_CODE and futures_client_holding.trdaccid == Sec.ACCOUNT then
return futures_client_holding.totalnet
end
end
return 0
end
function _G.main()
logFile = io.open(_G.getScriptPath().."\\test_log.txt", "w")
local Sec = {SEC_CODE = 'SRU0', CLASS_CODE = 'SPBFUT', ACCOUNT = 'SPBFUT001nw', FIRM_ID = 'SPBFUT000000'}
local curOpenCount = GetTotalnet(Sec)
while isRun do
local new_count = GetFuturesHolding(Sec)
if new_count ~= curOpenCount then
myLog('----------------------------------------------------------------------------------')
myLog('getFuturesHolding new_count', new_count)
curOpenCount = new_count
for i = 0, _G.getNumberOf('futures_client_holding') - 1 do
local fut_pos = _G.getItem('futures_client_holding', i)
myLog('futures_client_holding', i, 'sec_code', fut_pos.sec_code, 'avrposnprice', fut_pos.avrposnprice, 'totalnet', fut_pos.totalnet)
end
myLog('----------------------------------------------------------------------------------')
end
sleep(100)
end
end
function _G.OnFuturesClientHolding(fut_pos)
myLog('----------------------------------------------------------------------------------')
myLog(' OnFuturesClientHolding ', 'sec_code', fut_pos.sec_code, 'avrposnprice', fut_pos.avrposnprice, 'totalnet', fut_pos.totalnet)
myLog('----------------------------------------------------------------------------------')
end
function _G.OnStop()
isRun = false
myLog("Script Stoped")
if logFile then logFile:close() end
end
function _G.OnClose()
isRun = false
myLog("Script OnClose")
end |
А вот, что происходит во время вечернего клиринга. Я так понимаю это технологические изменения позиции. Реальные скрипты не проверяют баланс во время клиринга, но здесь вопрос: а согласованы ли параметры
TRADINGSTATUS и CLSTATE с изменением баланса? Т.е. не может ли быть так, что статус клиринга еще не успел обновиться, а баланс через getFuturesHolding обнулился?
Правда также возникает вопрос: а с чего он так скачет туда-обратно? Если вывести позицию в торговую панель стакана, то там стабильно позиция остается правильной.
[INFO 2020-08-04 15:37:55] : ----------------------------------------------------------------------------------[INFO 2020-08-04 15:37:55] : futures_client_holding 0 {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 18, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 18}
[INFO 2020-08-04 15:37:55] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:38:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:38:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = -12, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = -12}
[INFO 2020-08-04 15:38:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:39:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:39:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 6, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 6}
[INFO 2020-08-04 15:39:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:40:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:40:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 24, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 24}
[INFO 2020-08-04 15:40:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:41:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:41:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 18, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 18}
[INFO 2020-08-04 15:41:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:42:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:42:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 10, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 10}
[INFO 2020-08-04 15:42:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:43:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:43:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 28, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 28}
[INFO 2020-08-04 15:43:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:44:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:44:24] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 36, sec_code = "SRU0", seccode = "SRU0", session_status = 3, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 36}
[INFO 2020-08-04 15:44:24] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:45:00] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:45:00] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:45:00] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : OnFuturesClientHolding {avrposnprice = 0, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 0, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : getFuturesHolding new_count 0
[INFO 2020-08-04 15:47:06] : futures_client_holding 0 {avrposnprice = 0, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 0, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:06] : OnFuturesClientHolding {avrposnprice = 0, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 0, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:06] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:07] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:07] : OnFuturesClientHolding {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:07] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:07] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:07] : getFuturesHolding new_count 2
[INFO 2020-08-04 15:47:07] : futures_client_holding 0 {avrposnprice = 22792, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 2, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:07] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : OnFuturesClientHolding {avrposnprice = 0, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 0, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : getFuturesHolding new_count 0
[INFO 2020-08-04 15:47:10] : futures_client_holding 0 {avrposnprice = 0, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 0, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 0, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : OnFuturesClientHolding {avrposnprice = 22800, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 2, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:47:10] : getFuturesHolding new_count 2
[INFO 2020-08-04 15:47:10] : futures_client_holding 0 {avrposnprice = 22800, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = 0, sec_code = "SRU0", seccode = "SRU0", session_status = 4, startbuy = 0, startnet = 2, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = 0}
[INFO 2020-08-04 15:47:10] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:48:26] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:48:26] : OnFuturesClientHolding {avrposnprice = 22800, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = -300, sec_code = "SRU0", seccode = "SRU0", session_status = 5, startbuy = 0, startnet = 2, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 0, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = -300}
[INFO 2020-08-04 15:48:26] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:50:48] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 15:50:48] : OnFuturesClientHolding {avrposnprice = 22800, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = -300, sec_code = "SRU0", seccode = "SRU0", session_status = 5, startbuy = 0, startnet = 2, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 16, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = -300}
[INFO 2020-08-04 15:50:48] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 16:00:01] : ----------------------------------------------------------------------------------
[INFO 2020-08-04 16:00:01] : OnFuturesClientHolding {avrposnprice = 22800, cbplplanned = 0, cbplused = 0, firmid = "SPBFUT000000", openbuys = 0, opensells = 0, positionvalue = 0, real_varmargin = -300, sec_code = "SRU0", seccode = "SRU0", session_status = 6, startbuy = 0, startnet = 2, startsell = 0, todaybuy = 0, todaysell = 0, total_varmargin = 16, totalnet = 2, trdaccid = "SPBFUT001nw", type = 0, varmargin = -300}
[INFO 2020-08-04 16:00:01] : ----------------------------------------------------------------------------------