LibOFX
ofx_container_security.cpp
Go to the documentation of this file.
1/***************************************************************************
2 ofx_container_security.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Gr�goire
5 email : benoitg@coeus.ca
6***************************************************************************/
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24#include <string>
25#include "messages.hh"
26#include "libofx.h"
27#include "ofx_containers.hh"
28#include "ofx_utilities.hh"
29
30extern OfxMainContainer * MainContainer;
31
32/***************************************************************************
33 * OfxSecurityContainer *
34 ***************************************************************************/
35
36OfxSecurityContainer::OfxSecurityContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, std::string para_tag_identifier):
37 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
38{
39 memset(&data, 0, sizeof(data));
40 type = "SECURITY";
41
42 if (para_tag_identifier == "STOCKINFO")
43 data.security_type = data.OFX_STOCK_SECURITY;
44 else if (para_tag_identifier == "MFINFO")
45 data.security_type = data.OFX_FUND_SECURITY;
46 else if (para_tag_identifier == "OPTINFO")
47 data.security_type = data.OFX_OPTION_SECURITY;
48 else if (para_tag_identifier == "DEBTINFO")
49 data.security_type = data.OFX_DEBT_SECURITY;
50 else {
51 ASSIGN(data.security_type, data.OFX_OTHER_SECURITY);
52 }
53}
54OfxSecurityContainer::~OfxSecurityContainer()
55{
56}
57
58void OfxSecurityContainer::add_attribute(const std::string identifier, const std::string value)
59{
60 if (identifier == "UNIQUEID")
61 {
62 /* With <OPTINFO>, there can be two <UNIQUEID> elements, */
63 /* The one under <SECINFO> is mandatory and is for the option. */
64 /* The one under <OPTINFO> is optional and is for the underlying. */
65 /* Assume the first one in the file is the mandatory one and put it in unique_id */
66 if (data.unique_id_valid == false)
67 {
68 ASSIGN_STRNCPY(data.unique_id, value);
69 }
70 else
71 {
72 /* If unique_id is already set, use unique_id2 */
73 ASSIGN_STRNCPY(data.unique_id2, value);
74 }
75 }
76 else if (identifier == "UNIQUEIDTYPE")
77 {
78 /* With <OPTINFO>, there can be two <UNIQUEIDTYPE> elements, */
79 /* The one under <SECINFO> is mandatory and is for the option. */
80 /* The one under <OPTINFO> is optional and is for the underlying. */
81 /* Assume the first one in the file is the mandatory one and put it in unique_id */
82 if (data.unique_id_type_valid == false)
83 {
84 ASSIGN_STRNCPY(data.unique_id_type, value);
85 }
86 else
87 {
88 /* If unique_id_type is already set, use unique_id2_type */
90 }
91 }
92 else if (identifier == "SECNAME")
93 {
94 ASSIGN_STRNCPY(data.secname, value);
95 }
96 else if (identifier == "TICKER")
97 {
98 ASSIGN_STRNCPY(data.ticker, value);
99 }
100 else if (identifier == "RATING")
101 {
102 ASSIGN_STRNCPY(data.rating, value);
103 }
104 else if (identifier == "UNITPRICE")
105 {
107 }
108 else if (identifier == "DTASOF")
109 {
111 }
112 else if (identifier == "CURRATE")
113 {
115 }
116 else if (identifier == "CURSYM")
117 {
118 ASSIGN_STRNCPY(data.currency, value);
119 }
120 else if (identifier == "CURRENCY")
121 {
123 }
124 else if (identifier == "ORIGCURRENCY")
125 {
127 }
128 else if (identifier == "MEMO" || identifier == "MEMO2")
129 {
130 ASSIGN_STRNCPY(data.memo, value);
131 }
132 else if (identifier == "FIID")
133 {
134 ASSIGN_STRNCPY(data.fiid, value);
135 }
136 else if (identifier == "ASSETCLASS")
137 {
138 if (value == "DOMESTICBOND")
139 {
140 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_DOMESTICBOND);
141 }
142 else if (value == "INTLBOND")
143 {
144 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_INTLBOND);
145 }
146 else if (value == "LARGESTOCK")
147 {
148 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_LARGESTOCK);
149 }
150 else if (value == "SMALLSTOCK")
151 {
152 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_SMALLSTOCK);
153 }
154 else if (value == "INTLSTOCK")
155 {
156 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_INTLSTOCK);
157 }
158 else if (value == "MONEYMRKT")
159 {
160 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_MONEYMRKT);
161 }
162 else if (value == "OTHER")
163 {
164 ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_OTHER);
165 }
166 }
167 else if (identifier == "PARVALUE")
168 {
170 }
171 else if (identifier == "DEBTTYPE")
172 {
173 if (value == "COUPON")
174 {
175 ASSIGN(data.debt_type, data.OFX_DEBT_TYPE_COUPON);
176 }
177 else if (value == "ZERO")
178 {
179 ASSIGN(data.debt_type, data.OFX_DEBT_TYPE_ZERO);
180 }
181 }
182 else if (identifier == "DEBTCLASS")
183 {
184 if (value == "TREASURY")
185 {
186 ASSIGN(data.debt_class, data.OFX_DEBTCLASS_TREASURY);
187 }
188 else if (value == "MUNICIPAL")
189 {
190 ASSIGN(data.debt_class, data.OFX_DEBTCLASS_MUNICIPAL);
191 }
192 else if (value == "CORPORATE")
193 {
194 ASSIGN(data.debt_class, data.OFX_DEBTCLASS_CORPORATE);
195 }
196 else if (value == "OTHER")
197 {
198 ASSIGN(data.debt_class, data.OFX_DEBTCLASS_OTHER);
199 }
200 }
201 else if (identifier == "COUPONRT")
202 {
204 }
205 else if (identifier == "DTCOUPON")
206 {
208 }
209 else if (identifier == "COUPONFREQ")
210 {
211 if (value == "MONTHLY")
212 {
213 ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_MONTHLY);
214 }
215 else if (value == "QUARTERLY")
216 {
217 ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_QUARTERLY);
218 }
219 else if (value == "SEMIANNUAL")
220 {
221 ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_SEMIANNUAL);
222 }
223 else if (value == "ANNUAL")
224 {
225 ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_ANNUAL);
226 }
227 else if (value == "OTHER")
228 {
229 ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_OTHER);
230 }
231 }
232 else if (identifier == "CALLPRICE")
233 {
235 }
236 else if (identifier == "YIELDTOCALL")
237 {
239 }
240 else if (identifier == "DTCALL")
241 {
242 ASSIGN(data.call_date, ofxdate_to_time_t(value));
243 }
244 else if (identifier == "CALLTYPE")
245 {
246 if (value == "CALL")
247 {
248 ASSIGN(data.call_type, data.OFX_CALL_TYPE_CALL);
249 }
250 else if (value == "PUT")
251 {
252 ASSIGN(data.call_type, data.OFX_CALL_TYPE_PUT);
253 }
254 else if (value == "PREFUND")
255 {
256 ASSIGN(data.call_type, data.OFX_CALL_TYPE_PREFUND);
257 }
258 else if (value == "MATURITY")
259 {
260 ASSIGN(data.call_type, data.OFX_CALL_TYPE_MATURITY);
261 }
262 }
263 else if (identifier == "YIELDTOMAT")
264 {
266 }
267 else if (identifier == "DTMAT")
268 {
270 }
271 else if (identifier == "MFTYPE")
272 {
273 if (value == "OPENEND")
274 {
275 ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_OPENEND);
276 }
277 else if (value == "CLOSEEND")
278 {
279 ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_CLOSEEND);
280 }
281 else if (value == "OTHER")
282 {
283 ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_OTHER);
284 }
285 }
286 else if (identifier == "STOCKTYPE")
287 {
288 if (value == "COMMON")
289 {
290 ASSIGN(data.stock_type, data.OFX_STOCKTYPE_COMMON);
291 }
292 else if (value == "PREFERRED")
293 {
294 ASSIGN(data.stock_type, data.OFX_STOCKTYPE_PREFERRED);
295 }
296 else if (value == "CONVERTIBLE")
297 {
298 ASSIGN(data.stock_type, data.OFX_STOCKTYPE_CONVERTIBLE);
299 }
300 else if (value == "OTHER")
301 {
302 ASSIGN(data.stock_type, data.OFX_STOCKTYPE_OTHER);
303 }
304 }
305 else if (identifier == "YIELD")
306 {
307 ASSIGN(data.yield, ofxamount_to_double(value));
308 }
309 else if (identifier == "DTYIELDASOF")
310 {
312 }
313 else if (identifier == "OPTTYPE")
314 {
315 if (value == "CALL" || value == "Call")
316 {
317 ASSIGN(data.option_type, data.OFX_OPTION_TYPE_CALL);
318 }
319 else if (value == "PUT" || value == "Put")
320 {
321 ASSIGN(data.option_type, data.OFX_OPTION_TYPE_PUT);
322 }
323 }
324 else if (identifier == "STRIKEPRICE")
325 {
327 }
328 else if (identifier == "DTEXPIRE")
329 {
331 }
332 else if (identifier == "SHPERCTRCT")
333 {
335 }
336 else
337 {
338 /* Redirect unknown identifiers to the base class */
339 OfxGenericContainer::add_attribute(identifier, value);
340 }
341}
343{
344 libofx_context->securityCallback(data);
345 return true;
346}
347
349{
350 if (MainContainer != NULL)
351 {
352 return MainContainer->add_container(this);
353 }
354 else
355 {
356 return false;
357 }
358}
359
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
virtual void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
The root container. Created by the <OFX> OFX element or by the export functions.
virtual int gen_event()
Generate libofx.h events.
void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
virtual int add_to_main_tree()
Add this container to the main tree.
Main header file containing the LibOfx API.
Message IO functionality.
LibOFX internal object code.
double ofxamount_to_double(const std::string ofxamount)
Convert OFX amount of money to double float.
time_t ofxdate_to_time_t(const std::string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Various simple functions for type conversion & al.
#define ASSIGN_STRNCPY(DEST, VALUE)
#define ASSIGN(DEST, VALUE)
time_t maturity_date
Definition: libofx.h:573
time_t yield_asof_date
Definition: libofx.h:492
char unique_id[OFX_UNIQUE_ID_LENGTH]
Definition: libofx.h:390
char fiid[OFX_FIID_LENGTH]
Definition: libofx.h:438
double currency_ratio
Definition: libofx.h:424
char unique_id2[OFX_UNIQUE_ID_LENGTH]
Definition: libofx.h:608
time_t call_date
Definition: libofx.h:555
time_t date_unitprice
Definition: libofx.h:415
double strike_price
Definition: libofx.h:590
char currency[OFX_CURRENCY_LENGTH]
Definition: libofx.h:420
double yield_to_call
Definition: libofx.h:551
char secname[OFX_SECNAME_LENGTH]
Definition: libofx.h:397
int amounts_are_foreign_currency
Definition: libofx.h:430
double yield
Definition: libofx.h:489
char rating[OFX_SECURITY_RATING_LENGTH]
Definition: libofx.h:412
double call_price
Definition: libofx.h:547
char unique_id2_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: libofx.h:613
time_t date_coupon
Definition: libofx.h:532
double yield_to_maturity
Definition: libofx.h:569
time_t date_expire
Definition: libofx.h:594
double par_value
Definition: libofx.h:501
char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: libofx.h:393
double unitprice
Definition: libofx.h:408
double shares_per_cont
Definition: libofx.h:598
char memo[OFX_MEMO2_LENGTH]
Definition: libofx.h:433
double coupon_rate
Definition: libofx.h:528
char ticker[OFX_TICKER_LENGTH]
Definition: libofx.h:405