[GNC-dev] Extending GnuCash: CSV-import/lookup commodity by cusip
John Ralls
jralls at ceridwen.us
Fri Jan 21 16:19:20 EST 2022
Thomas,
By far the simplest solution to your problem would be to use your favorite scripting language to rewrite the CSV with the symbols you use for GnuCash.
As for the pricedb lookup by cusip and corresponding CSV column, sure, I think that would be a fine addition for GnuCash v5.
Regards,
John Ralls
> On Jan 21, 2022, at 12:39 PM, Thomas <tduellmann+gnucashdevel at gmail.com> wrote:
>
> Thanks a lot for your hints John!
>
> I think I'll need some time to find my way through the code and then try to adapt based on the existing implementation.
> Would you deem such a feature useful and worth implementing, so it might - at some point in the future - find its way into the codebase? Or do I maybe have a case that can be solved easily in another way?
>
> I can retrieve a current list of the securities/commodities in my depot. But the names are not always very intuitive or readable due to all kinds of suffixes (e.g., of stocks). For that reason, the symbol field of my commodities do not (exactly) match the ones from my bank.
> And because of that, I am struggling to do a matching based on that field. As my bank, denotes the WKN (a unique identifier), I was thinking that this would be a good way to match them properly without making the names of the securities that hard to read.
>
> If you see other, more convenient options, I am open for any recommendations (or how you maybe solve such an issue).
>
> Thanks a lot in advance!
>
> Best,
> Thomas
>
> On 1/21/22 19:53, John Ralls wrote:
>>> On Jan 21, 2022, at 9:32 AM, Thomas <tduellmann+gnucashdevel at gmail.com> wrote:
>>>
>>> Dear list,
>>>
>>> recently, I spotted a feature that I would love to have added to GnuCash. As I have a software development background, I could definitely contribute to the solution, but as it is quite some time ago that I developed in C++ and am new to contributing to GnuCash, I might need some cues.
>>>
>>> Desired feature:
>>> When importing prices from a CSV file, the matching to existing commodities seems to be possible only based on the symbol. What would be really helpful for me would be, if this matching could also be done by cusip.
>>>
>>> The optimal scenario would be the possiblity to choose either "symbol" or "cusip" in the dropdown list above the columns and then use another method that retrieves the respective commodity as done in gnucash/import-export/csv-imp/gnc-imp-props-price.cpp:106 using the symbol_str.
>>>
>>> From the functional point of view, I am currently only lacking an idea on how such a lookup based on the cusip would look like, as there seems only to be a 'gnc_commodity_table_lookup' function that only takes namespace and symbol. Would a respective method also need to be implemented or what would be the proper approach for looking up a commodity by cusip?
>>>
>>> Thanks a lot in advance and would be grateful for any hint in this regard!
>> Yes, you'd need to write a search function to find commodities by cusip. Commodities are currently stored in a nested hash table so the least-code method would be to use g_hash_table_foreach on each and test each commodity's cusip for a match. Iterating over hash tables isn't exactly efficient so that would be pretty slow.
>> The more performant way would be to create a separate hash table keyed on the cusip field and load it as part of gnc_commodity_table_insert and gnc_commodity_set_cusip.
>> If your C++ experience is with pre C++-11 you've got a lot of learning to do. The language has changed a lot.
>> Regards,
>> John Ralls
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
More information about the gnucash-devel
mailing list