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

     1  // Package polygon defines a REST client for the Polygon API.
     2  package polygon
     3  
     4  import (
     5  	"net/http"
     6  
     7  	"github.com/polygon-io/client-go/rest/client"
     8  )
     9  
    10  // Client defines a client to the Polygon REST API.
    11  type Client struct {
    12  	client.Client
    13  	AggsClient
    14  	QuotesClient
    15  	ReferenceClient
    16  	TradesClient
    17  	SnapshotClient
    18  	IndicatorsClient
    19  	SummariesClient
    20  	VX VXClient
    21  }
    22  
    23  // New creates a client for the Polygon REST API.
    24  func New(apiKey string) *Client {
    25  	return newClient(apiKey, nil)
    26  }
    27  
    28  // NewWithClient creates a client for the Polygon REST API using a custom HTTP client.
    29  func NewWithClient(apiKey string, hc *http.Client) *Client {
    30  	return newClient(apiKey, hc)
    31  }
    32  
    33  func newClient(apiKey string, hc *http.Client) *Client {
    34  	var c client.Client
    35  	if hc == nil {
    36  		c = client.New(apiKey)
    37  	} else {
    38  		c = client.NewWithClient(apiKey, hc)
    39  	}
    40  
    41  	return &Client{
    42  		Client:           c,
    43  		IndicatorsClient: IndicatorsClient{Client: c},
    44  		SummariesClient:  SummariesClient{Client: c},
    45  		AggsClient:       AggsClient{Client: c},
    46  		QuotesClient:     QuotesClient{Client: c},
    47  		ReferenceClient:  ReferenceClient{Client: c},
    48  		TradesClient:     TradesClient{Client: c},
    49  		SnapshotClient:   SnapshotClient{Client: c},
    50  		VX:               VXClient{Client: c},
    51  	}
    52  }