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

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"time"
     6  
     7  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
     8  	"github.com/davecgh/go-spew/spew"
     9  )
    10  
    11  func main() {
    12  	c := rest.NewClient()
    13  
    14  	getSinglePair(c)
    15  	getSinglePairWithLimit(c)
    16  	getMultiPair(c)
    17  	getForRange(c)
    18  }
    19  
    20  func getSinglePair(c *rest.Client) {
    21  	args := rest.GetTickerHistPayload{
    22  		Symbols: []string{"tLTCUSD"},
    23  	}
    24  
    25  	t, err := c.TickersHistory.Get(args)
    26  
    27  	if err != nil {
    28  		log.Fatalf("get single pair: %s", err)
    29  	}
    30  
    31  	spew.Dump("get single pair:> ", t)
    32  }
    33  
    34  func getSinglePairWithLimit(c *rest.Client) {
    35  	args := rest.GetTickerHistPayload{
    36  		Symbols: []string{"tLTCUSD"},
    37  		Limit:   10,
    38  	}
    39  
    40  	t, err := c.TickersHistory.Get(args)
    41  
    42  	if err != nil {
    43  		log.Fatalf("get single pair with limit: %s", err)
    44  	}
    45  
    46  	spew.Dump("get single pair with limit:> ", t)
    47  }
    48  
    49  func getMultiPair(c *rest.Client) {
    50  	args := rest.GetTickerHistPayload{
    51  		Symbols: []string{"tLTCUSD", "tBTCUSD"},
    52  	}
    53  
    54  	t, err := c.TickersHistory.Get(args)
    55  
    56  	if err != nil {
    57  		log.Fatalf("get multi pair: %s", err)
    58  	}
    59  
    60  	spew.Dump("get multi pair:> ", t)
    61  }
    62  
    63  func getForRange(c *rest.Client) {
    64  	now := time.Now()
    65  	yesterday := now.Add(time.Duration(-24) * time.Hour)
    66  	end := now.UnixNano() / 1000000
    67  	start := yesterday.UnixNano() / 1000000
    68  
    69  	args := rest.GetTickerHistPayload{
    70  		Symbols: []string{"tBTCUSD"},
    71  		Limit:   5,
    72  		Start:   start,
    73  		End:     end,
    74  	}
    75  
    76  	t, err := c.TickersHistory.Get(args)
    77  
    78  	if err != nil {
    79  		log.Fatalf("get for range: %s", err)
    80  	}
    81  
    82  	spew.Dump("get for range:> ", t)
    83  }