trader  v0.1a
A framework to build trading applications
cryptowatchdatabase.h
1 
2 #pragma once
3 
4 
5 namespace trader {
6 
7  namespace CryptowatchDatabase {
8 
9  class Api_Cost : public Poco::RefCountedObject {
10  public:
11 
12  struct Record {
13 
14  // Current Unix Timestamp
15  Poco::Int32 timeStamp;
16 
17  bool isSetTimeStamp() {
18  return (timeStamp != std::numeric_limits<Poco::Int32>::max());
19  }
20 
21  // URL of REST Call
22  std::string method;
23 
24  bool isSetMethod() {
25  return (method != "Empty");
26  }
27 
28  // Cost
29  double cost;
30 
31  bool isSetCost() {
32  return (cost != std::numeric_limits<double>::max());
33  }
34 
35  Record()
36  : timeStamp(std::numeric_limits<Poco::Int32>::max())
37  , method("Empty")
38  , cost(std::numeric_limits<double>::max())
39  {
40  }
41 
42  };
43 
44 
45  struct RecordWithId {
46 
47  // Current Unix Timestamp
48  Poco::Int32 timeStamp;
49 
50  bool isSetTimeStamp() {
51  return (timeStamp != std::numeric_limits<Poco::Int32>::max());
52  }
53 
54  // URL of REST Call
55  std::string method;
56 
57  bool isSetMethod() {
58  return (method != "Empty");
59  }
60 
61  // Cost
62  double cost;
63 
64  bool isSetCost() {
65  return (cost != std::numeric_limits<double>::max());
66  }
67 
68  //Record ID in database
69  Poco::Int32 id;
70 
71  RecordWithId()
72  : timeStamp(std::numeric_limits<Poco::Int32>::max())
73  , method("Empty")
74  , cost(std::numeric_limits<double>::max())
75  , id(std::numeric_limits<Poco::Int32>::max())
76  {
77  }
78 
79  };
80 
81 
82  Api_Cost(Poco::Data::Session* _db, std::string _suffix = "");
83 
84  ~Api_Cost();
85 
86  void init();
87 
88  void clear();
89 
90  void insert(Api_Cost::Record& record);
91 
92  void insertOnce(Api_Cost::Record& record);
93 
94  void insertMultiple(std::vector<Api_Cost::Record>& records);
95 
96  void insertMultiple(std::vector<Api_Cost::RecordWithId>& records);
97 
98  void insertMultipleUnique(std::vector<Api_Cost::Record>& records);
99 
100  void deleteMultiple(std::vector<Api_Cost::RecordWithId>& records);
101 
102  void insertAndDeleteUnchanged(Api_Cost::Record& record);
103 
104  void insertUnique(Api_Cost::Record& record);
105 
106  void getLatest(Api_Cost::RecordWithId& rec);
107 
108  std::size_t getAll(std::vector<Api_Cost::RecordWithId>& records, std::string condition);
109 
110  Poco::Data::Session* db;
111 
112  std::string tableName;
113 
114  }; //Api_Cost
115 
116  class Tables : public Poco::RefCountedObject {
117  public:
118 
119  Tables(Poco::Data::Session* _db);
120 
121  ~Tables();
122 
123  void init();
124 
125  void clear();
126 
127  Poco::Data::Session* db;
128 
129  Poco::AutoPtr<Api_Cost> api_CostTable;
130 
131  }; //Tables
132 
133  } //CryptowatchDatabase
134 } //trader
135 
136 template <>
137 class Poco::Data::TypeHandler<trader::CryptowatchDatabase::Api_Cost::Record>
138 {
139  public:
140  static std::size_t size()
141  {
142  return 3;
143  }
144 
145  static void bind(std::size_t pos, const trader::CryptowatchDatabase::Api_Cost::Record& record, Poco::Data::AbstractBinder::Ptr pBinder, Poco::Data::AbstractBinder::Direction dir)
146  {
147  Poco::Data::TypeHandler<Poco::Int32>::bind(pos++, record.timeStamp , pBinder, dir);
148  Poco::Data::TypeHandler<std::string>::bind(pos++, record.method , pBinder, dir);
149  Poco::Data::TypeHandler<double>::bind(pos++, record.cost , pBinder, dir);
150  }
151 
152  static void extract(std::size_t pos, trader::CryptowatchDatabase::Api_Cost::Record& record, trader::CryptowatchDatabase::Api_Cost::Record& deflt, Poco::Data::AbstractExtractor::Ptr pExtr)
153  {
154  Poco::Data::TypeHandler<Poco::Int32>::extract(pos++, record.timeStamp, deflt.timeStamp, pExtr);
155  Poco::Data::TypeHandler<std::string>::extract(pos++, record.method, deflt.method, pExtr);
156  Poco::Data::TypeHandler<double>::extract(pos++, record.cost, deflt.cost, pExtr);
157  }
158 
159  static void prepare(std::size_t pos, trader::CryptowatchDatabase::Api_Cost::Record& record, Poco::Data::AbstractPreparator::Ptr pPrep)
160  {
161  Poco::Data::TypeHandler<Poco::Int32>::prepare(pos++, record.timeStamp, pPrep);
162  Poco::Data::TypeHandler<std::string>::prepare(pos++, record.method, pPrep);
163  Poco::Data::TypeHandler<double>::prepare(pos++, record.cost, pPrep);
164  }
165 }
166 ;
167 
168 template <>
169 class Poco::Data::TypeHandler<trader::CryptowatchDatabase::Api_Cost::RecordWithId>
170 {
171  public:
172  static std::size_t size()
173  {
174  return 4;
175  }
176 
177  static void bind(std::size_t pos, const trader::CryptowatchDatabase::Api_Cost::RecordWithId& record, Poco::Data::AbstractBinder::Ptr pBinder, Poco::Data::AbstractBinder::Direction dir)
178  {
179  Poco::Data::TypeHandler<Poco::Int32>::bind(pos++, record.timeStamp , pBinder, dir);
180  Poco::Data::TypeHandler<std::string>::bind(pos++, record.method , pBinder, dir);
181  Poco::Data::TypeHandler<double>::bind(pos++, record.cost , pBinder, dir);
182  Poco::Data::TypeHandler<Poco::Int32>::bind(pos++, record.id, pBinder, dir);
183  }
184 
185  static void extract(std::size_t pos, trader::CryptowatchDatabase::Api_Cost::RecordWithId& record, trader::CryptowatchDatabase::Api_Cost::RecordWithId& deflt, Poco::Data::AbstractExtractor::Ptr pExtr)
186  {
187  Poco::Data::TypeHandler<Poco::Int32>::extract(pos++, record.timeStamp, deflt.timeStamp, pExtr);
188  Poco::Data::TypeHandler<std::string>::extract(pos++, record.method, deflt.method, pExtr);
189  Poco::Data::TypeHandler<double>::extract(pos++, record.cost, deflt.cost, pExtr);
190  Poco::Data::TypeHandler<Poco::Int32>::extract(pos++, record.id, deflt.id, pExtr);
191  }
192 
193  static void prepare(std::size_t pos, trader::CryptowatchDatabase::Api_Cost::RecordWithId& record, Poco::Data::AbstractPreparator::Ptr pPrep)
194  {
195  Poco::Data::TypeHandler<Poco::Int32>::prepare(pos++, record.timeStamp, pPrep);
196  Poco::Data::TypeHandler<std::string>::prepare(pos++, record.method, pPrep);
197  Poco::Data::TypeHandler<double>::prepare(pos++, record.cost, pPrep);
198  Poco::Data::TypeHandler<Poco::Int32>::prepare(pos++, record.id, pPrep);
199  }
200 }
201 ;
Definition: cryptowatchdatabase.h:12
Definition: cryptowatchdatabase.h:116
Definition: cryptowatchdatabase.h:9
Definition: cryptowatchdatabase.h:45
Definition: app.h:7