trader  v0.1a
A framework to build trading applications
bittrexapi.h
1 
2 #pragma once
3 #include "app.h"
4 #include "api.h"
5 #include "bittrexconfig.h"
6 #include "helper.h"
7 
8 
9 namespace trader {
10 
11  namespace BittrexApi {
12 
13  class Balance : public Poco::RefCountedObject {
14  public:
15 
16  Balance();
17 
18  ~Balance();
19 
20  void readFile(const std::string& _fileName);
21 
22  void read(Poco::Dynamic::Var val);
23 
24  struct DataObject {
25 
26  struct ResultArray {
27 
28  void SetAvailable(double val)
29  {
30  available = val;
31  }
32 
33  bool isSetAvailable() {
34  return (available != std::numeric_limits<double>::max());
35  }
36 
37  double available;
38 
39  void SetBalance(double val)
40  {
41  balance = val;
42  }
43 
44  bool isSetBalance() {
45  return (balance != std::numeric_limits<double>::max());
46  }
47 
48  double balance;
49 
50  void SetCryptoAddress(std::string val)
51  {
52  cryptoAddress = val;
53  }
54 
55  bool isSetCryptoAddress() {
56  return (cryptoAddress != "Empty");
57  }
58 
59  std::string cryptoAddress;
60 
61  void SetCurrency(std::string val)
62  {
63  currency = val;
64  }
65 
66  bool isSetCurrency() {
67  return (currency != "Empty");
68  }
69 
70  std::string currency;
71 
72  void SetPending(double val)
73  {
74  pending = val;
75  }
76 
77  bool isSetPending() {
78  return (pending != std::numeric_limits<double>::max());
79  }
80 
81  double pending;
82 
83  void SetRequested(bool val)
84  {
85  requested = val;
86  requestedSet = true;
87  }
88 
89  bool isSetRequested() {
90  return (requestedSet != false);
91  }
92 
93  bool requested;
94  bool requestedSet;
95 
96  void SetUuid(std::string val)
97  {
98  uuid = val;
99  }
100 
101  bool isSetUuid() {
102  return (uuid != "Empty");
103  }
104 
105  std::string uuid;
106 
107  ResultArray()
108  : available(std::numeric_limits<double>::max())
109  , balance(std::numeric_limits<double>::max())
110  , cryptoAddress("Empty")
111  , currency("Empty")
112  , pending(std::numeric_limits<double>::max())
113  , requested(false)
114  , requestedSet(false)
115  , uuid("Empty")
116  {
117  }
118 
119  };
120 
121  typedef std::vector<ResultArray> Result;
122  Result result;
123  DataObject()
124  {
125  }
126 
127  };
128 
129  DataObject dataObject;
130  }; //Balance
131 
132  class BalanceParams : public Poco::RefCountedObject {
133  public:
134 
135  BalanceParams();
136 
137  ~BalanceParams();
138 
139  void readFile(const std::string& _fileName);
140 
141  void read(Poco::Dynamic::Var val);
142 
143  struct DataObject {
144 
145  // a string literal for the market (ex: BTC-LTC)
146  void SetCurrency(std::string val)
147  {
148  currency = val;
149  }
150 
151  bool isSetCurrency() {
152  return (currency != "Empty");
153  }
154 
155  std::string currency;
156 
157  DataObject()
158  : currency("Empty")
159  {
160  }
161 
162  };
163 
164  DataObject dataObject;
165  }; //BalanceParams
166 
167  class History : public Poco::RefCountedObject {
168  public:
169 
170  History();
171 
172  ~History();
173 
174  void readFile(const std::string& _fileName);
175 
176  void read(Poco::Dynamic::Var val);
177 
178  struct DataObject {
179 
180  struct ResultArray {
181 
182  void SetFillType(std::string val)
183  {
184  std::regex valRegex("FILL|PARTIAL_FILL");
185  std::string valMatch(val);
186  if (std::regex_match(valMatch, valRegex))
187  {
188  fillType = val;
189  }
190  else
191  {
192  throw Poco::RegularExpressionException("fillType invalid.");
193  }
194  }
195 
196  bool isSetFillType() {
197  return (fillType != "Empty");
198  }
199 
200  std::string fillType;
201 
202  void SetId(Poco::Int32 val)
203  {
204  id = val;
205  }
206 
207  bool isSetId() {
208  return (id != std::numeric_limits<Poco::Int32>::max());
209  }
210 
211  Poco::Int32 id;
212 
213  void SetOrderType(std::string val)
214  {
215  std::regex valRegex("BUY|SELL");
216  std::string valMatch(val);
217  if (std::regex_match(valMatch, valRegex))
218  {
219  orderType = val;
220  }
221  else
222  {
223  throw Poco::RegularExpressionException("orderType invalid.");
224  }
225  }
226 
227  bool isSetOrderType() {
228  return (orderType != "Empty");
229  }
230 
231  std::string orderType;
232 
233  void SetPrice(double val)
234  {
235  price = val;
236  }
237 
238  bool isSetPrice() {
239  return (price != std::numeric_limits<double>::max());
240  }
241 
242  double price;
243 
244  void SetQuantity(double val)
245  {
246  quantity = val;
247  }
248 
249  bool isSetQuantity() {
250  return (quantity != std::numeric_limits<double>::max());
251  }
252 
253  double quantity;
254 
255  void SetTimeStamp(FormattedTime val)
256  {
257  timeStamp = val;
258  }
259 
260  void SetTimeStamp(const std::string& val)
261  {
262  FormattedTime fmt("%Y-%m-%dT%H:%M:%S");
263  fmt = val;
264  timeStamp = fmt;
265  }
266  FormattedTime timeStamp;
267 
268  void SetTotal(double val)
269  {
270  total = val;
271  }
272 
273  bool isSetTotal() {
274  return (total != std::numeric_limits<double>::max());
275  }
276 
277  double total;
278 
279  ResultArray()
280  : fillType("Empty")
281  , id(std::numeric_limits<Poco::Int32>::max())
282  , orderType("Empty")
283  , price(std::numeric_limits<double>::max())
284  , quantity(std::numeric_limits<double>::max())
285  , timeStamp("%Y-%m-%dT%H:%M:%S")
286  , total(std::numeric_limits<double>::max())
287  {
288  }
289 
290  };
291 
292  typedef std::vector<ResultArray> Result;
293  Result result;
294  DataObject()
295  {
296  }
297 
298  };
299 
300  DataObject dataObject;
301  }; //History
302 
303  class HistoryParams : public Poco::RefCountedObject {
304  public:
305 
306  HistoryParams();
307 
308  ~HistoryParams();
309 
310  void readFile(const std::string& _fileName);
311 
312  void read(Poco::Dynamic::Var val);
313 
314  struct DataObject {
315 
316  // a string literal for the market (ex: BTC-LTC)
317  void SetMarket(std::string val)
318  {
319  market = val;
320  }
321 
322  bool isSetMarket() {
323  return (market != "Empty");
324  }
325 
326  std::string market;
327 
328  DataObject()
329  : market("Empty")
330  {
331  }
332 
333  };
334 
335  DataObject dataObject;
336  }; //HistoryParams
337 
338  class Markets : public Poco::RefCountedObject {
339  public:
340 
341  Markets();
342 
343  ~Markets();
344 
345  void readFile(const std::string& _fileName);
346 
347  void read(Poco::Dynamic::Var val);
348 
349  struct DataObject {
350 
351  struct ResultArray {
352 
353  void SetBaseCurrency(std::string val)
354  {
355  baseCurrency = val;
356  }
357 
358  bool isSetBaseCurrency() {
359  return (baseCurrency != "Empty");
360  }
361 
362  std::string baseCurrency;
363 
364  void SetBaseCurrencyLong(std::string val)
365  {
366  baseCurrencyLong = val;
367  }
368 
369  bool isSetBaseCurrencyLong() {
370  return (baseCurrencyLong != "Empty");
371  }
372 
373  std::string baseCurrencyLong;
374 
375  void SetCreated(FormattedTime val)
376  {
377  created = val;
378  }
379 
380  void SetCreated(const std::string& val)
381  {
382  FormattedTime fmt("%Y-%m-%dT%H:%M:%S");
383  fmt = val;
384  created = fmt;
385  }
386  FormattedTime created;
387 
388  void SetIsActive(bool val)
389  {
390  isActive = val;
391  isActiveSet = true;
392  }
393 
394  bool isSetIsActive() {
395  return (isActiveSet != false);
396  }
397 
398  bool isActive;
399  bool isActiveSet;
400 
401  void SetLogoUrl(std::string val)
402  {
403  logoUrl = val;
404  }
405 
406  bool isSetLogoUrl() {
407  return (logoUrl != "Empty");
408  }
409 
410  std::string logoUrl;
411 
412  void SetMarketCurrency(std::string val)
413  {
414  marketCurrency = val;
415  }
416 
417  bool isSetMarketCurrency() {
418  return (marketCurrency != "Empty");
419  }
420 
421  std::string marketCurrency;
422 
423  void SetMarketCurrencyLong(std::string val)
424  {
425  marketCurrencyLong = val;
426  }
427 
428  bool isSetMarketCurrencyLong() {
429  return (marketCurrencyLong != "Empty");
430  }
431 
432  std::string marketCurrencyLong;
433 
434  void SetMarketName(std::string val)
435  {
436  marketName = val;
437  }
438 
439  bool isSetMarketName() {
440  return (marketName != "Empty");
441  }
442 
443  std::string marketName;
444 
445  void SetMinTradeSize(Poco::Int32 val)
446  {
447  minTradeSize = val;
448  }
449 
450  bool isSetMinTradeSize() {
451  return (minTradeSize != std::numeric_limits<Poco::Int32>::max());
452  }
453 
454  Poco::Int32 minTradeSize;
455 
456  void SetNotice(std::string val)
457  {
458  notice = val;
459  }
460 
461  bool isSetNotice() {
462  return (notice != "Empty");
463  }
464 
465  std::string notice;
466 
467  ResultArray()
468  : baseCurrency("Empty")
469  , baseCurrencyLong("Empty")
470  , created("%Y-%m-%dT%H:%M:%S")
471  , isActive(false)
472  , isActiveSet(false)
473  , logoUrl("Empty")
474  , marketCurrency("Empty")
475  , marketCurrencyLong("Empty")
476  , marketName("Empty")
477  , minTradeSize(std::numeric_limits<Poco::Int32>::max())
478  , notice("Empty")
479  {
480  }
481 
482  };
483 
484  typedef std::vector<ResultArray> Result;
485  Result result;
486  DataObject()
487  {
488  }
489 
490  };
491 
492  DataObject dataObject;
493  }; //Markets
494 
495  class OrderBook : public Poco::RefCountedObject {
496  public:
497 
498  OrderBook();
499 
500  ~OrderBook();
501 
502  void readFile(const std::string& _fileName);
503 
504  void read(Poco::Dynamic::Var val);
505 
506  struct DataObject {
507 
508  struct ResultArray {
509 
510  void SetQuantity(double val)
511  {
512  quantity = val;
513  }
514 
515  bool isSetQuantity() {
516  return (quantity != std::numeric_limits<double>::max());
517  }
518 
519  double quantity;
520 
521  void SetRate(double val)
522  {
523  rate = val;
524  }
525 
526  bool isSetRate() {
527  return (rate != std::numeric_limits<double>::max());
528  }
529 
530  double rate;
531 
532  ResultArray()
533  : quantity(std::numeric_limits<double>::max())
534  , rate(std::numeric_limits<double>::max())
535  {
536  }
537 
538  };
539 
540  typedef std::vector<ResultArray> Result;
541  Result result;
542  DataObject()
543  {
544  }
545 
546  };
547 
548  DataObject dataObject;
549  }; //OrderBook
550 
551  class OrderBookBoth : public Poco::RefCountedObject {
552  public:
553 
554  OrderBookBoth();
555 
556  ~OrderBookBoth();
557 
558  void readFile(const std::string& _fileName);
559 
560  void read(Poco::Dynamic::Var val);
561 
562  struct DataObject {
563 
564  struct ResultObject {
565 
566  struct BuyArray {
567 
568  void SetQuantity(double val)
569  {
570  quantity = val;
571  }
572 
573  bool isSetQuantity() {
574  return (quantity != std::numeric_limits<double>::max());
575  }
576 
577  double quantity;
578 
579  void SetRate(double val)
580  {
581  rate = val;
582  }
583 
584  bool isSetRate() {
585  return (rate != std::numeric_limits<double>::max());
586  }
587 
588  double rate;
589 
590  BuyArray()
591  : quantity(std::numeric_limits<double>::max())
592  , rate(std::numeric_limits<double>::max())
593  {
594  }
595 
596  };
597 
598  typedef std::vector<BuyArray> Buy;
599  Buy buy;
600  struct SellArray {
601 
602  void SetQuantity(double val)
603  {
604  quantity = val;
605  }
606 
607  bool isSetQuantity() {
608  return (quantity != std::numeric_limits<double>::max());
609  }
610 
611  double quantity;
612 
613  void SetRate(double val)
614  {
615  rate = val;
616  }
617 
618  bool isSetRate() {
619  return (rate != std::numeric_limits<double>::max());
620  }
621 
622  double rate;
623 
624  SellArray()
625  : quantity(std::numeric_limits<double>::max())
626  , rate(std::numeric_limits<double>::max())
627  {
628  }
629 
630  };
631 
632  typedef std::vector<SellArray> Sell;
633  Sell sell;
634  ResultObject()
635  {
636  }
637 
638  };
639 
640  ResultObject resultObject;
641  DataObject()
642  {
643  }
644 
645  };
646 
647  DataObject dataObject;
648  }; //OrderBookBoth
649 
650  class OrderBookParams : public Poco::RefCountedObject {
651  public:
652 
653  OrderBookParams();
654 
655  ~OrderBookParams();
656 
657  void readFile(const std::string& _fileName);
658 
659  void read(Poco::Dynamic::Var val);
660 
661  struct DataObject {
662 
663  // a string literal for the market (ex: BTC-LTC)
664  void SetMarket(std::string val)
665  {
666  market = val;
667  }
668 
669  bool isSetMarket() {
670  return (market != "Empty");
671  }
672 
673  std::string market;
674 
675  // buy, sell or both to identify the type of orderbook to return
676  void SetType(std::string val)
677  {
678  std::regex valRegex("buy|sell|both");
679  std::string valMatch(val);
680  if (std::regex_match(valMatch, valRegex))
681  {
682  type = val;
683  }
684  else
685  {
686  throw Poco::RegularExpressionException("type invalid.");
687  }
688  }
689 
690  bool isSetType() {
691  return (type != "Empty");
692  }
693 
694  std::string type;
695 
696  DataObject()
697  : market("Empty")
698  , type("Empty")
699  {
700  }
701 
702  };
703 
704  DataObject dataObject;
705  }; //OrderBookParams
706 
707  class ResultIntrospector : public Poco::RefCountedObject {
708  public:
709 
711 
713 
714  void readFile(const std::string& _fileName);
715 
716  void read(Poco::Dynamic::Var val);
717 
718  struct DataObject {
719 
720  void SetMessage(std::string val)
721  {
722  message = val;
723  }
724 
725  bool isSetMessage() {
726  return (message != "Empty");
727  }
728 
729  std::string message;
730 
731  void SetSuccess(bool val)
732  {
733  success = val;
734  successSet = true;
735  }
736 
737  bool isSetSuccess() {
738  return (successSet != false);
739  }
740 
741  bool success;
742  bool successSet;
743 
744  DataObject()
745  : message("Empty")
746  , success(false)
747  , successSet(false)
748  {
749  }
750 
751  };
752 
753  DataObject dataObject;
754  }; //ResultIntrospector
755 
756  class EndPoints {
757  public:
758 
759  EndPoints(Poco::AutoPtr<trader::App> app, Api* api);
760 
761  ~EndPoints();
762 
763 
764  // Used to get the open and available trading markets at Bittrex along with other meta data.
765  Poco::AutoPtr<Markets> GetMarkets();
766 
767  // Used to retrieve all balances from your account
768  Poco::AutoPtr<Balance> GetBalance(Poco::AutoPtr<BalanceParams> balanceParams);
769 
770  // Used to retrieve the latest trades that have occured for a specific market
771  Poco::AutoPtr<History> GetMarketHistory(Poco::AutoPtr<HistoryParams> historyParams);
772 
773  // Used to get retrieve the orderbook for a given market
774  Poco::AutoPtr<OrderBook> GetOrderBook(Poco::AutoPtr<OrderBookParams> orderBookParams);
775 
776  // Used to get retrieve the orderbook for a given market
777  Poco::AutoPtr<OrderBookBoth> GetBothOrderBooks(Poco::AutoPtr<OrderBookParams> orderBookParams);
778 
779  BittrexConfig config;
780 
781  Poco::AutoPtr<trader::App> _app;
782  Api* _api;
783  std::string _uri;
784  }; //EndPoints
785 
786  } //BittrexApi
787 } //trader
Definition: bittrexapi.h:756
Definition: bittrexconfig.h:7
Definition: bittrexapi.h:551
Definition: bittrexapi.h:303
Definition: bittrexapi.h:13
Definition: bittrexapi.h:132
Definition: bittrexapi.h:650
Definition: bittrexapi.h:167
Definition: bittrexapi.h:338
Definition: api.h:15
Definition: bittrexapi.h:349
Definition: bittrexapi.h:495
Definition: bittrexapi.h:24
Definition: bittrexapi.h:707
Definition: bittrexapi.h:506
Definition: bittrexapi.h:178
Definition: app.h:7