github.com/polygon-io/client-go@v1.16.4/rest/example/indices/aggregates-bars/main.go (about)

     1  // Indices - Aggregates (Bars)
     2  // https://polygon.io/docs/indices/get_v2_aggs_ticker__indicesticker__range__multiplier___timespan___from___to
     3  // https://github.com/polygon-io/client-go/blob/master/rest/aggs.go
     4  package main
     5  
     6  import (
     7  	"context"
     8  	"log"
     9  	"os"
    10  	"time"
    11  
    12  	polygon "github.com/polygon-io/client-go/rest"
    13  	"github.com/polygon-io/client-go/rest/models"
    14  )
    15  
    16  func main() {
    17  	// init client
    18  	c := polygon.New(os.Getenv("POLYGON_API_KEY"))
    19  
    20  	// set params
    21  	params := models.ListAggsParams{
    22  		Ticker:     "I:SPX",
    23  		Multiplier: 1,
    24  		Timespan:   "day",
    25  		From:       models.Millis(time.Date(2023, 4, 3, 0, 0, 0, 0, time.UTC)),
    26  		To:         models.Millis(time.Date(2023, 4, 12, 0, 0, 0, 0, time.UTC)),
    27  	}.WithOrder(models.Desc).WithLimit(50000).WithAdjusted(true)
    28  
    29  	// make request
    30  	iter := c.ListAggs(context.Background(), params)
    31  
    32  	// do something with the result
    33  	for iter.Next() {
    34  		log.Print(iter.Item())
    35  	}
    36  	if iter.Err() != nil {
    37  		log.Fatal(iter.Err())
    38  	}
    39  }