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

slow http performance #15

Open
baker-Xie opened this issue Jul 20, 2020 · 3 comments
Open

slow http performance #15

baker-Xie opened this issue Jul 20, 2020 · 3 comments

Comments

@baker-Xie
Copy link

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

@dmikushin
Copy link
Owner

dmikushin commented Jul 20, 2020

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?

@baker-Xie
Copy link
Author

baker-Xie commented Jul 21, 2020

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)

@mussonero
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants