|
| 1 | +////////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// example.cpp |
| 4 | +// |
| 5 | +// |
| 6 | +// Bitfinex REST API C++ client - examples |
| 7 | +// |
| 8 | +////////////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +// std |
| 11 | +#include <fstream> |
| 12 | +#include <iostream> |
| 13 | + |
| 14 | +// BitfinexAPI |
| 15 | +#include "BitfinexAPI.hpp" |
| 16 | + |
| 17 | + |
| 18 | +// namespaces |
| 19 | +using std::cout; |
| 20 | +using std::endl; |
| 21 | +using std::ifstream; |
| 22 | +using std::string; |
| 23 | + |
| 24 | + |
| 25 | +int main(int argc, char *argv[]) |
| 26 | +{ |
| 27 | + ///////////////////////////////////////////////////////////////////////// |
| 28 | + // Examples |
| 29 | + // Note that default values are not mandatory. See BitfinexAPI.hpp |
| 30 | + // for details. |
| 31 | + ///////////////////////////////////////////////////////////////////////// |
| 32 | + |
| 33 | + ///////////////////////////////////////////////////////////////////////// |
| 34 | + // GET REQUESTS - unauthenticated endpoints |
| 35 | + ///////////////////////////////////////////////////////////////////////// |
| 36 | + |
| 37 | + BfxAPI::BitfinexAPI bfxAPI; |
| 38 | + |
| 39 | + bfxAPI.getTicker("btcusd"); |
| 40 | + if (!bfxAPI.hasApiError()) |
| 41 | + cout << bfxAPI.strResponse() << endl; |
| 42 | + else |
| 43 | + { |
| 44 | + // see bfxERR enum in BitfinexAPI.hpp::BitfinexAPI |
| 45 | + cout << bfxAPI.getBfxApiStatusCode() << endl; |
| 46 | + // see https://curl.haxx.se/libcurl/c/libcurl-errors.html |
| 47 | + cout << bfxAPI.getCurlStatusCode() << endl; |
| 48 | + } |
| 49 | + |
| 50 | + bfxAPI.getStats("btcusd"); |
| 51 | + if (!bfxAPI.hasApiError()) |
| 52 | + cout << bfxAPI.strResponse() << endl; |
| 53 | + else |
| 54 | + { |
| 55 | + // see bfxERR enum in BitfinexAPI.hpp::BitfinexAPI |
| 56 | + cout << bfxAPI.getBfxApiStatusCode() << endl; |
| 57 | + // see https://curl.haxx.se/libcurl/c/libcurl-errors.html |
| 58 | + cout << bfxAPI.getCurlStatusCode() << endl; |
| 59 | + } |
| 60 | + |
| 61 | + return 0; |
| 62 | + |
| 63 | +} |
0 commit comments