set prices python script

Larry Thoma's Avatar

Larry Thoma

12 Mar, 2025 01:34 AM

Greetings,
I am trying to figure out why some of the stocks get a price update when I use this script (my version is md_price_history_script.py) and a data file as shown in the example (md_sph.csv).
The results when I run the script indicate the price was successfully set for each stock but when I back check a significant number are not updated and others have the current price every time.
Please let me know what I can check to try to resolve this issue.
Best regards,
Larry

  1. 1 Posted by Stuart Beesley ... on 12 Mar, 2025 08:18 AM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Please attach your script and csv file otherwise we cannot help.

  2. 2 Posted by Larry Thoma on 12 Mar, 2025 12:26 PM

    Larry Thoma's Avatar

    Sorry, they were attached, but when I submitted the discussion there was a glitch and must have dropped. I am attaching again.

  3. 3 Posted by Stuart Beesley ... on 12 Mar, 2025 02:05 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    This looks suspect:

    if dateint:
            security.setSnapshotInt(dateint, price).syncItem()
    

    Try trapping ‘if not dateint’ and also I’ll have to check out the ‘ security.setSnapshotInt(dateint, price).syncItem()’ as I’m not sure which object this is syncing?

  4. 4 Posted by Stuart Beesley ... on 12 Mar, 2025 02:08 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Ok. It’s returning the snapshot object so that should be fine. I’ll debug it later.

  5. 5 Posted by Stuart Beesley ... on 12 Mar, 2025 02:12 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Do any of these tickers consistently NOT work? Or is it random? And is it the dated price that’s missing, or the current price, or both, or is that random too?

  6. 6 Posted by Stuart Beesley ... on 12 Mar, 2025 03:22 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    OK, I ran your script with your data and all securities updated fine?

  7. 7 Posted by Larry Thoma on 13 Mar, 2025 04:01 AM

    Larry Thoma's Avatar

    Greetings Stuart,
    Sorry for the late reply,

    I've had a mixture.
    Some always seem to update (ABSI, BFLY, CAMT, CRS, EXLS)
    Some that updated but have since quit (TTD)
    Some that never update since I have been using the script (WHD, CTRE, EXEL)
    I started using the script in June of 2024.

    Some of the stocks I have had for long periods, others were recent
    additions.
    The dated price is not current, and the current price reflects the last
    dated price
    one that is working:

    [image: image.png]
    one that is not - note that the most current entry is 2/20/25 when the
    stock was last bought.
    [image: image.png]

    These are the values from the csv I attached to the discussion.
    EXEL,39.1550,20250310
    EXLS,45.7700,20250310

    Please let me know your thoughts.
    Best regards,
    Larry

  8. 8 Posted by dwg on 13 Mar, 2025 04:18 AM

    dwg's Avatar

    It seems to me you may be trying to reinvent the wheel here.

    Have you looked at Mike Bray's Security Price and History Load extensions?

    https://github.com/mrbray99/moneydanceproduction/wiki/Security-Price-and-History-Load

  9. 9 Posted by Stuart Beesley ... on 13 Mar, 2025 07:16 AM

    Stuart Beesley (Mr Toolbox)'s Avatar

    I’m confused why in your screenshot for EXEL you have differing highs and lows as these are not from your import file? How were these set?

    Questions:
    1. Are you you sure that you’re not running QL or Q&ER extensions?

    2. Run toolbox extension. Update mode. Security menu. Diagnose your hidden price date field.

    3. What version of MD are you running.

    4. Show me the settings on the edit screen of these two securities.

  10. 10 Posted by Larry Thoma on 13 Mar, 2025 01:26 PM

    Larry Thoma's Avatar

    Sorry for the confusion on the csv. When I run the script it will only have
    the end of day price for that specific day. In the example csv they were
    the prices for Mar 10. The CSV file would have been different for Mar 7,
    Feb 28, etc and would have values specific for those days.

    Q&ER extensions are loaded from when I could get prices from
    Alphavantage (before they limited the number of stocks), and TDA before it
    became Schwab and the interface unavailable. I have a different group of
    scripts that allow me to get price information from Schwab for separate
    stock tracking that I have developed using python / postgresql. The csv
    file is an extract from the postgresql data. Q&ER is listed as do not
    update for rates and prices and has not been run since sept 3 2024.

    Should I remove Q&ER? I see a warning about it on the opening screen of
    toolbox.
    [image: image.png]

    MD version 2024.4 (5253)

    [image: image.png]
    [image: image.png]

    I just noted that EXEL stock was used in a different investment account in
    2023. It appears the script is updating the stock prices in this account
    but not the one I noted earlier.

    [image: image.png]
    [image: image.png]

    [image: image.png]

    ***
    To answer the question from dwg on Mike Bray's extensions. I have not
    looked at them, most of the options I have looked at wanted you to sign up
    for expensive services to get the daily information. More for real time
    traders.

  11. 11 Posted by Stuart Beesley ... on 13 Mar, 2025 03:37 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    If you're not using QL / Q&ER, then yes, remove then...

    I have updated your script with more diagnostic logging... Can you try it (perhaps on a test dataset, or at least backup first)..

    (You will have to edit line 3 (filename))

  12. 12 Posted by Larry Thoma on 13 Mar, 2025 04:54 PM

    Larry Thoma's Avatar

    I removed Q&ER, did not see QL installed.
    I ran your script, this is the result file.
    I checked a couple of the stocks that I had noted not updated before (TTD,
    WHD, CTRE) and they still do not show the prices for Mar 10 even though
    they were noted as successful.
    Excl still shows as current in one account (however that account does not
    currently have quantities of this stock) and not updated in the one that
    does.
    do you want me to run the

       1.

       Run toolbox extension. Update mode. Security menu. Diagnose your hidden
       price date field.

    I did not earlier due to the notices of issues with Q&ER.
    Please let me know, since you are working the issue with me I don't want to
    do things that may conflict with your troubleshooting.
    Thanks for the help!
    Best regards,
    Larry

  13. 13 Posted by Stuart Beesley ... on 13 Mar, 2025 05:20 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    do not run the diagnose yet...

    I do not understand... This was CTRE

    Processing: CTRE 25.81 03/10/2025 (Security: CareTrust REIT, Inc. - Common Stock)
    ... SKIPPING: CTRE (as price for date 03/10/2025 already exists: ph: 25.81 vs snap: 25.81)

    It clearly says that CTRE already has a dated price.. Are you saying that it doesn't? If it doesn't, please send screenshot of that security and also its edit screen.

    Also, are you sure that you do not have duplicated securities with the same ticker?

  14. 14 Posted by Larry Thoma on 13 Mar, 2025 05:54 PM

    Larry Thoma's Avatar

    This is the info from the account that has stocks currently.
    [image: image.png]
    [image: image.png]

    The other two accounts (one active, one inactive) have the same values for
    the security history and edit security shown above.
    Is there a way to search by ticker symbol to see if there was an issue when
    the stock was added by downloads from fidelity, tda, or schwab?
    Trying to figure out how to search for duplicate tickers as you indicated.

    Best regards,

  15. 15 Posted by Stuart Beesley ... on 13 Mar, 2025 07:23 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Toolbox can find duplicates.

  16. 16 Posted by Stuart Beesley ... on 13 Mar, 2025 07:33 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    I'm convinced you have duplicates...

    Run this code:

    
    from com.infinitekind.moneydance.model import CurrencyType
    MD_REF=moneydance


    if True:
    allSecurities = [secCurr for secCurr in MD_REF.getCurrentAccountBook().getCurrencies().getAllCurrencies() if secCurr.getCurrencyType() is CurrencyType.Type.SECURITY] foundSecIDs = {} foundSecNames = {} foundSecTickers = {} for sec in allSecurities: secID = sec.getIDString().lower().strip() name = sec.getName().lower().strip() ticker = sec.getTickerSymbol().lower().strip() if secID != "": foundSecIDs[secID] = foundSecIDs.get(secID, []) + [sec] if name != "": foundSecNames[name] = foundSecNames.get(name, []) + [sec] if ticker != "": foundSecTickers[ticker] = foundSecTickers.get(ticker, []) + [sec] securitiesInvolved = {} duplicateSecurities = [] for what in sorted(foundSecIDs): if len(foundSecIDs[what]) > 1: for sec in foundSecIDs[what]: securitiesInvolved[sec] = True duplicateSecurities.append(["ID:", foundSecIDs[what][0].getIDString(), foundSecIDs[what]]) for what in sorted(foundSecNames): if len(foundSecNames[what]) > 1: for sec in foundSecNames[what]: securitiesInvolved[sec] = True duplicateSecurities.append(["Name:", foundSecNames[what][0].getName(), foundSecNames[what]]) for what in sorted(foundSecTickers): if len(foundSecTickers[what]) > 1: for sec in foundSecTickers[what]: securitiesInvolved[sec] = True duplicateSecurities.append(["Ticker:", foundSecTickers[what][0].getTickerSymbol(), foundSecTickers[what]]) output = None if len(duplicateSecurities) > 0: output = "POTENTIAL DUPLICATE SECURITIES:\n" \ " ------------------------------\n" for dup in duplicateSecurities: secTxt = "[" for sec in dup[2]: secTxt += "'%s'," %(sec.getName()) secTxt += "]" output += "%s '%s' Found in (%s): %s\n" %(dup[0], dup[1], len(dup[2]), secTxt) # Avoid IllegalArgument Exceptions....! output += "\n" \ "--- Unique list of Securities with potential duplicates:\n" for sec in sorted(securitiesInvolved, key=lambda _x: (_x.getName().lower())): output += "%s(Ticker: %s, ID: %s)\n" %(sec.getName(), sec.getTickerSymbol(), sec.getIDString()) output += "\n<END>" print output
  17. 17 Posted by Larry Thoma on 13 Mar, 2025 09:05 PM

    Larry Thoma's Avatar

    received the following error when trying to run from developer console
    Welcome to the interactive development console for Moneydance 2024.4(5253)
    Java version: 21.0.5, Jython version: 2.7.2(final), running on
    Linux(6.8.0-55-generic) amd64(intel64)
    Use the variable 'moneydance' to access Moneydance's API...
    example: 'moneydance.getUI()' for the GUI, and
    'moneydance.getCurrentAccountBook()' for the dataset
    ---------------------------------------------------------------------------------------------------
    Beginning snippet at Thu Mar 13 14:02:02 MST 2025

    -------------------------
    Error running snippet...: File "<string>", line 19
        if secID != &quot;&quot;: foundSecIDs[secID] = foundSecIDs.get(secID,
    []) + [sec]
                   ^
    SyntaxError: no viable alternative at input '&'

    -------------------------

  18. 18 Posted by Stuart Beesley ... on 13 Mar, 2025 09:09 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    That’s a copy / paste issue. You need to click the link to open this support page and then copy just the code and paste.

  19. 19 Posted by Stuart Beesley ... on 13 Mar, 2025 09:59 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    OK, version 3 attached. I have included the duplicate ticker check within this code:

  20. 20 Posted by Larry Thoma on 13 Mar, 2025 10:27 PM

    Larry Thoma's Avatar

    Here is the result from the script.

    Thanks again for your help
    Larry

  21. 21 Posted by Stuart Beesley ... on 14 Mar, 2025 09:45 AM

    Stuart Beesley (Mr Toolbox)'s Avatar

    I think the results speak for themselves.. All the tickers you are saying are not updating, have duplicates... You should only have ONE security/ticker for all accounts that hold any security. It looks like you have one security per account.. The script is working, it's just random which of the duplicate tickers it updates first... You really need to merge the duplicate securities (using toolbox)...

    If you really want to, I can show you how to update this script to update the duplicate tickers too..?

  22. 22 Posted by Larry Thoma on 14 Mar, 2025 02:09 PM

    Larry Thoma's Avatar

    I agree that there should only be one security/ticker for all accounts.
    First, I would like to know how to use toolbox to merge the duplicate
    securities. Second, what do I need to do differently so that I do not have
    to recreate the security if I use it in a different account but instead use
    the existing security/ticker. It seems that the automated downloads and
    when I add manually I am prompted to create the ticker before it can be
    used.

    Best regards,
    Larry

  23. Support Staff 23 Posted by Maddy on 14 Mar, 2025 02:31 PM

    Maddy's Avatar

    Hi Larry,

    In order to merge duplicate securities within the same account, you could proceed as follow:

    • Launch the Toolbox and select 'Update mode'

    In the MENU: Currency & Security tools tab, choose:
    FIX: Detect and merge/fix duplicate Security within same Investment Account

    Select->proceed and follow the on-screen instruction.

    Finally, restart Moneydance to retain the changes.

    Please let us know if you have further questions or need more assistance.

    --
    Maddy, Infinite Kind Support

  24. 24 Posted by Larry Thoma on 14 Mar, 2025 04:22 PM

    Larry Thoma's Avatar

    Hi Maddy,
    Thanks for the feedback.
    However, I have several investment accounts and I think that my issue is
    that each investment account has its own set of securities.
    Will this correct that issue so there is only one ticker?

    Best regards,
    Larry

    On Fri, Mar 14, 2025 at 7:31 AM Maddy <[email blocked]>
    wrote:

  25. 25 Posted by Stuart Beesley ... on 14 Mar, 2025 09:20 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    There is another toolbox menu option to merge duplicate securities. This is the one you want. So that you end up with singular securities shared across several accounts.

  26. 26 Posted by Larry Thoma on 15 Mar, 2025 12:35 AM

    Larry Thoma's Avatar

    Hi Stuart,
    I tried the toolbox option to merge duplicate securities into one master
    file.
    it appears that there are several criteria that must be in place to start
    with, including identical price history data.

    How would you approach matching the price history data? Is there other
    criteria I need to address before trying to merge the data?
    The attached is the output from the attempt to merge the data.

    Thanks again for your help, sorry this is such a hassle.
    Best regards,
    Larry

  27. 27 Posted by Stuart Beesley ... on 15 Mar, 2025 01:51 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    (Sorry for delay, I’m not getting notified of your replies).

    The price history does NOT have to match. The merge will allow you to merge history.

    The rules are clearly stated.

    The check / validation rules are:
    - Find potential 'duplicates' where Securities' 'Ticker' Symbols are the same/match (cannot be blank); then Duplicate Security's...:
    ... ID must be short and DIFFERENT (so you can identify them in this process). Examples: use '^APPL1', '^APPL2', '^APPL3'.. to merge 3 Apple Stocks
    ....(^^Close this window and use Tools>Securities>EDIT and change the Security ID for each duplicate and then re-run this function again)
    ...'Currency' must match
    ...'Current Price' must match
    ...'Prefix' & 'Suffix' must match
    ...'Splits' data must match
    ... hidden 'Decimal Places' setting must match **
    - NOTE: Security Name is not matched, but you can select the Security to become the 'master', that has right details, as part of the process
    

    So make sure for each ticker, the duplicate securities have different IDs - eg ticker APPLE. IDs Apple1, Apple2 etc.

    The error in the log you provided said to make the current price the same on duplicate securities you want to merge. Eg for Apple all current prices should be 213.49 for example.

    Keep me posted.

    By all means email me:

  28. 28 Posted by Larry Thoma on 16 Mar, 2025 01:54 AM

    Larry Thoma's Avatar

    Hi Stuart,
    Have fixed all of the validation rule issues. Now starting to work through
    the security merge. I think it will take a bit since it appears to be only
    one at a time.

    Thanks again for the help, I will keep you posted.
    Best regards,
    Larry

  29. 29 Posted by Stuart Beesley ... on 16 Mar, 2025 07:32 AM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Backup first.
    I would do one security at a time and restart MD in between each merge.

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