Kurlyk
Loading...
Searching...
No Matches
bybit_funding_history_example.cpp
Go to the documentation of this file.
1#include <kurlyk.hpp>
2#include <iostream>
3
4// Thread-safe logging of response details
6 KURLYK_PRINT << "Headers:" << std::endl;
7 for (const auto& header : response->headers) {
8 KURLYK_PRINT << header.first << ": " << header.second << std::endl;
9 }
10
12 << "Request complete:" << std::endl
13 << "Ready: " << response->ready << std::endl
14 << "Content: " << response->content << std::endl
15 << "Error Code: " << response->error_code << std::endl
16 << "Status Code: " << response->status_code << std::endl
17 << "----------------------------------------" << std::endl;
18}
19
20int main() {
21 kurlyk::init(true);
22 kurlyk::HttpClient client("https://api.bybit.com");
23 client.set_rate_limit_rps(10); // According to Bybit's API documentation, the rate limit for this endpoint is 10 requests per second.
24
25 // Direct URL request
26 KURLYK_PRINT << "Sending request with direct URL..." << std::endl;
27 client.get("/v5/market/funding/history?category=linear&symbol=ETHPERP&limit=1", kurlyk::QueryParams(), kurlyk::Headers(),
28 [](const kurlyk::HttpResponsePtr response) {
29 print_response(response);
30 });
31
32 // Request with QueryParams
33 KURLYK_PRINT << "Sending request using QueryParams..." << std::endl;
34 kurlyk::QueryParams params = {
35 {"category", "linear"},
36 {"symbol", "ETHPERP"},
37 {"limit", "1"}
38 };
39
40 client.get("/v5/market/funding/history", params, kurlyk::Headers(),
41 [](const kurlyk::HttpResponsePtr response) {
42 print_response(response);
43 });
44
45 KURLYK_PRINT << "Press Enter to exit..." << std::endl;
46 std::cin.get();
47 client.cancel_requests();
49 return 0;
50}
void print_response(const kurlyk::HttpResponsePtr &response)
A client class for making HTTP requests to a specific host.
void set_rate_limit_rps(long requests_per_second, RateLimitType type=RateLimitType::RL_GENERAL)
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 the active request associated with this client and waits for its completion.
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
A unique pointer to an HttpResponse object for memory management.
void deinit()
Deinitializes the Kurlyk library, stopping the network worker and releasing resources.
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