Kurlyk
Toggle main menu visibility
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
6
void
print_response
(
const
kurlyk::HttpResponsePtr
& response) {
7
KURLYK_PRINT
<<
"Headers:"
<< std::endl;
8
for
(
const
auto
& header : response->headers) {
9
KURLYK_PRINT
<< header.first <<
": "
<< header.second << std::endl;
10
}
11
12
KURLYK_PRINT
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
21
int
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
();
49
kurlyk::deinit
();
50
return
0;
51
}
print_response
void print_response(const kurlyk::HttpResponsePtr &response)
Definition
bybit_funding_history_example.cpp:6
main
int main()
Definition
bybit_funding_history_example.cpp:21
kurlyk::HttpClient
Concrete HTTP client for making requests to a specific host.
Definition
HttpClient.hpp:17
kurlyk::HttpClient::set_rate_limit_rps
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).
Definition
HttpClient.hpp:327
kurlyk::HttpClient::get
bool get(const std::string &path, const QueryParams &query, const Headers &headers, HttpResponseCallback callback)
Sends a GET request.
Definition
HttpClient.hpp:681
kurlyk::HttpClient::cancel_requests
void cancel_requests()
Cancels requests associated with this client and waits for cancellation callbacks.
Definition
HttpClient.hpp:52
kurlyk.hpp
Main header file for the Kurlyk library, providing HTTP and WebSocket support.
kurlyk::init
void init(const bool use_async=true)
Initializes the Kurlyk library, setting up necessary managers and the network worker.
Definition
runtime.hpp:13
kurlyk::HttpResponsePtr
std::unique_ptr< HttpResponse > HttpResponsePtr
Owning pointer to an HTTP response.
Definition
HttpResponse.hpp:36
kurlyk::deinit
void deinit()
Deinitializes the Kurlyk library, stopping async processing or cleaning up synchronous state.
Definition
runtime.hpp:26
kurlyk::Headers
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
Definition
CaseInsensitiveMultimap.hpp:62
kurlyk::QueryParams
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
Definition
CaseInsensitiveMultimap.hpp:65
KURLYK_PRINT
#define KURLYK_PRINT
Definition
print_utils.hpp:8
examples
bybit_funding_history_example.cpp
Generated by
1.17.0