binance-cxx-api icon indicating copy to clipboard operation
binance-cxx-api copied to clipboard

slow http performance

Open baker-Xie opened this issue 4 years ago • 3 comments

Hello I tested this library and python one When call the same restful API , this library costs 800ms and python library only cost 300ms . Is there any way to imporve the performance? Is the problem with keep alive? Thanks

baker-Xie avatar Jul 20 '20 14:07 baker-Xie

Dear @baker-Xie thank you for your testing! I could imagine the first connection is slower than subsequent ones, due to initialization overhead. A lot of other aspects may be involved, depending on how the actual test is designed. Would it be possible for you to publish and/or attach here your test code for our further analysis?

dmikushin avatar Jul 20 '20 15:07 dmikushin

Dear @dmikushin , Thanks for you reply. I'll paste my code here. (1) The first http call of binance-cxx-api is slow of course, but the rest http calls are slow too (800ms) (2) The python library is python-binance, please use pip install python-binance to install it.

Meanwhile, I have a question (1) About the sendOrder API There is quantity and price parameter which is double . But from website, there is minQty and tickSize. So we should guarantee that our price/quantity parameter are multiple to minQty/tickSize. But in your API, price/quantity are double, and I didn't see further post-process about them. So, if I use this API, should I pass a valid price/quantity , or you code will post-process for me? For example, minQty = 0.01 tickSize = 0.1 if my quantity is 0.015, my price is 1.12, should I just pass quantity=0.015 / price =1.12 to APi, or should I pass quantity = 0.01 and price = 1.1 to API?

c++ test code:

#include <iostream>
#include <json/json.h>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

#include "binance.h"
#include "binance_logger.h"
#include "binance_websocket.h"
#include "sys/time.h"

using namespace binance;

using std::map;
using std::vector;
using std::string;
using std::cout;
using std::endl;

unsigned long long GetTimestamp()
{
    struct timeval temp;
    gettimeofday(&temp, nullptr);
    return temp.tv_sec * 1e6 + temp.tv_usec;
}

int main()
{
    Json::Value result;

    auto _server = new Server;
    auto _market = new Market(*_server);

    auto beginTime = GetTimestamp();
    _market->getDepth(result, "LINKBTC", 5);
    auto endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;

    beginTime = GetTimestamp();
    _market->getDepth(result, "ETHTUSD", 5);
    endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;

    beginTime = GetTimestamp();
    _market->getDepth(result, "LINKETH", 5);
    endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;

    beginTime = GetTimestamp();
    _market->getDepth(result, "IOTABTC", 5);
    endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;

    beginTime = GetTimestamp();
    _market->getExchangeInfo(result);
    endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;

    beginTime = GetTimestamp();
    _market->getExchangeInfo(result);
    endTime = GetTimestamp();
    cout << (endTime-beginTime) << endl;
}

Pyhon test code:

from binance.client import Client as Client_Binance
from binance.enums import *
import time

binance_api_key = 'XXX'
binance_api_secret = 'XXX'

clientB = Client_Binance(binance_api_key, binance_api_secret)

beginTime = time.time()
depthB = clientB.get_order_book(symbol="LINKBTC", limit=5)
print(time.time() - beginTime)

beginTime = time.time()
depthB = clientB.get_order_book(symbol="ETHTUSD", limit=5)
print(time.time() - beginTime)

beginTime = time.time()
depthB = clientB.get_order_book(symbol="LINKETH", limit=5)
print(time.time() - beginTime)

beginTime = time.time()
depthB = clientB.get_order_book(symbol="IOTABTC", limit=5)
print(time.time() - beginTime)

beginTime = time.time()
depthB = clientB.get_order_book(symbol="IOTAETH", limit=5)
print(time.time() - beginTime)

baker-Xie avatar Jul 21 '20 01:07 baker-Xie

@baker-Xie,

  1. I did multiple tests using the examples provided, also I have added a high-resolution clock to both C++ and the python code, it is practically unnoticeable the difference. 0.04ms~0.06ms But still, python gets nice results 👍. test

  2. Regarding your question (1) About the sendOrder API You need to post-process manually

mussonero avatar Jul 25 '20 17:07 mussonero