tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/2025-how-to-add-a-security-from-a-python-scriptInfinite Kind: Discussion 2018-12-18T12:40:25Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/445539802018-02-23T00:28:27Z2018-02-23T00:28:27ZHow to add a security from a python script<div><p>Have not actually tried this but I think the pseudo code for this would be</p>
<p>import from com.infinitekind.moneydance.model import CurrencyTable, CurrencyType</p>
<p>book = moneydance.getCurrentAccountBook()<br>
currencies = book.getCurrencies().getAllCurrencies()<br>
newCurrency = CurrencyType(book)<br>
newCurrency.setTickerSymbol("symbol")<br>
newCurrency.setName("name")<br>
newCurrency.setIDString("id")<br>
...</p>
<p>and so forth. Or it seems maybe faster/better to use:</p>
<p>book = moneydance.getCurrentAccountBook()<br>
currencies = book.getCurrencies().getAllCurrencies()<br>
com.infinitekind.moneydance.model.CurrencyType.newCurrency = currencyFromFields(id, id_string, name, rate, decimalPlaces, prefix, suffix, tickerSymbol, effectiveDate, currencyType, currencies)</p>
<p>See the CurrencyType class in those within the com.infinitekind.moneydance.model package documented here <a href="https://infinitekind.com/dev/apidoc/index.html">https://infinitekind.com/dev/apidoc/index.html</a>.</p>
<p>Good luck.</p></div>whitedavidptag:infinitekind.tenderapp.com,2009-01-14:Comment/445539802018-09-18T12:38:14Z2018-09-18T12:43:02ZHow to add a security from a python script<div><p>Sorry for the delay in getting back to this topic, but I wanted to re-open the discussion to share my final solution. I tried both options suggested by whitedavidp, but decided against using the currencyFromFields option as I thought the field by field approach was more readable and flexible. The currencyFromFields sets the security currency as the book BaseType (USD in my case) which doesn't work for non-BaseType securities and it does not allow the setting of the HideInUI, so I'd have to do these functions by field anyway.</p>
<p>A big thank you to whitedavidp and jaraco (<a href="https://github.com/jaraco/moneydance/blob/master/migration.py">https://github.com/jaraco/moneydance/blob/master/migration.py</a>) for sharing their code and expertise, that was the basis of this function, see attachment (I tried pasting it but the formatting is messed up.</p></div>md_oz