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

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"time"
     7  
     8  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
     9  	"github.com/davecgh/go-spew/spew"
    10  )
    11  
    12  // Set BFX_API_KEY and BFX_API_SECRET:
    13  //
    14  // export BFX_API_KEY=<your-api-key>
    15  // export BFX_API_SECRET=<your-api-secret>
    16  //
    17  // you can obtain it from https://www.bitfinex.com/api
    18  
    19  func main() {
    20  	key := os.Getenv("BFX_API_KEY")
    21  	secret := os.Getenv("BFX_API_SECRET")
    22  
    23  	c := rest.
    24  		NewClient().
    25  		Credentials(key, secret)
    26  
    27  	now := time.Now()
    28  	millis := now.UnixNano() / 1000000
    29  	prior := now.Add(time.Duration(-240) * time.Hour)
    30  	millisStart := prior.UnixNano() / 1000000
    31  
    32  	l, err := c.Ledgers.Ledgers("BTC", millisStart, millis, 1000)
    33  	if err != nil {
    34  		log.Fatalf("Ledgers: %s", err)
    35  	}
    36  
    37  	spew.Dump(l)
    38  }