Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

добавлена возможность выбора серии опционов: недельная, месячная, ква… #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/QuikSharp/DataStructures/OptionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2014-2020 QUIKSharp Authors https://github.com/finsight/QUIKSharp/blob/master/AUTHORS.md. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE.txt in the project root for license information.

namespace QuikSharp.DataStructures
{
/// <summary>
/// Тип опциона
/// </summary>
public enum OptionType
{
/// <summary>
/// Call option
/// </summary>
Call,

/// <summary>
/// Put option
/// </summary>
Put
}
}
7 changes: 4 additions & 3 deletions src/QuikSharp/TradingFunctions/TradingFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public interface ITradingFunctions : IQuikService
/// </summary>
/// <param name="classCode"></param>
/// <param name="secCode"></param>
/// <param name="series"></param>
/// <returns></returns>
Task<List<OptionBoard>> GetOptionBoard(string classCode, string secCode);
Task<List<OptionBoard>> GetOptionBoard(string classCode, string secCode, string series);

/// <summary>
/// Функция заказывает получение параметров Таблицы текущих торгов
Expand Down Expand Up @@ -493,9 +494,9 @@ public async Task<List<FuturesClientHolding>> GetFuturesClientHoldings()
return response.Data;
}

public async Task<List<OptionBoard>> GetOptionBoard(string classCode, string secCode)
public async Task<List<OptionBoard>> GetOptionBoard(string classCode, string secCode, string series)
{
var message = new Message<string>(classCode + "|" + secCode, "getOptionBoard");
var message = new Message<string>(classCode + "|" + secCode + "|" + series, "getOptionBoard");
Message<List<OptionBoard>> response =
await QuikService.Send<Message<List<OptionBoard>>>(message).ConfigureAwait(false);
return response.Data;
Expand Down
80 changes: 60 additions & 20 deletions src/QuikSharp/lua/qsfunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ function qsfunctions.GetQuoteLevel2(msg)
local spl = split(msg.data, "|")
local class_code, sec_code = spl[1], spl[2]
local server_time = getInfoParam("SERVERTIME")
local status, ql2 = pcall(getQuoteLevel2, class_code, sec_code)
local status, ql2 = pcall(getQuoteLevel2, class_code, sec_code)
if status then
msg.data = ql2
msg.data.class_code = class_code
Expand Down Expand Up @@ -809,8 +809,8 @@ end
--------------------------
function qsfunctions.getOptionBoard(msg)
local spl = split(msg.data, "|")
local classCode, secCode = spl[1], spl[2]
local result, err = getOptions(classCode, secCode)
local classCode, secCode, series = spl[1], spl[2], spl[3]
local result, err = getOptions(classCode, secCode, series )
if result then
msg.data = result
else
Expand All @@ -820,35 +820,75 @@ function qsfunctions.getOptionBoard(msg)
return msg
end

function getOptions(classCode,secCode)
function getOptions(classCode,secCode,series)
--classCode = "SPBOPT"
--BaseSecList="RIZ6"
--series: 0 - ближайшая неделя, 1 - ближний месяц, 2 - ближний квартал, 4 - все
local SecList = getClassSecurities(classCode) --все сразу
local t={}
local p={}
local week = false
local month = false
local quartal = false
local all = false
local len = 0;
local days_to_mat
local last_char
for sec in string.gmatch(SecList, "([^,]+)") do --перебираем опционы по очереди.
week = false
month = false
quartal = false
all = false


local Optionbase=getParamEx(classCode,sec,"optionbase").param_image
local Optiontype=getParamEx(classCode,sec,"optiontype").param_image
if (string.find(secCode,Optionbase)~=nil) then
if (string.find(secCode,Optionbase)~=nil ) then

days_to_mat = getParamEx(classCode,sec,"DAYS_TO_MAT_DATE").param_value+0
len = string.len(sec)
last_char = string.sub(sec, len)

p={
["code"]=getParamEx(classCode,sec,"code").param_image,
["Name"]=getSecurityInfo(classCode,sec).name,
["DAYS_TO_MAT_DATE"]=getParamEx(classCode,sec,"DAYS_TO_MAT_DATE").param_value+0,
["BID"]=getParamEx(classCode,sec,"BID").param_value+0,
["OFFER"]=getParamEx(classCode,sec,"OFFER").param_value+0,
["OPTIONBASE"]=getParamEx(classCode,sec,"optionbase").param_image,
["OPTIONTYPE"]=getParamEx(classCode,sec,"optiontype").param_image,
["Longname"]=getParamEx(classCode,sec,"longname").param_image,
["shortname"]=getParamEx(classCode,sec,"shortname").param_image,
["Volatility"]=getParamEx(classCode,sec,"volatility").param_value+0,
["Strike"]=getParamEx(classCode,sec,"strike").param_value+0
}
--log("Last char:"..last_char)
--log("Type:"..type(tonumber(last_char)))
if(tonumber(last_char) ~= nil) then
-- log("Convert: "..tonumber(last_char))
month = true
end




if( tonumber(days_to_mat) <= 8 ) then
-- log("this week".."Sec:"..sec.." Days:"..days_to_mat)
week = true
else
-- log("Sec:"..sec.." Days:"..days_to_mat)
end

table.insert( t, p )
if(( tonumber(series) == 0 and week) or (tonumber(series) == 1 and month) ) or tonumber(series) == 4 then
p={
["code"]=getParamEx(classCode,sec,"code").param_image,
["Name"]=getSecurityInfo(classCode,sec).name,
["DAYS_TO_MAT_DATE"]=days_to_mat,
["BID"]=getParamEx(classCode,sec,"BID").param_value+0,
["OFFER"]=getParamEx(classCode,sec,"OFFER").param_value+0,
["OPTIONBASE"]=Optionbase,
["OPTIONTYPE"]=getParamEx(classCode,sec,"optiontype").param_image,
["Longname"]=getParamEx(classCode,sec,"longname").param_image,
["shortname"]=getParamEx(classCode,sec,"shortname").param_image,
["Volatility"]=getParamEx(classCode,sec,"volatility").param_value+0,
["Strike"]=getParamEx(classCode,sec,"strike").param_value+0,
["Lastprice"]=getParamEx(classCode,sec,"last").param_value+0,
["THEORPRICE"]=getParamEx(classCode,sec,"THEORPRICE").param_value+0,
["MAT_DATE"]=getParamEx(classCode,sec,"MAT_DATE").param_image,
["STEPPRICET"]=getParamEx(classCode,sec,"STEPPRICET").param_value+0,
["SEC_PRICE_STEP"]=getParamEx(classCode,sec,"SEC_PRICE_STEP").param_value+0
}



table.insert( t, p )
end
end

end
Expand Down