binance-exchange / binacpp

Binance C++ library
MIT License
209 stars 108 forks source link

Wrong get_current_ms_epoch() Returned? #43

Open CMLDMR opened 4 years ago

CMLDMR commented 4 years ago

get_current_ms_epoch() function return stupid unsigned long.

if back to readable format , that show 2055/../..

at here;

void BinaCPP::get_account( long recvWindow, Json::Value &json_result )

ghost commented 3 years ago

For some reason, the return type of get_current_ms_epoch() is unsigned long, which is way too small to store the value of unix epoch time in miliseconds.

However, I've managed to fix this by ditching get_current_ms_epoch(), and creating a new function that returns the millisecond part of the number and appending the seconds part and milliseconds part to the string separately.

In binapp_utils.cpp I added:

unsigned long get_current_epoch_decimal_place() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_usec / 1000;
}

And with querystring.append(to_string(get_current_ms_epoch())) in BinaCPP::get_account, I replaced it with

querystring.append( to_string( get_current_epoch() ) );
querystring.append(to_string(get_current_epoch_decimal_place()));