How to add a security from a python script

md_oz's Avatar

md_oz

21 Jan, 2018 08:41 PM

I'm trying to add a security to the security master via a python script.

I know the 'New Security" dialog does this, but I want to read my security attributes from a file and add a new security from a python script. The information I would read from the file is the same as what is entered manually in the 'New Security" dialog, namely:
- Security ID
- Security Name
- Ticker Symbol
- Price
- Value Prefix
- Value Suffix
- Max. Decimal Places
- Show on summary page

Is there any way I can invoke the java program behind the 'New Security" dialog from python to add a security?

I can see how to delete an item (via the .getCurrencyByID(symbol_id).deleteItem() method), but I can't determine how to add an item.

Can you share an example of how to do this please?

Thank you.

  1. 1 Posted by whitedavidp on 23 Feb, 2018 12:28 AM

    whitedavidp's Avatar

    Have not actually tried this but I think the pseudo code for this would be

    import from com.infinitekind.moneydance.model import CurrencyTable, CurrencyType

    book = moneydance.getCurrentAccountBook()
    currencies = book.getCurrencies().getAllCurrencies()
    newCurrency = CurrencyType(book)
    newCurrency.setTickerSymbol("symbol")
    newCurrency.setName("name")
    newCurrency.setIDString("id")
    ...

    and so forth. Or it seems maybe faster/better to use:

    book = moneydance.getCurrentAccountBook()
    currencies = book.getCurrencies().getAllCurrencies()
    com.infinitekind.moneydance.model.CurrencyType.newCurrency = currencyFromFields(id, id_string, name, rate, decimalPlaces, prefix, suffix, tickerSymbol, effectiveDate, currencyType, currencies)

    See the CurrencyType class in those within the com.infinitekind.moneydance.model package documented here <https://infinitekind.com/dev/apidoc/index.html>.

    Good luck.

  2. System closed this discussion on 25 May, 2018 12:30 AM.

  3. md_oz re-opened this discussion on 18 Sep, 2018 12:19 PM

  4. System closed this discussion on 18 Sep, 2018 12:20 PM.

  5. md_oz re-opened this discussion on 18 Sep, 2018 12:38 PM

  6. 2 Posted by md_oz on 18 Sep, 2018 12:38 PM

    md_oz's Avatar

    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.

    A big thank you to whitedavidp and jaraco (https://github.com/jaraco/moneydance/blob/master/migration.py) 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.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac