Uh oh!
There was an error while loading. Please reload this page.
forked from MMquant/bfx-cpp-api
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitfinexAPI.hpp
More file actions
Latest commit
156 lines (133 loc) · 6.13 KB
/
Copy pathBitfinexAPI.hpp
File metadata and controls
156 lines (133 loc) · 6.13 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//////////////////////////////////////////////////////////////////////////////
// BitfinexAPI.hpp
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include<iostream>
#include<curl/curl.h>
#include<vector>
using std::string;
using std::vector;
classBitfinexAPI
{
public:
// Enumerations
enum bfxERR // positive values for curl internal error codes
{
curlERR = -50,
badSymbol = -40,
badCurrency = -39,
badDepositMethod = -38,
badWalletType = -37,
requiredParamsMissing = -36,
wireParamsMissing = -35,
addressParamsMissing = -34,
badOrderType = -33
};
// Structure for multiple new orders endpoint
structsOrder
{
string symbol;
double amount;
double price;
string side;
string type;
};
typedef vector<sOrder> vOrders;
typedef vector<longlong> vIds;
// Constructor - destructor
explicitBitfinexAPI(const string &accessKey, const string &secretKey);
~BitfinexAPI();
// Accessors
string getWDconfFilePath() const { return WDconfFilePath; }
voidsetWDconfFilePath(const string &path) { WDconfFilePath = path; }
/// Public endpoints ///
intgetTicker(string &result, const string &symbol);
intgetStats(string &result, const string &symbol);
intgetFundingBook(string &result, const string ¤cy, constint &limit_bids = 50,
constint &limit_asks = 50);
intgetOrderBook(string &result, const string &symbol, constint &limit_bids = 50,
constint &limit_asks = 50, constbool &group = 1);
intgetTrades(string &result, const string &symbol, consttime_t &since = 0,
constint &limit_trades = 50);
intgetLends(string &result, const string ¤cy, consttime_t &since = 0,
constint &limit_lends = 50);
intgetSymbols(string &result);
intgetSymbolDetails(string &result);
/// Authenticated endpoints ///
// Account
intgetAccountInfo(string &result);
intgetSummary(string &result);
intdeposit(string &result, const string &method, const string &walletType,
constbool &renew = 0);
intgetKeyPermissions(string &result);
intgetMarginInfos(string &result);
intgetBalances(string &result);
inttransfer(string &result, constdouble &amount, const string ¤cy,
const string &walletfrom, const string &walletto);
intwithdraw(string &result); // configure withdraw.conf file before use
// Orders
intnewOrder(string &result, const string &symbol, constdouble &amount,
constdouble &price, const string &side, const string &type,
constbool &is_hidden = 0, constbool &is_postonly = 0,
constbool &use_all_available = 0, constbool &ocoorder = 0,
constdouble &buy_price_oco = 0);
intnewOrders(string &result, const vOrders &orders);
intcancelOrder(string &result, constlonglong &order_id);
intcancelOrders(string &result, const vIds &vOrder_ids);
intcancelAllOrders(string &result);
intreplaceOrder(string &result, constlonglong &order_id, const string &symbol,
constdouble &amount, constdouble &price, const string &side,
const string &type, constbool &is_hidden = 0,
constbool &use_remaining = 0);
intgetOrderStatus(string &result, constlonglong &order_id);
intgetActiveOrders(string &result);
// Positions
intgetActivePositions(string &result);
intclaimPosition(string &result, longlong &position_id, constdouble &amount);
// Historical data
intgetBalanceHistory(string &result, const string ¤cy, consttime_t &since = 0,
consttime_t &until = 0, constint &limit = 500,
const string &walletType = "all");
intgetDWHistory(string &result, const string ¤cy, const string &method = "all",
consttime_t &since = 0 , consttime_t &until = 0,
constint &limit = 500);
intgetPastTrades(string &result, const string &symbol, consttime_t ×tamp,
consttime_t &until = 0, constint &limit_trades = 500,
constbool reverse = 0);
// Margin funding
intnewOffer(string &result, const string ¤cy, constdouble &amount,
constfloat &rate, constint &period, const string &direction);
intcancelOffer(string &result, constlonglong &offer_id);
intgetOfferStatus(string &result, constlonglong &offer_id);
intgetActiveCredits(string &result);
intgetOffers(string &result);
intgetTakenFunds(string &result);
intgetUnusedTakenFunds(string &result);
intgetTotalTakenFunds(string &result);
intcloseLoan(string &result, constlonglong &offer_id);
private:
// BitfinexAPI object cannot be copied
BitfinexAPI(const BitfinexAPI&);
BitfinexAPI &operator=(const BitfinexAPI&);
// Private variables
vector<string> symbols; // possible symbol pairs
vector<string> currencies; // possible currencies
vector<string> methods; // possible deposit methods
vector<string> walletTypes; // possible walletTypes
vector<string> types; // possible Types (see new order endpoint)
string WDconfFilePath;
string APIurl;
string accessKey, secretKey;
CURL *curl;
CURLcode res;
// Utility private methods
intparseWDconfParams(string ¶ms);
static string bool2string(constbool &in);
static string getTonce();
staticintgetBase64(const string &content, string &base64);
staticintgetHmacSha384(const string &key, const string &content, string &digest);
staticsize_tWriteCallback(void *contents, size_t size, size_t nmemb, void *userp);
staticboolinArray(const string &value, const vector<string> &symbols);
intDoGETrequest(const string &UrlEndPoint, const string ¶ms, string &result);
intDoPOSTrequest(const string &UrlEndPoint, const string ¶ms, string &result);
};