cryptoprice

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 7 Imported by: 1

README

Package cryptoprice

GoDoc Go Report Card Build Status Coverage Status

A simple Client for querying the most accurate price for a given currency pair and time from the CryptoCompare REST API.

See GoDoc for complete documentation.

CLI

The ./cmd directory contains a simple CLI program for querying a price using this package.

Documentation

Overview

Package cryptoprice provides a simple Client for querying the most accurate crypto currency price available from the CryptoCompare REST API.

This is not intended to be a complete implementation of the full CryptoCompare REST API. It just accesses the CryptoCompare REST API endpoints required to get the most accurate price available for a given time.

The CryptoCompare REST API documentation can be found here: https://min-api.cryptocompare.com/

Index

Constants

View Source
const (
	CryptoCompareURL   = "https://min-api.cryptocompare.com/data"
	NowURI             = "/price"
	MinuteURI          = "/histominute"
	HourURI            = "/histohour"
	DefaultExtraParams = "golang pkg - github.com/canonical-ledgers/cryptoprice"
)

Default URIs and parameters

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	URL string

	// Get price of Currency in Units.
	Currency string
	Units    string

	// Only return data for direct trading pairs. Do not perform conversions.
	DirectPairOnly bool

	// Exchange to use for data (default: "CCCAGG" aggregated average)
	Exchange string

	// ExtraParams should be the name of your application, defaults to
	// const DefaultExtraParams
	ExtraParams string

	APIKey string

	http.Client
}

Client stores request parameters and provides methods for querying the CryptoCompare REST API. You may set any additional http.Client settings directly on this type.

func NewClient

func NewClient(currency, units string) *Client

NewClient returns a pointer to a new Client with the given Currency and Units set, as well as the correct CryptoCompare API endpoint URL.

func (*Client) GetPriceAt

func (c *Client) GetPriceAt(t time.Time) (float64, error)

GetPriceAt returns the most accurate price available for the given time t. If the requested time is within the past minute, the most recent price data is used. If the requested time is within the past 7 days, the simple average of the high and low prices for the minute that is closest to the given time is used. If the request time is any further in the past, the simple average of the high and low prices for the hour that is closest to the given price is used.

func (*Client) GetPriceNow

func (c *Client) GetPriceNow() (float64, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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