Enfernuz / quik-lua-rpc

RPC-сервис для вызова API Lua-библиотеки торгового терминала QUIK (ARQA Technologies)
Apache License 2.0
103 stars 43 forks source link

python abrosimov.a.a/qlua getCandlesByIndex - возвращает итерации одной свечи #67

Open lumhir opened 2 years ago

lumhir commented 2 years ago

После применения костыля https://gitlab.com/abrosimov_a_a/qlua/-/issues/8 функция работает, и c квика возвращается таблица, с виду корректная, но содержащая итерацию одной и той же свечи args.count раз. То есть, приходит 6 одинаковых свечей, как в примере. На каком програмном уровне происходит ошибка и почему, самостоятельно выяснить не удается.

args.tag = 'SRH2' args.line = 0 args.first_candle = 0 args.count = 6

Параметры заданы верно, а результат так же содержит повторение лейбла 't', но возможно так и должно быть:

_t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" does_exist: 1 } t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" does_exist: 1 } t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" does_exist: 1 } t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" does_exist: 1 } t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" does_exist: 1 } t { open: "25398.0" close: "26234.0" high: "26234.0" low: "25398.0" volume: "2.0" doesexist: 1 } n: 6 l: "SRH2 [Price]"

nokados commented 7 months ago

pb.defaults returns the original default model instead of a copy of it. So, to fix it you should set candle differently:

local candle = {}
pb.defaults(qlua_pb_types.qlua_structures.CandleEntry, candle)

All local myvar = pb.defaults(type) constructions should be replaced with

local myvar = {}
pb.defaults(type, myvar)

To do this automatically, use this python script:

with open("/path/to/your/impl/protobuf_request_response_serde.lua") as f:
    with open("/path/to/your/impl/protobuf_request_response_serde_fixed.lua", "w") as out:
        for line in f:
            line_fixed = re.sub(
                r"^(?P<ident>\s*)(?P<local>local\s+)?(?P<var>[A-Za-z0-9_\.]+)\s*=\s*pb\.defaults\((?P<type>[A-Za-z0-9_\.]+)\)\s*$",
                r"\g<ident>\g<local>\g<var> = {}" + "\n" + r"\g<ident>pb.defaults(\g<type>, \g<var>)" + "\n",
                line
            )
            out.write(line_fixed)

After that, rename old protobuf_request_response_serde.lua to protobuf_request_response_serde_orig.lua and new protobuf_request_response_serde_fixed.lua to protobuf_request_response_serde.lua