Open cocodrino opened 4 years ago
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)
}
I've several stocks in my portfolio and I'd like to access them using go,
right now I've the current code
but I'm getting an empty map as portfolio
hope you can help me, thank you so much