Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noob question: how can I access to my portfolio? #38

Open
cocodrino opened this issue Dec 11, 2019 · 1 comment
Open

noob question: how can I access to my portfolio? #38

cocodrino opened this issue Dec 11, 2019 · 1 comment

Comments

@cocodrino
Copy link

I've several stocks in my portfolio and I'd like to access them using go,

portfolio

right now I've the current code

account,err := ib.NewPrimaryAccountManager(engine)

if err != nil {
		fmt.Println("error getting account ",err)
	}

portfolio := account.Portfolio()

fmt.Println("Portfolio ", portfolio)

but I'm getting an empty map as portfolio

hope you can help me, thank you so much

@dsouzae
Copy link
Contributor

dsouzae commented Jul 20, 2020

In your case you need to wait for the request to the gateway to complete. Here is an example code you can use:

    account, err := ib.NewPrimaryAccountManager(engine)

    if err != nil {
        fmt.Println("error getting account ", err)
    }

    notify := account.Refresh()

    for {
        select {
        case <-notify:
            fmt.Printf("Portfolio\n")
            portfolio := account.Portfolio()
            for _, xc := range portfolio {
                fmt.Printf("%v\n", xc)
            }   
        }       
    }

You will get multiple calls to returned from the Manager.

Or you can use the following code if just want one time use:

    <-account.Refresh()
    fmt.Printf("Portfolio\n")
    portfolio := account.Portfolio()
    for _, xc := range portfolio {
        fmt.Printf("%v\n", xc)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants