flashnuke / BinanceExtensionCPP

An extension for the API of Binance (https://www.binance.com/)
GNU General Public License v3.0
14 stars 4 forks source link

Malformed klines #59

Closed VitalyVaryvdin closed 3 years ago

VitalyVaryvdin commented 3 years ago

Getting klines I'm randomly receiving malformed kline object which is always last in response

],
        [
                1622667600000,
                "1.81059000",
                "1.81856000",
                "1.80819000",
                "1.81000000",
                "3131994.90000000",
                1622669399999,
                "5679722.58880500",
                8036,
                "1450047.50000000",
                "2630337.35958400",
                "0"
        ],
        [
                1622669400000,
                "1.81000000",
                null
        ]
][
        [
                1622671200000,
                "1.81245000",
                "1.81966000",
                "1.81000000",
                "1.81183000",
                "3189448.30000000",
                1622672999999,
                "5783082.03389300",
                7960,
                "1224261.90000000",
                "2220666.73000300",
                "0"
        ],

You can see it here between two good klines. Didn't happen with python-binance so i thought that might be library issue. Json above is formed by doing multiple requests so in this case it's not last in the list.

VitalyVaryvdin commented 3 years ago

Found the issue.

Use of curl writefunction callback is incorrect.

  1. Callback might be called many times within single request. In other words callback call doesn't mean it received all the data it could.
  2. Returning anything than nmemb aborts the request.

    callback should return the number of bytes actually taken care of. If that amount differs from the amount passed to your callback function, it'll signal an error condition to the library.

Changed callback to only append response data to RequestHandler and removed everything else. Also, json parsing should happen right after curl_easy_perform, or at any point below that.

flashnuke commented 3 years ago

Hey @VitalyVaryvdin Can you please share the code snippet that solved this issue here?

flashnuke commented 3 years ago

thanks for bringing this up, fixed and tested in https://github.com/adanikel/BinanceExtensionCPP/pull/60 I will apply a few more minor changes and release a new version, let me know if this can be closed

VitalyVaryvdin commented 3 years ago

Sorry for late reply Glad to be helpful :) Yeah, im closing this now, just wanted to make sure you see it before closing