File tree Expand file tree Collapse file tree 5 files changed +358
-31
lines changed
Expand file tree Collapse file tree 5 files changed +358
-31
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,20 @@ _C++ Bitfinex REST API client_
66
77### Notice
88
9- *** Master*** branch contains new refactored version of the client. For old version checkout *** legacy*** branch.
9+ *** Master*** branch contains new version of the client. For old version checkout *** legacy*** branch.
1010
1111### Synopsis
1212
13- This header-only library contains class for interfacing Bitfinex REST API v1.
13+ This header-only library contains class for interfacing Bitfinex REST API v1. Current version supports response JSON
14+ schema validation.
1415
1516### Installation
1617
17- Just copy content of ` include/ ` directory into your project's ` include/ ` directory and
18+ 1 . Copy content of ` include/ ` directory into your project's ` include/ ` directory and
1819add ` #include "bfx-api-cpp/BitfinexAPI.hpp" ` in your ` .cpp ` file.
1920
21+ 2 . Copy ` doc/ ` directory with configuration files into your project.
22+
2023### Usage
2124
2225 // Create API client for both authenticated and unauthenticated requests
@@ -50,9 +53,12 @@ See self-explanatory `src/example.cpp` for general usage and more requests.
5053
5154### ToDo
5255
53- - [ ] Integrating RapidJSON
5456- [ ] Unit tests
55- - [ ] JSON Scheme validation
57+ - [x] JSON Scheme validation
58+
59+ ### Change Log
60+
61+ - 2018-07-11 Schema validation logic complete. Client currently validates public requests only.
5662
5763### Author
5864
Original file line number Diff line number Diff line change 77 "type" : " string"
88 }
99 },
10- "symbols" : {
11- "description" : " JSON schema used in https://api.bitfinex.com/v1/symbols/ endpoint" ,
12- "type" : " array" ,
13- "items" : {
14- "type" : " string"
15- },
16- "uniqueItems" : false
17- },
1810 "pubticker" : {
1911 "description" : " JSON schema used in https://api.bitfinex.com/v1/pubticker/ endpoint" ,
2012 "type" : " object" ,
5446 " volume" ,
5547 " timestamp"
5648 ]
49+ },
50+ "stats" : {
51+ "description" : " JSON schema used in https://api.bitfinex.com/v1/stats/ endpoint" ,
52+ "type" : " array" ,
53+ "items" : {
54+ "type" : " object" ,
55+ "properties" : {
56+ "period" : {
57+ "type" : " integer"
58+ },
59+ "volume" : {
60+ "type" : " string"
61+ }
62+ },
63+ "required" : [
64+ " period" ,
65+ " volume"
66+ ]
67+ }
68+ },
69+ "lendbook" : {
70+ "description" : " JSON schema used in https://api.bitfinex.com/v1/lendbook/ endpoint" ,
71+ "type" : " object" ,
72+ "properties" : {
73+ "bids" : {
74+ "type" : " array" ,
75+ "items" : {
76+ "type" : " object" ,
77+ "properties" : {
78+ "rate" : {
79+ "type" : " string"
80+ },
81+ "amount" : {
82+ "type" : " string"
83+ },
84+ "period" : {
85+ "type" : " integer"
86+ },
87+ "timestamp" : {
88+ "type" : " string"
89+ },
90+ "frr" : {
91+ "type" : " string"
92+ }
93+ },
94+ "required" : [
95+ " rate" ,
96+ " amount" ,
97+ " period" ,
98+ " timestamp" ,
99+ " frr"
100+ ]
101+ }
102+ },
103+ "asks" : {
104+ "type" : " array" ,
105+ "items" : {
106+ "type" : " object" ,
107+ "properties" : {
108+ "rate" : {
109+ "type" : " string"
110+ },
111+ "amount" : {
112+ "type" : " string"
113+ },
114+ "period" : {
115+ "type" : " integer"
116+ },
117+ "timestamp" : {
118+ "type" : " string"
119+ },
120+ "frr" : {
121+ "type" : " string"
122+ }
123+ },
124+ "required" : [
125+ " rate" ,
126+ " amount" ,
127+ " period" ,
128+ " timestamp" ,
129+ " frr"
130+ ]
131+ }
132+ }
133+ },
134+ "required" : [
135+ " bids" ,
136+ " asks"
137+ ]
138+ },
139+ "book" : {
140+ "description" : " JSON schema used in https://api.bitfinex.com/v1/book/ endpoint" ,
141+ "type" : " object" ,
142+ "properties" : {
143+ "bids" : {
144+ "type" : " array" ,
145+ "items" : {
146+ "type" : " object" ,
147+ "properties" : {
148+ "price" : {
149+ "type" : " string"
150+ },
151+ "amount" : {
152+ "type" : " string"
153+ },
154+ "timestamp" : {
155+ "type" : " string"
156+ }
157+ },
158+ "required" : [
159+ " price" ,
160+ " amount" ,
161+ " timestamp"
162+ ]
163+ }
164+ },
165+ "asks" : {
166+ "type" : " array" ,
167+ "items" : {
168+ "type" : " object" ,
169+ "properties" : {
170+ "price" : {
171+ "type" : " string"
172+ },
173+ "amount" : {
174+ "type" : " string"
175+ },
176+ "timestamp" : {
177+ "type" : " string"
178+ }
179+ },
180+ "required" : [
181+ " price" ,
182+ " amount" ,
183+ " timestamp"
184+ ]
185+ }
186+ }
187+ },
188+ "required" : [
189+ " bids" ,
190+ " asks"
191+ ]
192+ },
193+ "trades" : {
194+ "description" : " JSON schema used in https://api.bitfinex.com/v1/trades/ endpoint" ,
195+ "type" : " array" ,
196+ "items" : {
197+ "type" : " object" ,
198+ "properties" : {
199+ "timestamp" : {
200+ "type" : " integer"
201+ },
202+ "tid" : {
203+ "type" : " integer"
204+ },
205+ "price" : {
206+ "type" : " string"
207+ },
208+ "amount" : {
209+ "type" : " string"
210+ },
211+ "exchange" : {
212+ "type" : " string"
213+ },
214+ "type" : {
215+ "type" : " string"
216+ }
217+ },
218+ "required" : [
219+ " timestamp" ,
220+ " tid" ,
221+ " price" ,
222+ " amount" ,
223+ " exchange" ,
224+ " type"
225+ ]
226+ }
227+ },
228+ "lends" : {
229+ "description" : " JSON schema used in https://api.bitfinex.com/v1/lends/ endpoint" ,
230+ "type" : " array" ,
231+ "items" : {
232+ "type" : " object" ,
233+ "properties" : {
234+ "rate" : {
235+ "type" : " string"
236+ },
237+ "amount_lent" : {
238+ "type" : " string"
239+ },
240+ "amount_used" : {
241+ "type" : " string"
242+ },
243+ "timestamp" : {
244+ "type" : " integer"
245+ }
246+ },
247+ "required" : [
248+ " rate" ,
249+ " amount_lent" ,
250+ " amount_used" ,
251+ " timestamp"
252+ ]
253+ }
254+ },
255+ "symbols" : {
256+ "description" : " JSON schema used in https://api.bitfinex.com/v1/symbols/ endpoint" ,
257+ "type" : " array" ,
258+ "items" : {
259+ "type" : " string"
260+ },
261+ "uniqueItems" : false
262+ },
263+ "symbols_details" : {
264+ "description" : " JSON schema used in https://api.bitfinex.com/v1/symbols_details/ endpoint" ,
265+ "type" : " array" ,
266+ "items" : {
267+ "type" : " object" ,
268+ "properties" : {
269+ "pair" : {
270+ "type" : " string"
271+ },
272+ "price_precision" : {
273+ "type" : " integer"
274+ },
275+ "initial_margin" : {
276+ "type" : " string"
277+ },
278+ "minimum_margin" : {
279+ "type" : " string"
280+ },
281+ "maximum_order_size" : {
282+ "type" : " string"
283+ },
284+ "minimum_order_size" : {
285+ "type" : " string"
286+ },
287+ "expiration" : {
288+ "type" : " string"
289+ },
290+ "margin" : {
291+ "type" : " boolean"
292+ }
293+ },
294+ "required" : [
295+ " pair" ,
296+ " price_precision" ,
297+ " initial_margin" ,
298+ " minimum_margin" ,
299+ " maximum_order_size" ,
300+ " minimum_order_size" ,
301+ " expiration" ,
302+ " margin"
303+ ]
304+ }
57305 }
58306}
Original file line number Diff line number Diff line change @@ -1041,13 +1041,13 @@ namespace BfxAPI
10411041 }
10421042 };
10431043
1044- void doPOSTrequest (const string &UrlEndPoint , const string ¶ms)
1044+ void doPOSTrequest (const string &apiEndPoint , const string ¶ms)
10451045 {
10461046 bfxApiStatusCode_ = noError;
10471047
10481048 if (curlPOST_)
10491049 {
1050- string url = APIurl_ + UrlEndPoint ;
1050+ string url = APIurl_ + apiEndPoint ;
10511051 string payload;
10521052 string signature;
10531053 getBase64 (params, payload);
@@ -1082,11 +1082,21 @@ namespace BfxAPI
10821082 {
10831083 cerr << " Libcurl error in doPOSTrequest():\n " ;
10841084 cerr << " CURLcode: " << curlStatusCode_ << " \n " ;
1085+ bfxApiStatusCode_ = curlERR;
1086+ }
1087+ // Check schema
1088+ else
1089+ {
1090+ bfxApiStatusCode_ =
1091+ schemaValidator_.validateSchema (apiEndPoint, result_);
10851092 }
10861093
10871094 }
10881095 else
1096+ {
10891097 cerr << " curl not properly initialized curlPOST_ = nullptr" ;
1098+ bfxApiStatusCode_ = curlERR;
1099+ }
10901100 };
10911101
10921102 // //////////////////////////////////////////////////////////////////////
@@ -1156,7 +1166,8 @@ namespace BfxAPI
11561166 size_t nmemb,
11571167 void *userp) noexcept
11581168 {
1159- (static_cast <string*>(userp))->append (static_cast <char *>(response));
1169+ (static_cast <string*>(userp))->
1170+ append (static_cast <char *>(response), size * nmemb);
11601171 return size * nmemb;
11611172 };
11621173
You can’t perform that action at this time.
0 commit comments