github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/rest-positions/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "os" 7 8 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/position" 9 "github.com/bitfinexcom/bitfinex-api-go/v2/rest" 10 "github.com/davecgh/go-spew/spew" 11 ) 12 13 // Set BFX_API_KEY and BFX_API_SECRET: 14 // 15 // export BFX_API_KEY=<your-api-key> 16 // export BFX_API_SECRET=<your-api-secret> 17 // 18 // you can obtain it from https://www.bitfinex.com/api 19 20 func main() { 21 key := os.Getenv("BFX_API_KEY") 22 secret := os.Getenv("BFX_API_SECRET") 23 c := rest.NewClient().Credentials(key, secret) 24 25 all(c) 26 claim(c) 27 } 28 29 func all(c *rest.Client) { 30 p, err := c.Positions.All() 31 if err != nil { 32 log.Fatalf("All: %s", err) 33 } 34 35 for _, ps := range p.Snapshot { 36 fmt.Println(ps) 37 } 38 } 39 40 func claim(c *rest.Client) { 41 pc, err := c.Positions.Claim(&position.ClaimRequest{ 42 Id: 36228736, 43 }) 44 if err != nil { 45 log.Fatalf("Claim: %s", err) 46 } 47 48 spew.Dump(pc) 49 }