| #define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES" |
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the exchange where it is traded.
The LEGACY name is only used by the file i/o routines, and is converted to another commodity namespace before it is seen by the rest of the system. The ISO namespace represents currencies. With the exception of the NASDAQ namespace (which is used once in the binary importer) the rest of the namespace declarations are only used to populate an option menu in the commodity selection window.
Definition at line 97 of file gnc-commodity.h.
| enum QuoteSourceType |
The quote source type enum account types are used to determine how the transaction data in the account is displayed. These values can be safely changed from one release to the next.
Definition at line 118 of file gnc-commodity.h.
00119 { 00120 SOURCE_SINGLE = 0, 00124 SOURCE_MULTI, 00127 SOURCE_UNKNOWN, 00131 SOURCE_MAX, 00132 SOURCE_CURRENCY = SOURCE_MAX, 00133 } QuoteSourceType;
| gnc_commodity* gnc_commodity_clone | ( | const gnc_commodity * | src, | |
| QofBook * | dest_book | |||
| ) |
allocate and copy
Definition at line 661 of file gnc-commodity.c.
00662 { 00663 gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL); 00664 qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book); 00665 00666 dest->fullname = CACHE_INSERT(src->fullname); 00667 dest->mnemonic = CACHE_INSERT(src->mnemonic); 00668 dest->cusip = CACHE_INSERT(src->cusip); 00669 dest->quote_tz = CACHE_INSERT(src->quote_tz); 00670 00671 dest->namespace = src->namespace; 00672 00673 dest->mark = 0; 00674 dest->fraction = src->fraction; 00675 dest->quote_flag = src->quote_flag; 00676 00677 gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src)); 00678 00679 kvp_frame_delete (dest->inst.kvp_data); 00680 dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data); 00681 00682 reset_printname(dest); 00683 reset_unique_name(dest); 00684 00685 return dest; 00686 }
| void gnc_commodity_copy | ( | gnc_commodity * | dest, | |
| const gnc_commodity * | src | |||
| ) |
Copy src into dest
Definition at line 647 of file gnc-commodity.c.
00648 { 00649 gnc_commodity_set_fullname (dest, src->fullname); 00650 dest->namespace = src->namespace; 00651 gnc_commodity_set_fraction (dest, src->fraction); 00652 gnc_commodity_set_cusip (dest, src->cusip); 00653 gnc_commodity_set_quote_flag (dest, src->quote_flag); 00654 gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src)); 00655 gnc_commodity_set_quote_tz (dest, src->quote_tz); 00656 kvp_frame_delete (dest->inst.kvp_data); 00657 dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data); 00658 }
| void gnc_commodity_decrement_usage_count | ( | gnc_commodity * | cm | ) |
Decrement a commodity's internal counter that tracks how many accounts are using that commodity. For currencies, this may have the side effect of disabling the commodity's quote flag.
| cm | A pointer to a commodity data structure. |
Definition at line 1109 of file gnc-commodity.c.
01110 { 01111 const char *str; 01112 01113 ENTER("(cm=%p)", cm); 01114 01115 if(!cm) { 01116 LEAVE(""); 01117 return; 01118 } 01119 01120 if(cm->usage_count == 0) { 01121 PWARN("usage_count already zero"); 01122 LEAVE(""); 01123 return; 01124 } 01125 01126 cm->usage_count--; 01127 if((cm->usage_count == 0) && cm->quote_flag 01128 && gnc_commodity_get_auto_quote_control_flag(cm) 01129 && gnc_commodity_is_iso(cm)) { 01130 /* if this is a currency with auto quote control enabled and no more 01131 * accounts reference this currency, disable quote retrieval */ 01132 gnc_commodity_set_quote_flag(cm, FALSE); 01133 } 01134 LEAVE("(usage_count=%d)", cm->usage_count); 01135 }
| void gnc_commodity_destroy | ( | gnc_commodity * | cm | ) |
Destroy a commodity. Release all memory attached to this data structure.
| cm | The commodity to destroy. |
Definition at line 600 of file gnc-commodity.c.
00601 { 00602 QofBook *book; 00603 gnc_commodity_table *table; 00604 if(!cm) return; 00605 00606 book = qof_instance_get_book(&cm->inst); 00607 table = gnc_commodity_table_get_table(book); 00608 gnc_commodity_table_remove(table, cm); 00609 00610 qof_event_gen (&cm->inst, QOF_EVENT_DESTROY, NULL); 00611 00612 /* Set at creation */ 00613 CACHE_REMOVE (cm->fullname); 00614 CACHE_REMOVE (cm->cusip); 00615 CACHE_REMOVE (cm->mnemonic); 00616 CACHE_REMOVE (cm->quote_tz); 00617 cm->namespace = NULL; 00618 00619 /* Set through accessor functions */ 00620 cm->quote_source = NULL; 00621 00622 /* Automatically generated */ 00623 g_free(cm->printname); 00624 cm->printname = NULL; 00625 00626 g_free(cm->unique_name); 00627 cm->unique_name = NULL; 00628 00629 cm->mark = 0; 00630 00631 #ifdef ACCOUNTS_CLEANED_UP 00632 /* Account objects are not actually cleaned up when a book is closed (in fact 00633 * a memory leak), but commodities are, so in currently this warning gets hit 00634 * quite frequently. Disable the check until cleaning up of accounts objects 00635 * on close is implemented. */ 00636 if(cm->usage_count != 0) { 00637 PWARN("Destroying commodity (%p) with non-zero usage_count (%d).", cm, 00638 cm->usage_count); 00639 } 00640 #endif 00641 00642 /* qof_instance_release (&cm->inst); */ 00643 g_object_unref(cm); 00644 }
| gboolean gnc_commodity_equal | ( | const gnc_commodity * | a, | |
| const gnc_commodity * | b | |||
| ) |
This routine returns TRUE if the two commodities are equal. Commodities are equal if they have the same namespace, mnemonic, fullname, exchange private code and fraction.
Definition at line 1157 of file gnc-commodity.c.
01158 { 01159 if (a == b) return TRUE; 01160 01161 if (!a || !b) 01162 { 01163 DEBUG ("one is NULL"); 01164 return FALSE; 01165 } 01166 01167 if (a->namespace != b->namespace) 01168 { 01169 DEBUG ("namespaces differ: %p(%s) vs %p(%s)", 01170 a->namespace, gnc_commodity_namespace_get_name(a->namespace), 01171 b->namespace, gnc_commodity_namespace_get_name(b->namespace)); 01172 return FALSE; 01173 } 01174 01175 if (safe_strcmp(a->mnemonic, b->mnemonic) != 0) 01176 { 01177 DEBUG ("mnemonics differ: %s vs %s", a->mnemonic, b->mnemonic); 01178 return FALSE; 01179 } 01180 01181 if (safe_strcmp(a->fullname, b->fullname) != 0) 01182 { 01183 DEBUG ("fullnames differ: %s vs %s", a->fullname, b->fullname); 01184 return FALSE; 01185 } 01186 01187 if (safe_strcmp(a->cusip, b->cusip) != 0) 01188 { 01189 DEBUG ("cusips differ: %s vs %s", a->cusip, b->cusip); 01190 return FALSE; 01191 } 01192 01193 if (a->fraction != b->fraction) 01194 { 01195 DEBUG ("fractions differ: %d vs %d", a->fraction, b->fraction); 01196 return FALSE; 01197 } 01198 01199 return TRUE; 01200 }
| gboolean gnc_commodity_equiv | ( | const gnc_commodity * | a, | |
| const gnc_commodity * | b | |||
| ) |
This routine returns TRUE if the two commodities are equivalent. Commodities are equivalent if they have the same namespace and mnemonic. Equivalent commodities may belong to different exchanges, may have different fullnames, and may have different fractions.
Definition at line 1147 of file gnc-commodity.c.
01148 { 01149 if(a == b) return TRUE; 01150 if(!a || !b) return FALSE; 01151 if(a->namespace != b->namespace) return FALSE; 01152 if(safe_strcmp(a->mnemonic, b->mnemonic) != 0) return FALSE; 01153 return TRUE; 01154 }
| const char* gnc_commodity_get_cusip | ( | const gnc_commodity * | cm | ) |
Retrieve the 'exchange code' for the specified commodity. This will be a pointer to a null terminated string of the form "AXQ14728", etc. This field is often used when presenting information to the user.
| cm | A pointer to a commodity data structure. |
Definition at line 769 of file gnc-commodity.c.
| int gnc_commodity_get_fraction | ( | const gnc_commodity * | cm | ) |
Retrieve the fraction for the specified commodity. This will be an integer value specifying the number of fractional units that one of these commodities can be divided into. Should always be a power of 10.
| cm | A pointer to a commodity data structure. |
Definition at line 780 of file gnc-commodity.c.
| const char* gnc_commodity_get_fullname | ( | const gnc_commodity * | cm | ) |
Retrieve the full name for the specified commodity. This will be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 745 of file gnc-commodity.c.
| gint16 gnc_commodity_get_mark | ( | const gnc_commodity * | cm | ) |
Retrieve the 'mark' field for the specified commodity.
| cm | A pointer to a commodity data structure. |
Definition at line 791 of file gnc-commodity.c.
| const char* gnc_commodity_get_mnemonic | ( | const gnc_commodity * | cm | ) |
Retrieve the mnemonic for the specified commodity. This will be a pointer to a null terminated string of the form "ACME", "QWER", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 693 of file gnc-commodity.c.
| const char* gnc_commodity_get_namespace | ( | const gnc_commodity * | cm | ) |
Retrieve the namespace for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 716 of file gnc-commodity.c.
00717 { 00718 if(!cm) return NULL; 00719 return gnc_commodity_namespace_get_name(cm->namespace); 00720 }
| const char* gnc_commodity_get_namespace_compat | ( | const gnc_commodity * | cm | ) |
Retrieve the namespace for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc. The only difference between function and gnc_commodity_get_namespace() is that this function returns ISO4217 instead of CURRENCY for backward compatability with the 1.8 data files.
| cm | A pointer to a commodity data structure. |
Definition at line 723 of file gnc-commodity.c.
00724 { 00725 if (!cm || !cm->namespace) return NULL; 00726 if (cm->namespace->iso4217) { 00727 /* Data files are still written with ISO4217. */ 00728 return GNC_COMMODITY_NS_ISO; 00729 } 00730 return gnc_commodity_namespace_get_name(cm->namespace); 00731 }
| gnc_commodity_namespace* gnc_commodity_get_namespace_ds | ( | const gnc_commodity * | cm | ) |
Retrieve the namespace data strucure for the specified commodity. This will be a pointer to another data structure.
| cm | A pointer to a commodity data structure. |
Definition at line 734 of file gnc-commodity.c.
| const char* gnc_commodity_get_printname | ( | const gnc_commodity * | cm | ) |
Retrieve the 'print' name for the specified commodity. This will be a pointer to a null terminated string of the form "Acme Systems, Inc. (ACME)", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 704 of file gnc-commodity.c.
| gboolean gnc_commodity_get_quote_flag | ( | const gnc_commodity * | cm | ) |
Retrieve the automatic price quote flag for the specified commodity. This flag indicates whether stock quotes should be retrieved for the specified stock.
| cm | A pointer to a commodity data structure. |
Definition at line 817 of file gnc-commodity.c.
| gnc_quote_source* gnc_commodity_get_quote_source | ( | const gnc_commodity * | cm | ) |
Retrieve the automatic price quote source for the specified commodity. This will be a pointer to a null terminated string of the form "Yahoo (Asia)", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 828 of file gnc-commodity.c.
00829 { 00830 if(!cm) return NULL; 00831 if (!cm->quote_source && gnc_commodity_is_iso(cm)) 00832 return ¤cy_quote_source; 00833 return cm->quote_source; 00834 }
| const char* gnc_commodity_get_quote_tz | ( | const gnc_commodity * | cm | ) |
Retrieve the automatic price quote timezone for the specified commodity. This will be a pointer to a null terminated string of the form "America/New_York", etc.
| cm | A pointer to a commodity data structure. |
Definition at line 850 of file gnc-commodity.c.
| const char* gnc_commodity_get_unique_name | ( | const gnc_commodity * | cm | ) |
Retrieve the 'unique' name for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX::ACME", etc. This field is often used when performing comparisons or other functions invisible to the user.
| cm | A pointer to a commodity data structure. |
Definition at line 757 of file gnc-commodity.c.
| void gnc_commodity_increment_usage_count | ( | gnc_commodity * | cm | ) |
Increment a commodity's internal counter that tracks how many accounts are using that commodity. For currencies, this may have the side effect of enabling the commodity's quote flag.
| cm | A pointer to a commodity data structure. |
Definition at line 1078 of file gnc-commodity.c.
01079 { 01080 const char *str; 01081 01082 ENTER("(cm=%p)", cm); 01083 01084 if(!cm) { 01085 LEAVE(""); 01086 return; 01087 } 01088 01089 if((cm->usage_count == 0) && !cm->quote_flag 01090 && gnc_commodity_get_auto_quote_control_flag(cm) 01091 && gnc_commodity_is_iso(cm)) { 01092 /* compatability hack - Gnucash 1.8 gets currency quotes when a 01093 non-default currency is assigned to an account. */ 01094 gnc_commodity_begin_edit(cm); 01095 gnc_commodity_set_quote_flag(cm, TRUE); 01096 gnc_commodity_set_quote_source(cm, 01097 gnc_commodity_get_default_quote_source(cm)); 01098 gnc_commodity_commit_edit(cm); 01099 } 01100 cm->usage_count++; 01101 LEAVE("(usage_count=%d)", cm->usage_count); 01102 }
| gboolean gnc_commodity_is_currency | ( | const gnc_commodity * | cm | ) |
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency.
| cm | The commodity to check. |
Definition at line 1590 of file gnc-commodity.c.
01591 { 01592 const char *ns_name; 01593 if (!cm) return FALSE; 01594 01595 ns_name = gnc_commodity_namespace_get_name(cm->namespace); 01596 return (!safe_strcmp(ns_name, GNC_COMMODITY_NS_LEGACY) || 01597 !safe_strcmp(ns_name, GNC_COMMODITY_NS_CURRENCY)); 01598 }
| gboolean gnc_commodity_is_iso | ( | const gnc_commodity * | cm | ) |
Checks to see if the specified commodity is an ISO 4217 recognized currency.
| cm | The commodity to check. |
Definition at line 1583 of file gnc-commodity.c.
| GList* gnc_commodity_namespace_get_commodity_list | ( | const gnc_commodity_namespace * | ns | ) |
Return a list of all commodity data structures in the specified namespace.
Definition at line 1215 of file gnc-commodity.c.
| const char* gnc_commodity_namespace_get_name | ( | const gnc_commodity_namespace * | ns | ) |
Return the textual name of a namespace data strucure.
| ns | A pointer to the namespace data strucure. |
Definition at line 1207 of file gnc-commodity.c.
01208 { 01209 if (ns == NULL) 01210 return NULL; 01211 return ns->name; 01212 }
| gboolean gnc_commodity_namespace_is_iso | ( | const char * | namespace | ) |
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
| namespace | The string to check. |
Definition at line 1224 of file gnc-commodity.c.
01225 { 01226 return ((safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0) || 01227 (safe_strcmp(namespace, GNC_COMMODITY_NS_CURRENCY) == 0)); 01228 }
| gnc_commodity* gnc_commodity_new | ( | QofBook * | book, | |
| const char * | fullname, | |||
| const char * | namespace, | |||
| const char * | mnemonic, | |||
| const char * | cusip, | |||
| int | fraction | |||
| ) |
Create a new commodity. This function allocates a new commodity data structure, populates it with the data provided, and then generates the dynamic names that exist as part of a commodity.
| book | The book that the new commodity will belong to. | |
| fullname | The complete name of this commodity. E.G. "Acme Systems, Inc." | |
| namespace | An aggregation of commodities. E.G. ISO4217, Nasdaq, Downbelow, etc. | |
| mnemonic | An abbreviation for this stock. For publicly traced stocks, this field should contain the stock ticker symbol. This field is used to get online price quotes, so it must match the stock ticker symbol used by the exchange where you want to get automatic stock quote updates. E.G. ACME, ACME.US, etc. | |
| cusip | A string containing the CUSIP code or similar UNIQUE code for this commodity. The stock ticker is NOT appropriate as that goes in the mnemonic field. | |
| fraction | The smallest division of this commodity allowed. I.E. If this is 1, then the commodity must be traded in whole units; if 100 then the commodity may be traded in 0.01 units, etc. |
Definition at line 559 of file gnc-commodity.c.
00562 { 00563 gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL); 00564 gnc_commodity_table *table; 00565 00566 qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book); 00567 table = gnc_commodity_table_get_table(book); 00568 if (namespace) { 00569 retval->namespace = gnc_commodity_table_find_namespace(table, namespace); 00570 if (!retval->namespace) 00571 retval->namespace = gnc_commodity_table_add_namespace(table, namespace, book); 00572 } else { 00573 retval->namespace = NULL; 00574 } 00575 00576 retval->fullname = CACHE_INSERT(fullname); 00577 retval->mnemonic = CACHE_INSERT(mnemonic); 00578 retval->cusip = CACHE_INSERT(cusip); 00579 retval->fraction = fraction; 00580 retval->mark = 0; 00581 retval->quote_flag = 0; 00582 retval->quote_source = NULL; 00583 retval->quote_tz = CACHE_INSERT(""); 00584 00585 reset_printname(retval); 00586 reset_unique_name(retval); 00587 if (gnc_commodity_namespace_is_iso(namespace)) 00588 retval->quote_source = gnc_quote_source_lookup_by_internal("currency"); 00589 qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL); 00590 00591 return retval; 00592 }
| gnc_commodity* gnc_commodity_obtain_twin | ( | const gnc_commodity * | from, | |
| QofBook * | book | |||
| ) |
Given the commodity 'from', this routine will find and return the equivalent commodity (commodity with the same 'unique name') in the indicated book. This routine is primarily useful for setting up clones of things across multiple books.
Definition at line 1264 of file gnc-commodity.c.
01265 { 01266 gnc_commodity *twin; 01267 const char * ucom; 01268 gnc_commodity_table * comtbl; 01269 01270 if (!from) return NULL; 01271 comtbl = gnc_commodity_table_get_table (book); 01272 if (!comtbl) return NULL; 01273 01274 ucom = gnc_commodity_get_unique_name (from); 01275 twin = gnc_commodity_table_lookup_unique (comtbl, ucom); 01276 if (!twin) 01277 { 01278 twin = gnc_commodity_clone (from, book); 01279 twin = gnc_commodity_table_insert (comtbl, twin); 01280 } 01281 return twin; 01282 }
| void gnc_commodity_set_cusip | ( | gnc_commodity * | cm, | |
| const char * | cusip | |||
| ) |
Set the 'exchange code' for the specified commodity. This should be a pointer to a null terminated string of the form "AXQ14728", etc.
| cm | A pointer to a commodity data structure. | |
| cusip | A pointer to the cusip or other exchange specific data for this commodity. This string belongs to the caller and will be duplicated by the engine. |
Definition at line 928 of file gnc-commodity.c.
00930 { 00931 if(!cm) return; 00932 if(cm->cusip == cusip) return; 00933 00934 gnc_commodity_begin_edit(cm); 00935 CACHE_REMOVE (cm->cusip); 00936 cm->cusip = CACHE_INSERT (cusip); 00937 mark_commodity_dirty(cm); 00938