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 
30 extern OfxMainContainer * MainContainer;
31 
32 /***************************************************************************
33  * OfxSecurityContainer *
34  ***************************************************************************/
35 
36 OfxSecurityContainer::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 }
54 OfxSecurityContainer::~OfxSecurityContainer()
55 {
56 }
57 
58 void 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 */
89  ASSIGN_STRNCPY(data.unique_id2_type, value);
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  {
106  ASSIGN(data.unitprice, ofxamount_to_double(value));
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  {
169  ASSIGN(data.par_value, ofxamount_to_double(value));
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  {
203  ASSIGN(data.coupon_rate, ofxamount_to_double(value));
204  }
205  else if (identifier == "DTCOUPON")
206  {
207  ASSIGN(data.date_coupon, ofxdate_to_time_t(value));
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  {
234  ASSIGN(data.call_price, ofxamount_to_double(value));
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  {
269  ASSIGN(data.maturity_date, ofxdate_to_time_t(value));
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  {
330  ASSIGN(data.date_expire, ofxdate_to_time_t(value));
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 
OfxGenericContainer::type
std::string type
Definition: ofx_containers.hh:41
ASSIGN
#define ASSIGN(DEST, VALUE)
Definition: ofx_utilities.hh:45
OfxSecurityData::yield
double yield
Definition: inc/libofx.h:489
OfxSecurityData::unique_id2_type
char unique_id2_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: inc/libofx.h:613
ASSIGN_STRNCPY
#define ASSIGN_STRNCPY(DEST, VALUE)
Definition: ofx_utilities.hh:52
OfxSecurityData::call_price
double call_price
Definition: inc/libofx.h:547
OfxSecurityData::strike_price
double strike_price
Definition: inc/libofx.h:590
OfxSecurityData::yield_to_maturity
double yield_to_maturity
Definition: inc/libofx.h:569
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: ofx_containers.hh:289
OfxSecurityData::yield_asof_date
time_t yield_asof_date
Definition: inc/libofx.h:492
OfxSecurityData::unique_id
char unique_id[OFX_UNIQUE_ID_LENGTH]
Definition: inc/libofx.h:390
OfxSecurityData::coupon_rate
double coupon_rate
Definition: inc/libofx.h:528
OfxSecurityData::unique_id_type
char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: inc/libofx.h:393
OfxSecurityData::ticker
char ticker[OFX_TICKER_LENGTH]
Definition: inc/libofx.h:405
OfxSecurityData::par_value
double par_value
Definition: inc/libofx.h:501
OfxSecurityContainer::add_to_main_tree
virtual int add_to_main_tree()
Add this container to the main tree.
Definition: ofx_container_security.cpp:348
OfxSecurityData::unitprice
double unitprice
Definition: inc/libofx.h:408
OfxSecurityData::date_expire
time_t date_expire
Definition: inc/libofx.h:594
OfxSecurityData::call_date
time_t call_date
Definition: inc/libofx.h:555
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxSecurityContainer::gen_event
virtual int gen_event()
Generate libofx.h events.
Definition: ofx_container_security.cpp:342
OfxSecurityData::date_unitprice
time_t date_unitprice
Definition: inc/libofx.h:415
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: ofx_containers.hh:31
OfxGenericContainer::add_attribute
virtual void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
Definition: ofx_container_generic.cpp:57
ofxamount_to_double
double ofxamount_to_double(const std::string ofxamount)
Convert OFX amount of money to double float.
Definition: ofx_utilities.cpp:130
LibofxContext
Definition: context.hh:23
ofx_containers.hh
LibOFX internal object code.
OfxSecurityData::date_coupon
time_t date_coupon
Definition: inc/libofx.h:532
OfxSecurityData::yield_to_call
double yield_to_call
Definition: inc/libofx.h:551
OfxSecurityData::unique_id2
char unique_id2[OFX_UNIQUE_ID_LENGTH]
Definition: inc/libofx.h:608
ofxdate_to_time_t
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.
Definition: ofx_utilities.cpp:68
OfxSecurityData::currency_ratio
double currency_ratio
Definition: inc/libofx.h:424
OfxSecurityData::memo
char memo[OFX_MEMO2_LENGTH]
Definition: inc/libofx.h:433
OfxSecurityData::fiid
char fiid[OFX_FIID_LENGTH]
Definition: inc/libofx.h:438
OfxSecurityData::secname
char secname[OFX_SECNAME_LENGTH]
Definition: inc/libofx.h:397
OfxSecurityData::shares_per_cont
double shares_per_cont
Definition: inc/libofx.h:598
OfxSecurityData::currency
char currency[OFX_CURRENCY_LENGTH]
Definition: inc/libofx.h:420
OfxSecurityContainer::add_attribute
void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
Definition: ofx_container_security.cpp:58
OfxSecurityData::amounts_are_foreign_currency
int amounts_are_foreign_currency
Definition: inc/libofx.h:430
OfxSecurityData::rating
char rating[OFX_SECURITY_RATING_LENGTH]
Definition: inc/libofx.h:412
messages.hh
Message IO functionality.
OfxSecurityData::maturity_date
time_t maturity_date
Definition: inc/libofx.h:573