github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/rest-candles/main.go (about) 1 package main 2 3 import ( 4 "log" 5 "time" 6 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/common" 8 bfx "github.com/bitfinexcom/bitfinex-api-go/v2" 9 "github.com/bitfinexcom/bitfinex-api-go/v2/rest" 10 "github.com/davecgh/go-spew/spew" 11 ) 12 13 func main() { 14 c := rest.NewClient() 15 16 last(c) 17 history(c) 18 historyWithQuery(c) 19 } 20 21 func last(c *rest.Client) { 22 candle, err := c.Candles.Last(common.TradingPrefix+"BTCUSD", common.FiveMinutes) 23 if err != nil { 24 log.Fatalf("last: %s", err) 25 } 26 27 spew.Dump(candle) 28 } 29 30 func history(c *rest.Client) { 31 candles, err := c.Candles.History(common.TradingPrefix+"BTCUSD", common.FiveMinutes) 32 if err != nil { 33 log.Fatalf("history: %s", err) 34 } 35 36 spew.Dump(candles) 37 } 38 39 func historyWithQuery(c *rest.Client) { 40 now := time.Now() 41 millis := now.UnixNano() / 1000000 42 prior := now.Add(time.Duration(-24) * time.Hour) 43 millisStart := prior.UnixNano() / 1000000 44 start := common.Mts(millisStart) 45 end := common.Mts(millis) 46 47 candles, err := c.Candles.HistoryWithQuery( 48 common.TradingPrefix+bfx.BTCUSD, 49 common.FiveMinutes, 50 start, 51 end, 52 200, 53 common.OldestFirst, 54 ) 55 56 if err != nil { 57 log.Fatalf("historyWithQuery: %s", err) 58 } 59 60 spew.Dump(candles) 61 }