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

     1  // Indices - Snapshot
     2  // https://polygon.io/docs/indices/get_v3_snapshot_indices
     3  // https://github.com/polygon-io/client-go/blob/master/rest/snapshot.go
     4  package main
     5  
     6  import (
     7  	"context"
     8  	"log"
     9  	"os"
    10  	"strings"
    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  	// define tickers
    21  	tickers := []string{"I:SPX", "I:DJI"}
    22  	tickerAnyOf := strings.Join(tickers, ",")
    23  
    24  	// set params
    25  	params := &models.GetIndicesSnapshotParams{
    26  		TickerAnyOf: &tickerAnyOf,
    27  	}
    28  
    29  	// make request
    30  	res, err := c.GetIndicesSnapshot(context.Background(), params)
    31  	if err != nil {
    32  		log.Fatal(err)
    33  	}
    34  
    35  	// do something with the result
    36  	log.Print(res)
    37  }