samjtro / schwab

⚡ fast unofficial schwab traderapi hook
https://pkg.go.dev/github.com/samjtro/schwab
GNU General Public License v2.0
8 stars 2 forks source link

Incorrect HOMEDIR on Windows. #60

Open KeithP2019 opened 1 month ago

KeithP2019 commented 1 month ago

what happened?

When trying to initialize on Windows with a newer version of Go (>=1.12) I get an error with the homedir path:

mkdir C:\Users\MySystem\MyUsername/.trade: The system cannot find the path specified.

Windows is inserting the System (or Windows Domain) name with the actual username. The expected path should be:

C:\Users\MyUsername/.trade not C:\Users\MySystem\MyUsername/.trade

It looks like the current recommendation is to use os.UserHomeDir() instead.

So, line 115 in utils should change from:

    case "windows":
        homedir = "C:\\Users\\" + currentUser.Username

to:

    case "windows":
        homedir,err = os.UserHomeDir()

what did you expect to happen?

Windows provides the proper path to the home directory for the current user.

samjtro commented 1 month ago

hi @KeithP2019 ! i was unaware of os.UserHomeDir(), thank you for the tip.

i'll implement this now - if you'd like to reinitialize, i'd love to hear if you run into any Windows-specific issues; as although i should have, i have not yet tested on Windows.