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

     1  // Options - Aggregates (Bars)
     2  // https://polygon.io/docs/options/get_v2_aggs_ticker__optionsticker__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  
    18  	// init client
    19  	c := polygon.New(os.Getenv("POLYGON_API_KEY"))
    20  
    21  	// set params
    22  	params := models.ListAggsParams{
    23  		Ticker:     "O:SPY251219C00650000",
    24  		Multiplier: 1,
    25  		Timespan:   "day",
    26  		From:       models.Millis(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)),
    27  		To:         models.Millis(time.Date(2023, 3, 9, 0, 0, 0, 0, time.UTC)),
    28  	}.WithOrder(models.Desc).WithLimit(50000).WithAdjusted(true)
    29  
    30  	// make request
    31  	iter := c.ListAggs(context.Background(), params)
    32  
    33  	// do something with the result
    34  	for iter.Next() {
    35  		log.Print(iter.Item())
    36  	}
    37  	if iter.Err() != nil {
    38  		log.Fatal(iter.Err())
    39  	}
    40  
    41  }