github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/rest-submit-order/main.go (about) 1 package main 2 3 import ( 4 "os" 5 "time" 6 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/order" 8 "github.com/bitfinexcom/bitfinex-api-go/v2/rest" 9 ) 10 11 // Set BFX_APIKEY and BFX_SECRET as : 12 // 13 // export BFX_API_KEY=YOUR_API_KEY 14 // export BFX_API_SECRET=YOUR_API_SECRET 15 // 16 // you can obtain it from https://www.bitfinex.com/api 17 18 func main() { 19 key := os.Getenv("BFX_KEY") 20 secret := os.Getenv("BFX_SECRET") 21 c := rest.NewClientWithURL("https://test.bitfinex.com/v2/").Credentials(key, secret) 22 23 // create order 24 response, err := c.Orders.SubmitOrder(&order.NewRequest{ 25 Symbol: "tBTCUSD", 26 CID: time.Now().Unix() / 1000, 27 Amount: 0.02, 28 Type: "EXCHANGE LIMIT", 29 Price: 5000, 30 }) 31 if err != nil { 32 panic(err) 33 } 34 time.Sleep(time.Second * 5) 35 orders := response.NotifyInfo.(*order.Snapshot) 36 // update orders 37 for _, o := range orders.Snapshot { 38 response, err = c.Orders.SubmitUpdateOrder(&order.UpdateRequest{ 39 ID: o.ID, 40 Price: 6000, 41 }) 42 if err != nil { 43 panic(err) 44 } 45 // cancel orders 46 updatedOrder := response.NotifyInfo.(*order.Update) 47 err := c.Orders.SubmitCancelOrder(&order.CancelRequest{ 48 ID: updatedOrder.ID, 49 }) 50 if err != nil { 51 panic(err) 52 } 53 } 54 }