-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// +build example | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
ib "github.com/tomlister/ibclient" | ||
) | ||
|
||
func main() { | ||
ib.SetBaseURL("https://localhost:5000/v1") | ||
// Authenticate with the brokerage server | ||
ib.Authenticate() | ||
// IBKR will time out the sso session if left inactive | ||
// Here KeepAlive is scheduled to run async every minute | ||
ib.Schedule(func() { | ||
ib.KeepAlive() | ||
}, time.Minute) | ||
// Grab the active brokerage account | ||
broker := ib.Brokers().Selected() | ||
// Get all of the portfolios under the user account | ||
portfolios := ib.Portfolios() | ||
// Get the positions under a specific (in this case the first) portfolio | ||
positions := portfolios[0].Positions() | ||
// Filter the positions by asset class | ||
futures := positions.FilterAssets(ib.Futures) | ||
for _, p := range futures { | ||
// Create a new reference to a security from a position | ||
sec := broker.Security(p) | ||
// Retrieve a market data snapshot for that security | ||
fmt.Println(sec.Snapshot(ib.OpenPrice, ib.ClosePrice, ib.High, ib.Low, ib.Volume)) | ||
} | ||
} |