nicehash-api-cpp  0.0.1
getOrdersByAlgorithm.cpp
Go to the documentation of this file.
1 #include <string>
2 
3 #include "../../include/nicehash-api.hpp"
4 
5 
6 /**
7  * \brief Get all orders for a given algorithm id.
8  *
9  * Get all orders for a given algorithm (data refreshed every 30 seconds).
10  * It (GET) requests https://api.nicehash.com/api?method=orders.get&location=...&algo=...
11  * where the algo is an algorithm id and location is a location id (see https://www.nicehash.com/?p=api).
12  *
13  */
14 std::string NiceHashApi::getOrdersByAlgorithm (int algorithm_id, int location_id) {
15 
16  this->throwExceptionIfAlgorithmInvalid(algorithm_id);
17  this->throwExceptionIfLocationInvalid(location_id);
18 
19  // Construct the query params (&location= and algo=)
20  std::string endpoint = "https://api.nicehash.com/api?method=orders.get";
21  std::string url = endpoint + "&location=" + std::to_string(location_id) + "&algo=" + std::to_string(algorithm_id);
22 
23  std::string response = this->client->get(url);
24 
25  return response;
26 }
27 
28 /**
29  * \brief Get all orders for a given algorithm by name.
30  *
31  * Get all orders for a given algorithm (data refreshed every 30 seconds).
32  * It (GET) requests https://api.nicehash.com/api?method=orders.get&location=...&algo=...
33  * where the algo is an algorithm id and location is a location id (see https://www.nicehash.com/?p=api).
34  *
35  */
36 std::string NiceHashApi::getOrdersByAlgorithm (std::string algorithm_name, int location_id) {
37  return this->getOrdersByAlgorithm(this->algorithmNameToId(algorithm_name), location_id);
38 }
virtual std::string get(std::string const url)
GET request the provided url and return the response body as a string.
Definition: get.cpp:14
std::string getOrdersByAlgorithm(int algorithm_id, int location_id)
Get all orders for a given algorithm id.
int algorithmNameToId(std::string algorithm_name)
Convert an algorithm name to its id.