Add HttpMethod "DELETE"

In Binance's REST api, orders are canceled via DELETE requests.
This commit is contained in:
John Colvin committed 2024-12-21 20:01:55 +00:00
1 parent d05d91bbe7
commit 142e1bd2da
3 files changed
+28 -1

No files matched your search

+2 -1
View File
@@ -15,7 +15,8 @@ namespace bts::io::http {
per_value(HttpMethod, NONE) \
per_value(HttpMethod, GET) \
per_value(HttpMethod, POST) \
per_value(HttpMethod, PUT)
per_value(HttpMethod, PUT) \
per_value(HttpMethod, DELETE)
// clang-format on
/**
+17
View File
@@ -72,6 +72,19 @@ void HttpClient::put(
send(req, response);
}
void HttpClient::del(
string url,
string body,
unordered_map<string, string> headers,
IHttpResponse *response) {
HttpRequest req;
req.url = std::move(url);
req.body = std::move(body);
req.headers = std::move(headers);
req.method = io::http::HttpMethod::DELETE;
send(req, response);
}
void HttpClient::send(const HttpRequest &req, IHttpResponse *response) {
LOG(Http, Info, "HttpClient::send. {}", JsonDumper::dump(req));
CurlSession session;
@@ -102,6 +115,10 @@ void HttpClient::send(const HttpRequest &req, IHttpResponse *response) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, req.body.size());
break;
case io::http::HttpMethod::DELETE:
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req.body.c_str());
break;
case io::http::HttpMethod::NONE:
default:
break;
+9
View File
@@ -38,6 +38,15 @@ class HttpClient {
std::unordered_map<std::string, std::string> headers,
IHttpResponse *response);
/**
* Performs an http DELETE request
*/
static void del(
std::string url,
std::string body,
std::unordered_map<std::string, std::string> headers,
IHttpResponse *response);
/**
* Requests an oauth access token
*