coinmarketcap

package
v0.0.0-...-eb07c7e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package coinmarketcap connects to a suite of high-performance RESTful JSON endpoints that are specifically designed to meet the mission-critical demands of application developers, data scientists, and enterprise business platforms. Please see https://coinmarketcap.com/api/documentation/v1/# for API documentation

Index

Constants

View Source
const (
	Basic uint8 = 1 << iota
	Hobbyist
	Startup
	Standard
	Professional
	Enterprise
)

Coinmarketcap account plan bitmasks, url and enpoint consts

Variables

This section is empty.

Functions

This section is empty.

Types

type Coinmarketcap

type Coinmarketcap struct {
	Verbose    bool
	Enabled    bool
	Name       string
	APIkey     string
	APIUrl     string
	APIVersion string
	Plan       uint8
	Requester  *request.Requester
}

Coinmarketcap is the overarching type across this package

func (*Coinmarketcap) CheckAccountPlan

func (c *Coinmarketcap) CheckAccountPlan(minAllowable uint8) error

CheckAccountPlan checks your current account plan to the minimal account needed to send http request, this is used to minimize requests for lower account privileges

func (*Coinmarketcap) GetCryptocurrencyHistoricalListings

func (c *Coinmarketcap) GetCryptocurrencyHistoricalListings() ([]CryptocurrencyHistoricalListings, error)

GetCryptocurrencyHistoricalListings returns a paginated list of all cryptocurrencies with market data for a given historical time.

func (*Coinmarketcap) GetCryptocurrencyHistoricalQuotes

func (c *Coinmarketcap) GetCryptocurrencyHistoricalQuotes(currencyID int64, tStart, tEnd time.Time) (CryptocurrencyHistoricalQuotes, error)

GetCryptocurrencyHistoricalQuotes returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.

currencyID - refers to the coinmarketcap currency id tStart - refers to the start time of historic value tEnd - refers to the end of the time block if zero will default to time.Now()

func (*Coinmarketcap) GetCryptocurrencyIDMap

func (c *Coinmarketcap) GetCryptocurrencyIDMap() ([]CryptoCurrencyMap, error)

GetCryptocurrencyIDMap returns a paginated list of all cryptocurrencies by CoinMarketCap ID.

func (*Coinmarketcap) GetCryptocurrencyInfo

func (c *Coinmarketcap) GetCryptocurrencyInfo(currencyID ...int64) (CryptoCurrencyInfo, error)

GetCryptocurrencyInfo returns all static metadata for one or more cryptocurrencies including name, symbol, logo, and its various registered URLs

currencyID = digit code generated by coinmarketcap

func (*Coinmarketcap) GetCryptocurrencyLatestListing

func (c *Coinmarketcap) GetCryptocurrencyLatestListing(start, limit int64) ([]CryptocurrencyLatestListings, error)

GetCryptocurrencyLatestListing returns a paginated list of all cryptocurrencies with latest market data.

Start - optionally offsets the paginated items limit - optionally sets return limit on items [1..5000]

func (*Coinmarketcap) GetCryptocurrencyLatestMarketPairs

func (c *Coinmarketcap) GetCryptocurrencyLatestMarketPairs(currencyID, start, limit int64) (CryptocurrencyLatestMarketPairs, error)

GetCryptocurrencyLatestMarketPairs returns all market pairs across all exchanges for the specified cryptocurrency with associated stats.

currencyID - refers to the coinmarketcap currency id Start - optionally offsets the paginated items limit - optionally sets return limit on items [1..5000]

func (*Coinmarketcap) GetCryptocurrencyLatestQuotes

func (c *Coinmarketcap) GetCryptocurrencyLatestQuotes(currencyID ...int64) (CryptocurrencyLatestQuotes, error)

GetCryptocurrencyLatestQuotes returns the latest market quote for 1 or more cryptocurrencies.

currencyID - refers to the coinmarketcap currency id

func (*Coinmarketcap) GetCryptocurrencyOHLCHistorical

func (c *Coinmarketcap) GetCryptocurrencyOHLCHistorical(currencyID int64, tStart, tEnd time.Time) (CryptocurrencyOHLCHistorical, error)

GetCryptocurrencyOHLCHistorical return an interval of historic OHLCV (Open, High, Low, Close, Volume) market quotes for a cryptocurrency. Currently daily and hourly OHLCV periods are supported.

currencyID - refers to the coinmarketcap currency id tStart - refers to the start time of historic value tEnd - refers to the end of the time block if zero will default to time.Now()

func (*Coinmarketcap) GetCryptocurrencyOHLCLatest

func (c *Coinmarketcap) GetCryptocurrencyOHLCLatest(currencyID int64) (CryptocurrencyOHLCLatest, error)

GetCryptocurrencyOHLCLatest return the latest OHLCV (Open, High, Low, Close, Volume) market values for one or more cryptocurrencies in the currently UTC day. Since the current UTC day is still active these values are updated frequently. You can find the final calculated OHLCV values for the last completed UTC day along with all historic days using /cryptocurrency/ohlcv/historical.

currencyID - refers to the coinmarketcap currency id

func (*Coinmarketcap) GetExchangeHistoricalListings

func (c *Coinmarketcap) GetExchangeHistoricalListings() ([]ExchangeHistoricalListings, error)

GetExchangeHistoricalListings returns a paginated list of all cryptocurrency exchanges with historical market data for a given point in time.

func (*Coinmarketcap) GetExchangeHistoricalQuotes

func (c *Coinmarketcap) GetExchangeHistoricalQuotes(exchangeID int64, tStart, tEnd time.Time) (ExchangeHistoricalQuotes, error)

GetExchangeHistoricalQuotes returns an interval of historic quotes for any exchange based on time and interval parameters.

exchangeID - refers to coinmarketcap exchange id tStart - refers to the start time of historic value tEnd - refers to the end of the time block if zero will default to time.Now()

func (*Coinmarketcap) GetExchangeInfo

func (c *Coinmarketcap) GetExchangeInfo(exchangeID ...int64) (ExchangeInfo, error)

GetExchangeInfo returns all static metadata for one or more exchanges including logo and homepage URL.

exchangeID - refers to coinmarketcap exchange id

func (*Coinmarketcap) GetExchangeLatestListings

func (c *Coinmarketcap) GetExchangeLatestListings() ([]ExchangeLatestListings, error)

GetExchangeLatestListings returns a paginated list of all cryptocurrency exchanges with historical market data for a given point in time.

func (*Coinmarketcap) GetExchangeLatestMarketPairs

func (c *Coinmarketcap) GetExchangeLatestMarketPairs(exchangeID, start, limit int64) (ExchangeLatestMarketPairs, error)

GetExchangeLatestMarketPairs returns a list of active market pairs for an exchange. Active means the market pair is open for trading.

exchangeID - refers to coinmarketcap exchange id Start - optionally offsets the paginated items limit - optionally sets return limit on items [1..5000]

func (*Coinmarketcap) GetExchangeLatestQuotes

func (c *Coinmarketcap) GetExchangeLatestQuotes(exchangeID ...int64) (ExchangeLatestQuotes, error)

GetExchangeLatestQuotes returns the latest aggregate market data for 1 or more exchanges.

exchangeID - refers to coinmarketcap exchange id

func (*Coinmarketcap) GetExchangeMap

func (c *Coinmarketcap) GetExchangeMap(start, limit int64) ([]ExchangeMap, error)

GetExchangeMap returns a paginated list of all cryptocurrency exchanges by CoinMarketCap ID. Recommend using this convenience endpoint to lookup and utilize the unique exchange id across all endpoints as typical exchange identifiers may change over time. ie huobi -> hadax -> global -> who knows what else

Start - optionally offsets the paginated items limit - optionally sets return limit on items [1..5000]

func (*Coinmarketcap) GetGlobalMeticHistoricalQuotes

func (c *Coinmarketcap) GetGlobalMeticHistoricalQuotes(tStart, tEnd time.Time) (GlobalMeticHistoricalQuotes, error)

GetGlobalMeticHistoricalQuotes returns an interval of aggregate 24 hour volume and market cap data globally based on time and interval parameters.

tStart - refers to the start time of historic value tEnd - refers to the end of the time block if zero will default to time.Now()

func (*Coinmarketcap) GetGlobalMeticLatestQuotes

func (c *Coinmarketcap) GetGlobalMeticLatestQuotes() (GlobalMeticLatestQuotes, error)

GetGlobalMeticLatestQuotes returns the latest quote of aggregate market metrics.

func (*Coinmarketcap) GetPriceConversion

func (c *Coinmarketcap) GetPriceConversion(amount float64, currencyID int64, atHistoricTime time.Time) (PriceConversion, error)

GetPriceConversion converts an amount of one currency into multiple cryptocurrencies or fiat currencies at the same time using the latest market averages. Optionally pass a historical timestamp to convert values based on historic averages.

amount - An amount of currency to convert. Example: 10.43 currencyID - refers to the coinmarketcap currency id atHistoricTime - [Optional] timestamp to reference historical pricing during conversion.

func (*Coinmarketcap) SendHTTPRequest

func (c *Coinmarketcap) SendHTTPRequest(method, endpoint string, v url.Values, result interface{}) error

SendHTTPRequest sends a valid HTTP request

func (*Coinmarketcap) SetAccountPlan

func (c *Coinmarketcap) SetAccountPlan(s string) error

SetAccountPlan sets account plan

func (*Coinmarketcap) SetDefaults

func (c *Coinmarketcap) SetDefaults()

SetDefaults sets default values for the exchange

func (*Coinmarketcap) Setup

func (c *Coinmarketcap) Setup(conf Settings)

Setup sets user configuration

type CryptoCurrencyInfo

type CryptoCurrencyInfo map[string]struct {
	ID       int         `json:"id"`
	Name     string      `json:"name"`
	Symbol   string      `json:"symbol"`
	Category string      `json:"category"`
	Slug     string      `json:"slug"`
	Logo     string      `json:"logo"`
	Tags     []string    `json:"tags"`
	Platform interface{} `json:"platform"`
	Urls     struct {
		Website      []string      `json:"website"`
		Explorer     []string      `json:"explorer"`
		SourceCode   []string      `json:"source_code"`
		MessageBoard []string      `json:"message_board"`
		Chat         []interface{} `json:"chat"`
		Announcement []interface{} `json:"announcement"`
		Reddit       []string      `json:"reddit"`
		Twitter      []string      `json:"twitter"`
	} `json:"urls"`
}

CryptoCurrencyInfo defines cryptocurrency information

type CryptoCurrencyMap

type CryptoCurrencyMap struct {
	ID                  int       `json:"id"`
	Name                string    `json:"name"`
	Symbol              string    `json:"symbol"`
	Slug                string    `json:"slug"`
	IsActive            int       `json:"is_active"`
	FirstHistoricalData time.Time `json:"first_historical_data"`
	LastHistoricalData  time.Time `json:"last_historical_data"`
	Platform            struct {
		ID           int    `json:"id"`
		Name         string `json:"name"`
		Symbol       string `json:"symbol"`
		Slug         string `json:"slug"`
		TokenAddress string `json:"token_address"`
	} `json:"platform"`
}

CryptoCurrencyMap defines a cryptocurrency struct

type CryptocurrencyHistoricalListings

type CryptocurrencyHistoricalListings struct {
	ID                int       `json:"id"`
	Name              string    `json:"name"`
	Symbol            string    `json:"symbol"`
	Slug              string    `json:"slug"`
	CmcRank           int       `json:"cmc_rank"`
	NumMarketPairs    int       `json:"num_market_pairs"`
	CirculatingSupply float64   `json:"circulating_supply"`
	TotalSupply       float64   `json:"total_supply"`
	MaxSupply         float64   `json:"max_supply"`
	LastUpdated       time.Time `json:"last_updated"`
	Quote             struct {
		USD Currency `json:"USD"`
		BTC Currency `json:"BTC"`
	} `json:"quote"`
}

CryptocurrencyHistoricalListings defines a historical listing data

type CryptocurrencyHistoricalQuotes

type CryptocurrencyHistoricalQuotes struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Symbol string `json:"symbol"`
	Quotes []struct {
		Timestamp time.Time `json:"timestamp"`
		Quote     struct {
			USD Currency `json:"USD"`
		} `json:"quote"`
	} `json:"quotes"`
}

CryptocurrencyHistoricalQuotes defines historical cryptocurrency quotation data

type CryptocurrencyLatestListings

type CryptocurrencyLatestListings struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Symbol            string      `json:"symbol"`
	Slug              string      `json:"slug"`
	CmcRank           int         `json:"cmc_rank"`
	NumMarketPairs    int         `json:"num_market_pairs"`
	CirculatingSupply float64     `json:"circulating_supply"`
	TotalSupply       float64     `json:"total_supply"`
	MaxSupply         float64     `json:"max_supply"`
	LastUpdated       time.Time   `json:"last_updated"`
	DateAdded         time.Time   `json:"date_added"`
	Tags              []string    `json:"tags"`
	Platform          interface{} `json:"platform"`
	Quote             struct {
		USD Currency `json:"USD"`
		BTC Currency `json:"BTC"`
	} `json:"quote"`
}

CryptocurrencyLatestListings defines latest cryptocurrency listing data

type CryptocurrencyLatestMarketPairs

type CryptocurrencyLatestMarketPairs struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	Symbol         string `json:"symbol"`
	NumMarketPairs int    `json:"num_market_pairs"`
	MarketPairs    []struct {
		Exchange struct {
			ID   int    `json:"id"`
			Name string `json:"name"`
			Slug string `json:"slug"`
		} `json:"exchange"`
		MarketPair     string `json:"market_pair"`
		MarketPairBase struct {
			CurrencyID     int    `json:"currency_id"`
			CurrencySymbol string `json:"currency_symbol"`
			CurrencyType   string `json:"currency_type"`
		} `json:"market_pair_base"`
		MarketPairQuote struct {
			CurrencyID     int    `json:"currency_id"`
			CurrencySymbol string `json:"currency_symbol"`
			CurrencyType   string `json:"currency_type"`
		} `json:"market_pair_quote"`
		Quote struct {
			ExchangeReported struct {
				Price          float64   `json:"price"`
				Volume24HBase  float64   `json:"volume_24h_base"`
				Volume24HQuote float64   `json:"volume_24h_quote"`
				LastUpdated    time.Time `json:"last_updated"`
			} `json:"exchange_reported"`
			USD Currency `json:"USD"`
		} `json:"quote"`
	} `json:"market_pairs"`
}

CryptocurrencyLatestMarketPairs defines the latest cryptocurrency pairs

type CryptocurrencyLatestQuotes

type CryptocurrencyLatestQuotes map[string]struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Symbol            string      `json:"symbol"`
	Slug              string      `json:"slug"`
	CirculatingSupply float64     `json:"circulating_supply"`
	TotalSupply       float64     `json:"total_supply"`
	MaxSupply         float64     `json:"max_supply"`
	DateAdded         time.Time   `json:"date_added"`
	NumMarketPairs    int         `json:"num_market_pairs"`
	CmcRank           int         `json:"cmc_rank"`
	LastUpdated       time.Time   `json:"last_updated"`
	Tags              []string    `json:"tags"`
	Platform          interface{} `json:"platform"`
	Quote             struct {
		USD Currency `json:"USD"`
	} `json:"quote"`
}

CryptocurrencyLatestQuotes defines latest cryptocurrency quotation data

type CryptocurrencyOHLCHistorical

type CryptocurrencyOHLCHistorical struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Symbol string `json:"symbol"`
	Quotes []struct {
		TimeOpen  time.Time `json:"time_open"`
		TimeClose time.Time `json:"time_close"`
		Quote     struct {
			USD OHLC `json:"USD"`
		} `json:"quote"`
	} `json:"quotes"`
}

CryptocurrencyOHLCHistorical defines open high low close historical data

type CryptocurrencyOHLCLatest

type CryptocurrencyOHLCLatest map[string]struct {
	ID          int         `json:"id"`
	Name        string      `json:"name"`
	Symbol      string      `json:"symbol"`
	LastUpdated time.Time   `json:"last_updated"`
	TimeOpen    time.Time   `json:"time_open"`
	TimeClose   interface{} `json:"time_close"`
	Quote       struct {
		USD OHLC `json:"USD"`
	} `json:"quote"`
}

CryptocurrencyOHLCLatest defines open high low close latest data

type Currency

type Currency struct {
	Price                  float64   `json:"price"`
	Volume24H              float64   `json:"volume_24h"`
	Volume24HAdjusted      float64   `json:"volume_24h_adjusted"`
	Volume7D               float64   `json:"volume_7d"`
	Volume30D              float64   `json:"volume_30d"`
	PercentChange1H        float64   `json:"percent_change_1h"`
	PercentChangeVolume24H float64   `json:"percent_change_volume_24h"`
	PercentChangeVolume7D  float64   `json:"percent_change_volume_7d"`
	PercentChangeVolume30D float64   `json:"percent_change_volume_30d"`
	MarketCap              float64   `json:"market_cap"`
	TotalMarketCap         float64   `json:"total_market_cap"`
	LastUpdated            time.Time `json:"last_updated"`
}

Currency defines a generic sub type to capture currency data

type ExchangeHistoricalListings

type ExchangeHistoricalListings struct {
	ID             int       `json:"id"`
	Name           string    `json:"name"`
	Slug           string    `json:"slug"`
	CmcRank        int       `json:"cmc_rank"`
	NumMarketPairs int       `json:"num_market_pairs"`
	Timestamp      time.Time `json:"timestamp"`
	Quote          struct {
		USD Currency `json:"USD"`
	} `json:"quote"`
}

ExchangeHistoricalListings defines historical exchange listings

type ExchangeHistoricalQuotes

type ExchangeHistoricalQuotes struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Slug   string `json:"slug"`
	Quotes []struct {
		Timestamp time.Time `json:"timestamp"`
		Quote     struct {
			USD Currency `json:"USD"`
		} `json:"quote"`
		NumMarketPairs int `json:"num_market_pairs"`
	} `json:"quotes"`
}

ExchangeHistoricalQuotes defines historical exchange quotations

type ExchangeInfo

type ExchangeInfo map[string]struct {
	Urls struct {
		Website []string      `json:"website"`
		Twitter []string      `json:"twitter"`
		Blog    []interface{} `json:"blog"`
		Chat    []string      `json:"chat"`
		Fee     []string      `json:"fee"`
	} `json:"urls"`
	Logo string `json:"logo"`
	ID   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

ExchangeInfo defines exchange information

type ExchangeLatestListings

type ExchangeLatestListings struct {
	ID             int       `json:"id"`
	Name           string    `json:"name"`
	Slug           string    `json:"slug"`
	NumMarketPairs int       `json:"num_market_pairs"`
	LastUpdated    time.Time `json:"last_updated"`
	Quote          struct {
		USD Currency `json:"USD"`
	} `json:"quote"`
}

ExchangeLatestListings defines latest exchange listings

type ExchangeLatestMarketPairs

type ExchangeLatestMarketPairs struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	Slug           string `json:"slug"`
	NumMarketPairs int    `json:"num_market_pairs"`
	MarketPairs    []struct {
		MarketPair     string `json:"market_pair"`
		MarketPairBase struct {
			CurrencyID     int    `json:"currency_id"`
			CurrencySymbol string `json:"currency_symbol"`
			CurrencyType   string `json:"currency_type"`
		} `json:"market_pair_base"`
		MarketPairQuote struct {
			CurrencyID     int    `json:"currency_id"`
			CurrencySymbol string `json:"currency_symbol"`
			CurrencyType   string `json:"currency_type"`
		} `json:"market_pair_quote"`
		Quote struct {
			ExchangeReported struct {
				Price          float64   `json:"price"`
				Volume24HBase  float64   `json:"volume_24h_base"`
				Volume24HQuote float64   `json:"volume_24h_quote"`
				LastUpdated    time.Time `json:"last_updated"`
			} `json:"exchange_reported"`
			USD Currency `json:"USD"`
		} `json:"quote"`
	} `json:"market_pairs"`
}

ExchangeLatestMarketPairs defines latest market pairs

type ExchangeLatestQuotes

type ExchangeLatestQuotes struct {
	Binance struct {
		ID             int       `json:"id"`
		Name           string    `json:"name"`
		Slug           string    `json:"slug"`
		NumMarketPairs int       `json:"num_market_pairs"`
		LastUpdated    time.Time `json:"last_updated"`
		Quote          struct {
			USD Currency `json:"USD"`
		} `json:"quote"`
	} `json:"binance"`
}

ExchangeLatestQuotes defines latest exchange quotations

type ExchangeMap

type ExchangeMap struct {
	ID                  int       `json:"id"`
	Name                string    `json:"name"`
	Slug                string    `json:"slug"`
	IsActive            int       `json:"is_active"`
	FirstHistoricalData time.Time `json:"first_historical_data"`
	LastHistoricalData  time.Time `json:"last_historical_data"`
}

ExchangeMap defines a data for an exchange

type GlobalMeticHistoricalQuotes

type GlobalMeticHistoricalQuotes struct {
	Quotes []struct {
		Timestamp    time.Time `json:"timestamp"`
		BtcDominance float64   `json:"btc_dominance"`
		Quote        struct {
			USD Currency `json:"USD"`
		} `json:"quote"`
	} `json:"quotes"`
}

GlobalMeticHistoricalQuotes defines historical global metric quotations

type GlobalMeticLatestQuotes

type GlobalMeticLatestQuotes struct {
	BtcDominance           float64   `json:"btc_dominance"`
	EthDominance           float64   `json:"eth_dominance"`
	ActiveCryptocurrencies int       `json:"active_cryptocurrencies"`
	ActiveMarketPairs      int       `json:"active_market_pairs"`
	ActiveExchanges        int       `json:"active_exchanges"`
	LastUpdated            time.Time `json:"last_updated"`
	Quote                  struct {
		USD Currency `json:"USD"`
	} `json:"quote"`
}

GlobalMeticLatestQuotes defines latest global metric quotations

type OHLC

type OHLC struct {
	Open      float64   `json:"open"`
	High      float64   `json:"high"`
	Low       float64   `json:"low"`
	Close     float64   `json:"close"`
	Volume    float64   `json:"volume"`
	Timestamp time.Time `json:"timestamp"`
}

OHLC defines a generic sub type for OHLC currency data

type PriceConversion

type PriceConversion struct {
	Symbol      string    `json:"symbol"`
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Amount      float64   `json:"amount"`
	LastUpdated time.Time `json:"last_updated"`
	Quote       struct {
		GBP Currency `json:"GBP"`
		LTC Currency `json:"LTC"`
		USD Currency `json:"USD"`
	} `json:"quote"`
}

PriceConversion defines price conversion data

type Settings

type Settings struct {
	Name        string `json:"name"`
	Enabled     bool   `json:"enabled"`
	Verbose     bool   `json:"verbose"`
	APIkey      string `json:"apiKey"`
	AccountPlan string `json:"accountPlan"`
}

Settings defines the current settings from configuration file

type Status

type Status struct {
	Timestamp    string `json:"timestamp"`
	ErrorCode    int64  `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Elapsed      int64  `json:"elapsed"`
	CreditCount  int64  `json:"credit_count"`
}

Status defines a response status JSON struct that is received with every HTTP request

Jump to

Keyboard shortcuts

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