-
Notifications
You must be signed in to change notification settings - Fork 35
/
kapi.hpp
89 lines (62 loc) · 2.29 KB
/
kapi.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef _KRAKEN_KAPI_HPP_
#define _KRAKEN_KAPI_HPP_
#include <map>
#include <string>
#include <vector>
#include <curl/curl.h>
//------------------------------------------------------------------------------
namespace Kraken {
//------------------------------------------------------------------------------
class KAPI {
public:
// helper type to make requests
typedef std::map<std::string,std::string> Input;
// constructor with all explicit parameters
KAPI(const std::string& key, const std::string& secret,
const std::string& url, const std::string& version);
// default API base URL and API version
KAPI(const std::string& key, const std::string& secret);
// constructor with empty API key and API secret
KAPI();
// destructor
~KAPI();
// makes public method to kraken.com
std::string public_method(const std::string& method,
const KAPI::Input& input) const;
// makes private method to kraken.com
std::string private_method(const std::string& method,
const KAPI::Input& input) const;
// TODO: public market data
//void time();
//void assets();
private:
// init CURL and other stuffs
void init();
// TODO: gather common commands from public_method and
// private_method in a single method: curl_perform
// create signature for private requests
std::string signature(const std::string& path,
const std::string& nonce,
const std::string& postdata) const;
// CURL callback
static size_t write_cb(char* ptr, size_t size,
size_t nmemb, void* userdata);
std::string key_; // API key
std::string secret_; // API secret
std::string url_; // API base URL
std::string version_; // API version
CURL* curl_; // CURL handle
// disallow copying
KAPI(const KAPI&);
KAPI& operator=(const KAPI&);
};
//------------------------------------------------------------------------------
// helper functions to initialize and terminate Kraken API library.
// KAPI uses CURL, the latter has a no thread-safe function called
// curl_global_init().
void initialize();
void terminate();
//------------------------------------------------------------------------------
}; // namespace Kraken
//------------------------------------------------------------------------------
#endif