github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/rest-public-trades/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"time"
     7  
     8  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/common"
     9  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
    10  )
    11  
    12  func main() {
    13  	c := rest.NewClient()
    14  
    15  	// calculate start and end
    16  	now := time.Now()
    17  	millis := now.UnixNano() / 1000000
    18  	prior := now.Add(time.Duration(-24) * time.Hour)
    19  	millisStart := prior.UnixNano() / 1000000
    20  	start := common.Mts(millisStart)
    21  	end := common.Mts(millis)
    22  	// send request
    23  	trades, err := c.Trades.PublicHistoryWithQuery("tBTCUSD", start, end, 10, common.OldestFirst)
    24  	if err != nil {
    25  		log.Fatalf("%v", err)
    26  	}
    27  	for _, trade := range trades.Snapshot {
    28  		fmt.Println(trade)
    29  	}
    30  }