Kurlyk
Loading...
Searching...
No Matches
bybit_funding_history_example.cpp
Go to the documentation of this file.
1#define KURLYK_AUTO_INIT 0
2#include <kurlyk.hpp>
3#include <iostream>
4
5// Thread-safe logging of response details
7 KURLYK_PRINT << "Headers:" << std::endl;
8 for (const auto& header : response->headers) {
9 KURLYK_PRINT << header.first << ": " << header.second << std::endl;
10 }
11
13 << "Request complete:" << std::endl
14 << "Ready: " << response->ready << std::endl
15 << "Content: " << response->content << std::endl
16 << "Error Code: " << response->error_code << std::endl
17 << "Status Code: " << response->status_code << std::endl
18 << "----------------------------------------" << std::endl;
19}
20
21int main() {
22 kurlyk::init(true);
23 kurlyk::HttpClient client("https://api.bybit.com");
24 client.set_rate_limit_rps(10); // According to Bybit's API documentation, the rate limit for this endpoint is 10 requests per second.
25
26 // Direct URL request
27 KURLYK_PRINT << "Sending request with direct URL..." << std::endl;
28 client.get("/v5/market/funding/history?category=linear&symbol=ETHPERP&limit=1", kurlyk::QueryParams(), kurlyk::Headers(),
29 [](const kurlyk::HttpResponsePtr response) {
30 print_response(response);
31 });
32
33 // Request with QueryParams
34 KURLYK_PRINT << "Sending request using QueryParams..." << std::endl;
35 kurlyk::QueryParams params = {
36 {"category", "linear"},
37 {"symbol", "ETHPERP"},
38 {"limit", "1"}
39 };
40
41 client.get("/v5/market/funding/history", params, kurlyk::Headers(),
42 [](const kurlyk::HttpResponsePtr response) {
43 print_response(response);
44 });
45
46 KURLYK_PRINT << "Press Enter to exit..." << std::endl;
47 std::cin.get();
48 client.cancel_requests();
50 return 0;
51}
void print_response(const kurlyk::HttpResponsePtr &response)
Concrete HTTP client for making requests to a specific host.
void set_rate_limit_rps(long requests_per_second, RateLimitType type=RateLimitType::RL_GENERAL, bool sequential=false)
Sets the rate limit based on requests per second (RPS).
bool get(const std::string &path, const QueryParams &query, const Headers &headers, HttpResponseCallback callback)
Sends a GET request.
void cancel_requests()
Cancels requests associated with this client and waits for cancellation callbacks.
Main header file for the Kurlyk library, providing HTTP and WebSocket support.
void init(const bool use_async=true)
Initializes the Kurlyk library, setting up necessary managers and the network worker.
Definition runtime.hpp:13
std::unique_ptr< HttpResponse > HttpResponsePtr
Owning pointer to an HTTP response.
void deinit()
Deinitializes the Kurlyk library, stopping async processing or cleaning up synchronous state.
Definition runtime.hpp:26
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
#define KURLYK_PRINT