niXman / binapi

Binance API C++ implementation
Apache License 2.0
264 stars 88 forks source link

Time and parse issue #19

Closed gitkornel closed 3 years ago

gitkornel commented 3 years ago

Hello, I'm getting error in type.cpp line 568 when using the main example,

assert(json.is_valid());
exchange_info_t res{};

And at,

std::string read_file(const char* fname) {
    std::ifstream file(fname);
    assert(file);

    std::string res{
         (std::istreambuf_iterator<char>(file))
        ,(std::istreambuf_iterator<char>())
    };

    return res;
}

The "assert(file);"

Windows x64

niXman commented 3 years ago

hi,

assert(json.is_valid());

please provide me the content of str with length len.

assert(file);

why you can't check yourself if fname is valid and points to an existing file? because it works for me.

gitkornel commented 3 years ago

hi,

assert(json.is_valid());

please provide me the content of str with length len.

assert(file);

why you can't check yourself if fname is valid and points to an existing file? because it works for me.

I have fixed it by syncing Windows time, anyways now I have an issue, how can I convert price.v.price * 1.4 to string so I can use it as:

auto market_sell_order = api.new_order(
        "RVNBTC",
        binapi::e_side::sell,
        binapi::e_type::limit,
        binapi::e_time::GTC,
        "0.0001",
        price.v.price * 1.4,
        nullptr,
        nullptr,
        nullptr
    );
Any ideas?
niXman commented 3 years ago

what type of price.v.price variable?

gitkornel commented 3 years ago

what type of price.v.price variable?

the double_type price;

niXman commented 3 years ago

why double_type ? double_type is just alias.

gitkornel commented 3 years ago

why double_type ? double_type is just alias.

my bad,

auto price = api.price("RVNBTC");
double x = 1.4;
std::string sell_price = (price.v.price * x).str();

std::cout << "original price: " << price.v.price << std::endl << std::endl;
std::cout << "multiplied price: " << price.v.price * 1.4 << std::endl << std::endl;
std::cout << "multiplied price to string: " << sell_price.c_str() << std::endl << std::endl;

results:

original price: 0.00000308 multiplied price: 0.00000431 multiplied price to string: 4.3119999999999997264410467323613768e-06