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, 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 OfxSecurityContainer::~OfxSecurityContainer()
54 {
55 }
56 
57 void OfxSecurityContainer::add_attribute(const string identifier, const string value)
58 {
59  if (identifier == "UNIQUEID")
60  {
61  /* With <OPTINFO>, there can be two <UNIQUEID> elements, */
62  /* The one under <SECINFO> is mandatory and is for the option. */
63  /* The one under <OPTINFO> is optional and is for the underlying. */
64  /* Assume the first one in the file is the mandatory one and put it in unique_id */
65  if (data.unique_id_valid == false)
66  {
67  ASSIGN_STRNCPY(data.unique_id, value);
68  }
69  else
70  {
71  /* If unique_id is already set, use unique_id2 */
72  ASSIGN_STRNCPY(data.unique_id2, value);
73  }
74  }
75  else if (identifier == "UNIQUEIDTYPE")
76  {
77  /* With <OPTINFO>, there can be two <UNIQUEIDTYPE> elements, */
78  /* The one under <SECINFO> is mandatory and is for the option. */
79  /* The one under <OPTINFO> is optional and is for the underlying. */
80  /* Assume the first one in the file is the mandatory one and put it in unique_id */
81  if (data.unique_id_type_valid == false)
82  {
83  ASSIGN_STRNCPY(data.unique_id_type, value);
84  }
85  else
86  {
87  /* If unique_id_type is already set, use unique_id2_type */
88  ASSIGN_STRNCPY(data.unique_id2_type, value);
89  }
90  }
91  else if (identifier == "SECNAME")
92  {
93  ASSIGN_STRNCPY(data.secname, value);
94  }
95  else if (identifier == "TICKER")
96  {
97  ASSIGN_STRNCPY(data.ticker, value);
98  }
99  else if (identifier == "RATING")
100  {
101  ASSIGN_STRNCPY(data.rating, value);
102  }
103  else if (identifier == "UNITPRICE")
104  {
105  ASSIGN(data.unitprice, ofxamount_to_double(value));
106  }
107  else if (identifier == "DTASOF")
108  {
110  }
111  else if (identifier == "CURRATE")
112  {
114  }
115  else if (identifier == "CURSYM")
116  {
117  ASSIGN_STRNCPY(data.currency, value);
118  }
119  else if (identifier == "CURRENCY")
120  {
122  }
123  else if (identifier == "ORIGCURRENCY")
124  {
126  }
127  else if (identifier == "MEMO" || identifier == "MEMO2")
128  {
129  ASSIGN_STRNCPY(data.memo, value);
130  }
131  else if (identifier == "FIID")
132  {
133  ASSIGN_STRNCPY(data.fiid, value);
134  }
135  else if (identifier == "ASSETCLASS")
136  {
137  if (value == "DOMESTICBOND")
138  {
139  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_DOMESTICBOND);
140  }
141  else if (value == "INTLBOND")
142  {
143  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_INTLBOND);
144  }
145  else if (value == "LARGESTOCK")
146  {
147  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_LARGESTOCK);
148  }
149  else if (value == "SMALLSTOCK")
150  {
151  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_SMALLSTOCK);
152  }
153  else if (value == "INTLSTOCK")
154  {
155  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_INTLSTOCK);
156  }
157  else if (value == "MONEYMRKT")
158  {
159  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_MONEYMRKT);
160  }
161  else if (value == "OTHER")
162  {
163  ASSIGN(data.asset_class, data.OFX_ASSET_CLASS_OTHER);
164  }
165  }
166  else if (identifier == "PARVALUE")
167  {
168  ASSIGN(data.par_value, ofxamount_to_double(value));
169  }
170  else if (identifier == "DEBTTYPE")
171  {
172  if (value == "COUPON")
173  {
174  ASSIGN(data.debt_type, data.OFX_DEBT_TYPE_COUPON);
175  }
176  else if (value == "ZERO")
177  {
178  ASSIGN(data.debt_type, data.OFX_DEBT_TYPE_ZERO);
179  }
180  }
181  else if (identifier == "DEBTCLASS")
182  {
183  if (value == "TREASURY")
184  {
185  ASSIGN(data.debt_class, data.OFX_DEBTCLASS_TREASURY);
186  }
187  else if (value == "MUNICIPAL")
188  {
189  ASSIGN(data.debt_class, data.OFX_DEBTCLASS_MUNICIPAL);
190  }
191  else if (value == "CORPORATE")
192  {
193  ASSIGN(data.debt_class, data.OFX_DEBTCLASS_CORPORATE);
194  }
195  else if (value == "OTHER")
196  {
197  ASSIGN(data.debt_class, data.OFX_DEBTCLASS_OTHER);
198  }
199  }
200  else if (identifier == "COUPONRT")
201  {
202  ASSIGN(data.coupon_rate, ofxamount_to_double(value));
203  }
204  else if (identifier == "DTCOUPON")
205  {
206  ASSIGN(data.date_coupon, ofxdate_to_time_t(value));
207  }
208  else if (identifier == "COUPONFREQ")
209  {
210  if (value == "MONTHLY")
211  {
212  ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_MONTHLY);
213  }
214  else if (value == "QUARTERLY")
215  {
216  ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_QUARTERLY);
217  }
218  else if (value == "SEMIANNUAL")
219  {
220  ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_SEMIANNUAL);
221  }
222  else if (value == "ANNUAL")
223  {
224  ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_ANNUAL);
225  }
226  else if (value == "OTHER")
227  {
228  ASSIGN(data.coupon_freq, data.OFX_COUPON_FREQ_OTHER);
229  }
230  }
231  else if (identifier == "CALLPRICE")
232  {
233  ASSIGN(data.call_price, ofxamount_to_double(value));
234  }
235  else if (identifier == "YIELDTOCALL")
236  {
238  }
239  else if (identifier == "DTCALL")
240  {
241  ASSIGN(data.call_date, ofxdate_to_time_t(value));
242  }
243  else if (identifier == "CALLTYPE")
244  {
245  if (value == "CALL")
246  {
247  ASSIGN(data.call_type, data.OFX_CALL_TYPE_CALL);
248  }
249  else if (value == "PUT")
250  {
251  ASSIGN(data.call_type, data.OFX_CALL_TYPE_PUT);
252  }
253  else if (value == "PREFUND")
254  {
255  ASSIGN(data.call_type, data.OFX_CALL_TYPE_PREFUND);
256  }
257  else if (value == "MATURITY")
258  {
259  ASSIGN(data.call_type, data.OFX_CALL_TYPE_MATURITY);
260  }
261  }
262  else if (identifier == "YIELDTOMAT")
263  {
265  }
266  else if (identifier == "DTMAT")
267  {
268  ASSIGN(data.maturity_date, ofxdate_to_time_t(value));
269  }
270  else if (identifier == "MFTYPE")
271  {
272  if (value == "OPENEND")
273  {
274  ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_OPENEND);
275  }
276  else if (value == "CLOSEEND")
277  {
278  ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_CLOSEEND);
279  }
280  else if (value == "OTHER")
281  {
282  ASSIGN(data.mutual_fund_type, data.OFX_MFTYPE_OTHER);
283  }
284  }
285  else if (identifier == "STOCKTYPE")
286  {
287  if (value == "COMMON")
288  {
289  ASSIGN(data.stock_type, data.OFX_STOCKTYPE_COMMON);
290  }
291  else if (value == "PREFERRED")
292  {
293  ASSIGN(data.stock_type, data.OFX_STOCKTYPE_PREFERRED);
294  }
295  else if (value == "CONVERTIBLE")
296  {
297  ASSIGN(data.stock_type, data.OFX_STOCKTYPE_CONVERTIBLE);
298  }
299  else if (value == "OTHER")
300  {
301  ASSIGN(data.stock_type, data.OFX_STOCKTYPE_OTHER);
302  }
303  }
304  else if (identifier == "YIELD")
305  {
306  ASSIGN(data.yield, ofxamount_to_double(value));
307  }
308  else if (identifier == "DTYIELDASOF")
309  {
311  }
312  else if (identifier == "OPTTYPE")
313  {
314  if (value == "CALL" || value == "Call")
315  {
316  ASSIGN(data.option_type, data.OFX_OPTION_TYPE_CALL);
317  }
318  else if (value == "PUT" || value == "Put")
319  {
320  ASSIGN(data.option_type, data.OFX_OPTION_TYPE_PUT);
321  }
322  }
323  else if (identifier == "STRIKEPRICE")
324  {
326  }
327  else if (identifier == "DTEXPIRE")
328  {
329  ASSIGN(data.date_expire, ofxdate_to_time_t(value));
330  }
331  else if (identifier == "SHPERCTRCT")
332  {
334  }
335  else
336  {
337  /* Redirect unknown identifiers to the base class */
338  OfxGenericContainer::add_attribute(identifier, value);
339  }
340 }
342 {
343  libofx_context->securityCallback(data);
344  return true;
345 }
346 
348 {
349  if (MainContainer != NULL)
350  {
351  return MainContainer->add_container(this);
352  }
353  else
354  {
355  return false;
356  }
357 }
358 
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
virtual void add_attribute(const string identifier, const 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 string identifier, const 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.
time_t ofxdate_to_time_t(const string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
Various simple functions for type conversion & al.
#define ASSIGN_STRNCPY(DEST, VALUE)
#define ASSIGN(DEST, VALUE)
time_t maturity_date
Definition: libofx.h:562
time_t yield_asof_date
Definition: libofx.h:481
char unique_id[OFX_UNIQUE_ID_LENGTH]
Definition: libofx.h:379
char fiid[OFX_FIID_LENGTH]
Definition: libofx.h:427
double currency_ratio
Definition: libofx.h:413
char unique_id2[OFX_UNIQUE_ID_LENGTH]
Definition: libofx.h:597
time_t call_date
Definition: libofx.h:544
time_t date_unitprice
Definition: libofx.h:404
double strike_price
Definition: libofx.h:579
char currency[OFX_CURRENCY_LENGTH]
Definition: libofx.h:409
double yield_to_call
Definition: libofx.h:540
char secname[OFX_SECNAME_LENGTH]
Definition: libofx.h:386
int amounts_are_foreign_currency
Definition: libofx.h:419
double yield
Definition: libofx.h:478
char rating[OFX_SECURITY_RATING_LENGTH]
Definition: libofx.h:401
double call_price
Definition: libofx.h:536
char unique_id2_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: libofx.h:602
time_t date_coupon
Definition: libofx.h:521
double yield_to_maturity
Definition: libofx.h:558
time_t date_expire
Definition: libofx.h:583
double par_value
Definition: libofx.h:490
char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: libofx.h:382
double unitprice
Definition: libofx.h:397
double shares_per_cont
Definition: libofx.h:587
char memo[OFX_MEMO2_LENGTH]
Definition: libofx.h:422
double coupon_rate
Definition: libofx.h:517
char ticker[OFX_TICKER_LENGTH]
Definition: libofx.h:394