StockGlance2020 - Python script to display and extract the totals of stock/fund unit qty balances by security

Stuart Beesley's Avatar

Stuart Beesley

24 Sep, 2020 05:16 PM

For anyone that wants it, Python script to extract / total stock / unit qty balances by Security (as MD doesn’t have a report to do this). Original Credit to @jameslarus and waynelloydsmith as I took StockGlance as a base).

For example: if I have share/security "Company X" in 3 different ac counts - e.g. 100, 300, 500, then this script will tell you that you have 900 of this security. MD reports do not do this. The report also shows you a lot more, deals with currency, totals, and can show cash balances.

It's quite clever with lots of user parameters and filters. Let me know of any issues...

Showing page 2 out of 2. View the first page

  1. 31 Posted by Stuart Beesley on 22 Oct, 2020 09:43 AM

    Stuart Beesley's Avatar

    Hi, the link below is fine, but note it’s the beta version (as it’s in dev). It’s fine to use this - it works - but great to have ’testers’ providing updates. I plan to load (working) functional updates here before the main release. You should see 4d now. I think I’ve fixed the non-ascii character issue. Let me know?

    Beta test link:
    https://github.com/yogi1967/MoneyDancePythonScripts/blob/dev/StockGlance2020.py <https://github.com/yogi1967/MoneyDancePythonScripts/blob/dev/StockGlance2020.py>

    SCB

  2. 32 Posted by derekkent23 on 22 Oct, 2020 09:54 AM

    derekkent23's Avatar

    Hi Stuart

    I still get.

    SyntaxError: Non-ASCII character in file 'C:\Users\derek\OneDrive\MONEYDANCE\Script to display and CSV Export Security Totals\StockGlance2020.py', but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

  3. 33 Posted by Stuart Beesley on 22 Oct, 2020 10:29 AM

    Stuart Beesley's Avatar

    Hi, I can’t find any dodgy characters…? Sorry to ask. I wonder if the script copied properly for you? How did you get from GitHub? You should click RAW and then select all and copy/paste; or download that raw file…
    By all means send it back to me so I can look inside the file?

  4. 34 Posted by Stuart Beesley on 22 Oct, 2020 01:00 PM

    Stuart Beesley's Avatar

    Resolved: FYI - in GitHub you either need to right click the file link and save link as, or click RAW and then copy/paste the script. (If you just save what GitHub displays then you are just saving an HTML web page and not the actual script).

    Regards Stuart

  5. 35 Posted by Cyril Couten on 23 Oct, 2020 07:35 AM

    Cyril Couten's Avatar

    The display works fine (I understand you will add the cost & gain at a
    later stage).
    However the filing seems to have problems, no file being filed ... Pls see
    below ...

    Beginning file C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py at Fri
    Oct 23 09:31:59 CEST 2020
    StuWareSoftSystems...
    StockGlance2020.py....... Version: 4d
    Parameters...
    Hiding Hidden Securities...
    Hiding Inactive Accounts...
    Hiding Hidden Accounts...
    Selecting ALL Currencies...
    Selecting ALL Securities...
    Selecting ALL Accounts...
    Including Cash Balances - WARNING - this is per account!
    Splitting Securities by account - WARNING, this will disable sorting....
    Will strip non-ASCII characters - e.g. Currency symbols from output
    file... Using Delimiter: ,
    Will display Stock balances and then extract to file:
     C:\CC_DATA\MONEYDANCE\extract_stock_balances.csv (NOTE: Should drop non
    utf8 characters...)
    !!!FILE WILL BE GENERATED AFTER YOU CLOSE THE TABLE VIEW WINDOW!!!
    Error running script: Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: (13, 'Permission denied',
    'C:\\CC_DATA\\MONEYDANCE\\extract_stock_balances.csv')
    Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: [Errno 13] Permission denied:
    'C:\\CC_DATA\\MONEYDANCE\\extract_stock_balances.csv'
    _______________________________
    Cyril COUTEN
    Mobile : +33 6 18 40 80 65

  6. 36 Posted by Stuart Beesley on 23 Oct, 2020 07:41 AM

    Stuart Beesley's Avatar

    Very strange. It’s a permission denied issue.. :
    - Do you have permissions to the folder?
    - Was the file already open somewhere else?
    - Can you try again, choose a different file?
    - can you run in debug and send me that output?

    Thanks

  7. 37 Posted by Cyril Couten on 23 Oct, 2020 07:54 AM

    Cyril Couten's Avatar

    Here is the debug narratives ... I have deleted all the details which is
    not relevant ...

    Beginning file C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py at Fri
    Oct 23 09:47:42 CEST 2020
    StuWareSoftSystems...
    StockGlance2020.py....... Version: 4d
    DEBUG turned on
    Parameters...
    Hiding Hidden Securities...
    Hiding Inactive Accounts...
    Hiding Hidden Accounts...
    Selecting ALL Currencies...
    Selecting ALL Securities...
    Selecting ALL Accounts...
    Including Cash Balances - WARNING - this is per account!
    Splitting Securities by account - WARNING, this will disable sorting....
    Will strip non-ASCII characters - e.g. Currency symbols from output
    file... Using Delimiter: ,
    In grabTheFile ()
    Scriptpath: C:\Users\cycou\.moneydance\Documents
    Non Mac platform detected: Therefore I will run JFileChooser() to get
    filename....
    Will display Stock balances and then extract to file:
     C:\CC_DATA\PP\extract_stock_balances retry 948.csv (NOTE: Should drop non
    utf8 characters...)
    In StockGlance2020 ()
    In myJTable ()
    !!!FILE WILL BE GENERATED AFTER YOU CLOSE THE TABLE VIEW WINDOW!!!
    In createAndShowGUI ()
    In getTableModel ()
    MD Book: CCFinances
    Base Currency: EUR : Euro
    getAllCurrencies(): [EDENRED, MONCEY, Israeli New Shekel, INTERPARFUMS,
    WENDEL, FAIVELEY TRANSPORT, ALSTOM, TIEPOLO RDT, Icelandic Krona, Egyption
    Pound, BARCLAYS
    ...............deleted..............

    Skipping Security with 0 shares..: CARREFOUR Curr: EUR Price: 47.83
     Qty: 0
    In getFooterModel ()
    Generating the footer table data....
    getFooterModel: was not allOneCurrency..
    Hiding unused Currency Column...
    ScreenSize: java.awt.Dimension[width=1920,height=1080]
    Main JTable heights....
    Row Count: 372
    RowHeight: 16
    Intercell spacing: 1
    Header height: 20
    Insets, Top/Bot: java.awt.Insets[top=0,left=0,bottom=1,right=0] 0 1
    Total scrollpane height: 980
    Scrollbar height: java.awt.Dimension[width=0,height=0] 0
    Footer JTable heights....
    Row Count: 19
    RowHeight: 16
    Intercell spacing: 1
    Header height: 0
    Insets, Top/Bot: java.awt.Insets[top=0,left=0,bottom=1,right=0] 0 1
    Total scrollpane height: 335
    Scrollbar height: java.awt.Dimension[width=48,height=10] 10
    Total frame height required: 980 + 335 + Intercells: 0 1 = 1317
    Waiting for JFrame() to close... Wait number...: 1
    Waiting for JFrame() to close... Wait number...: 2
    Waiting for JFrame() to close... Wait number...: 3
    Waiting for JFrame() to close... Wait number...: 4
    Waiting for JFrame() to close... Wait number...: 5
    Waiting for JFrame() to close... Wait number...: 6
    Waiting for JFrame() to close... Wait number...: 7
    Waiting for JFrame() to close... Wait number...: 8
    Waiting for JFrame() to close... Wait number...: 9
    Waiting for JFrame() to close... Wait number...: 10
    Waiting for JFrame() to close... Wait number...: 11
    Waiting for JFrame() to close... Wait number...: 12
    Waiting for JFrame() to close... Wait number...: 13
    In windowClosing ()
    Waiting for JFrame() to close... Wait number...: 14
    No longer waiting....
    In ExportDataToFile ()
    Opening file and writing 392 records
    Error running script: Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: (13, 'Permission denied', 'C:\\CC_DATA\\PP\\extract_stock_balances
    retry 948.csv')
    Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: [Errno 13] Permission denied:
    'C:\\CC_DATA\\PP\\extract_stock_balances retry 948.csv'
    _______________________________
    Cyril COUTEN
    Mobile : +33 6 18 40 80 65

  8. 38 Posted by Stuart Beesley on 23 Oct, 2020 07:59 AM

    Stuart Beesley's Avatar

    Can you try a directory that’s not C:\CC_DATA\MONEYDANCE\ ? And or the previous version of script? I’ve not changed anything here….

    Thanks

  9. 39 Posted by Cyril Couten on 23 Oct, 2020 08:10 AM

    Cyril Couten's Avatar

    Same ... This time filing on c:\\ ...
    To be honest, apart from the 1st time where it worked, I have skipped
    checking the real filing ... So you must have changed something between the
    very first version and the subsequent ones ?

    No longer waiting....
    In ExportDataToFile ()
    Opening file and writing 392 records
    Error running script: Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: (13, 'Permission denied', 'C:\\extract_stock_balances.csv')
    Traceback (most recent call last):
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1904, in
    <module>
        ExportDataToFile()
      File "C:\CC_DATA\MONEYDANCE\StockGlance2020_v21oct_4d.py", line 1845, in
    ExportDataToFile
        if debug: print "Opening file and writing ", len(rawDataTable),
    "records"
    IOError: [Errno 13] Permission denied: 'C:\\extract_stock_balances.csv'
    _______________________________
    Cyril COUTEN
    Mobile : +33 6 18 40 80 65

  10. 40 Posted by Stuart Beesley on 23 Oct, 2020 08:17 AM

    Stuart Beesley's Avatar

    OK… Hang fire, I will send you a new script soon and we will see what that does… If you send me your email I can email you directly? (You will have to write it as email space at space domain)

  11. 41 Posted by Cyril Couten on 23 Oct, 2020 08:22 AM

    Cyril Couten's Avatar

    sure : [email blocked]
    _______________________________
    Cyril COUTEN
    Mobile : +33 6 18 40 80 65

  12. 42 Posted by Stuart Beesley on 23 Oct, 2020 05:07 PM

    Stuart Beesley's Avatar

    V4e (beta) of script with many enhancements

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • StockGlance2020_v2.py 71.8 KB

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