coingecko

package module
v0.0.0-...-8d2bd39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 10 Imported by: 0

README

polygon

Go library for accessing the Coingecko API

Installation

$ go get github.com/woodstock-tokyo/coingecko

Supported API (more to be added, PR welcomed)

Contact

min@woodstock.club

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client models a client to consume the Polygon Cloud API.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient creates a client with the given authorization token.

func (Client) CoinList

func (c Client) CoinList(ctx context.Context, opt *CoinListOption) (CoinList, error)

MarketChart List all supported coin id, name and symbol

func (Client) Coins

func (c Client) Coins(ctx context.Context, id string, opt *CoinsOption) (Coins, error)

Coins get current data (name, price, market, ... including exchange tickers) for a coin

func (*Client) FetchURLToJSON

func (c *Client) FetchURLToJSON(ctx context.Context, u *url.URL, v interface{}) error

Fetches JSON content from the given URL and unmarshals it into `v`.

func (*Client) GetBytes

func (c *Client) GetBytes(ctx context.Context, endpoint string) ([]byte, error)

GetBytes gets the data from the given endpoint.

func (*Client) GetFloat64

func (c *Client) GetFloat64(ctx context.Context, endpoint string) (float64, error)

GetFloat64 gets the number from the given endpoint.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, endpoint string, v interface{}) error

GetJSON gets the JSON data from the given endpoint.

func (*Client) GetJSONWithQueryParams

func (c *Client) GetJSONWithQueryParams(ctx context.Context, endpoint string, queryParams map[string]string, v interface{}) error

GetJSONWithQueryParams gets the JSON data from the given endpoint with the query parameters attached.

func (*Client) GetJSONWithoutToken

func (c *Client) GetJSONWithoutToken(ctx context.Context, endpoint string, v interface{}) error

GetJSONWithoutToken gets the JSON data from the given endpoint without adding a token to the URL.

func (Client) MarketChart

func (c Client) MarketChart(ctx context.Context, id string, opt *MarketChartOption) (MarketChart, error)

MarketChart Get historical market data include price, market cap, and 24h volume (granularity auto)

type ClientOption

type ClientOption func(*Client)

ClientOption applies an option to the client.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the baseURL for a new IEX Client

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets the http.Client for a new IEX Client

func WithSecureHTTPClient

func WithSecureHTTPClient() ClientOption

WithSecureHTTPClient sets a secure http.Client for a new IEX Client

type CoinList

type CoinList []struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Symbol string `json:"symbol"`
}

CoinList coin list response

type CoinListOption

type CoinListOption struct {
	IncludePlatform bool `url:"include_platform,omitempty"`
}

CoinListOption coin list option

type Coins

type Coins struct {
	Symbol      string `json:"symbol"`
	Name        string `json:"name"`
	Description struct {
		English  string `json:"en"`
		Japanese string `json:"ja"`
	} `json:"description,omitempty"`
	Links struct {
		HomePage []string `json:"homepage"`
	} `json:"links"`
	Image struct {
		Large string `json:"large"`
	} `json:"image"`
	MarketCapRank uint64 `json:"market_cap_rank"`
	MarketData    struct {
		TotalSupply       float64 `json:"total_supply"`
		MaxSupply         float64 `json:"max_supply"`
		CirculatingSupply float64 `json:"circulating_supply"`
	} `json:"market_data"`
}

Coins coins response

type CoinsOption

type CoinsOption struct {
	IncludeLocalizedLang bool `url:"localization,omitempty"`
	IncludeTickersData   bool `url:"tickers,omitempty"`
	IncludeMarketData    bool `url:"market_data,omitempty"`
	IncludeCommunityData bool `url:"community_data,omitempty"`
	IncludeDeveloperData bool `url:"developer_data,omitempty"`
	IncludeSparklineData bool `url:"sparkline,omitempty"`
}

CoinsOption option for fetching coins

type Currency

type Currency string

Currency curreny

const EUR Currency = "eur"
const JPY Currency = "jpy"
const USD Currency = "usd"

to be added

type Error

type Error struct {
	ErrorMessage string `json:"error"`
}

Error represents an Polygon API error

func (Error) Error

func (e Error) Error() string

Error implements the error interface

type Interval

type Interval string

Interval used for market chart (only daily supported)

const Daily Interval = "daily"

type MarketChart

type MarketChart struct {
	MarketCaps   [][]float64 `json:"market_caps"`
	TotalVolumes [][]float64 `json:"total_volumes"`
}

MarketChart market chart response

type MarketChartOption

type MarketChartOption struct {
	TargetCurrency Currency `url:"vs_currency"`
	Days           int      `url:"days"`
	Interval       Interval `url:"interval,omitempty"`
}

MarketChartOption market chart option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL