coingecko

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

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 11 Imported by: 0

README

GO-COINGECKO

A curated command line interface to coingecko.

Go programs

Usage: coingecko [-C usd] [-D DATE] [-L DAYS] ...

Fetch cryptocurrency prices from "coingecko.com".

  -l                    : List available cryptocurrencies.
  -p TICKETS...         : Print the price of tickers.
  -f FROM    VALUE...   : Convert to fiat
  -c TO      VALUE...   : Convert to crypto.
  -k FROM-TO VALUE...   : Convert crypto to crypto.
  -g COIN [-D,-L]       : Print price graph.
  -i COIN [-D]          : Print historic price.

Copyright (c) 2023 Harkaitz Agirre, harkaitz.aguirre@gmail.com

Go documentation

package coingecko // import "github.com/harkaitz/go-coingecko"

var Coingecko u.RPC = u.RPC{ ... }
func GetCoinPrice(ticker, currency string) (price float64, err error)
type Coin struct{ ... }
    func GetCoinList() (coins []Coin, err error)
type CoinData struct{ ... }
    func GetCoinData(id CoinID) (data CoinData, err error)
    func GetCoinHistory(id CoinID, day time.Time) (data CoinData, err error)
type CoinGraph struct{ ... }
    func GetCoinGraph(id CoinID, start, end time.Time, currency string) (graph CoinGraph, err error)
type CoinID string
    func GetCoinID(ticker string) (id CoinID, err error)

Collaborating

For making bug reports, feature requests and donations visit one of the following links:

  1. gemini://harkadev.com/oss/
  2. https://harkadev.com/oss/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VerboseRPC bool = os.Getenv("VERBOSE_RPC") != ""

Functions

func GetCoinPrice

func GetCoinPrice(ticker, currency string) (price float64, err error)

func GetFromCache

func GetFromCache(id string, exp int64, out any) (found bool)

func IsError

func IsError(oB []byte) (err error)

func SaveToCache

func SaveToCache(id string, in any)

Types

type Coin

type Coin struct {
	ID     CoinID `json:"id"`
	Symbol string `json:"symbol"`
	Name   string `json:"name"`
}

func GetCoinList

func GetCoinList() (coins []Coin, err error)

type CoinData

type CoinData struct {
	ID                 CoinID `json:"id"`
	Symbol             string `json:"symbol"`
	Name               string `json:"name"`
	BlockTimeInMinutes int    `json:"block_time_in_minutes"`
	Links              struct {
		Homepage []string `json:"homepage"`
	} `json:"links"`
	Image struct {
		Thumb string `json:"thumb"`
		Small string `json:"small"`
		Large string `json:"large"`
	} `json:"image"`
	MarketData struct {
		CurrentPrice map[string]float64 `json:"current_price"`
	} `json:"market_data"`
}

func GetCoinData

func GetCoinData(id CoinID) (data CoinData, err error)

func GetCoinHistory

func GetCoinHistory(id CoinID, day time.Time) (data CoinData, err error)

func (*CoinData) Price

func (d *CoinData) Price(currency string) (price float64, err error)

func (*CoinData) Print

func (d *CoinData) Print()

type CoinGraph

type CoinGraph struct {
	Prices       [][2]float64
	MarketCaps   [][2]float64
	TotalVolumes [][2]float64
}

func GetCoinGraph

func GetCoinGraph(id CoinID, start, end time.Time, currency string) (graph CoinGraph, err error)

func (*CoinGraph) PrintPrices

func (g *CoinGraph) PrintPrices()

type CoinID

type CoinID string

func GetCoinID

func GetCoinID(ticker string) (id CoinID, err error)

type RPC

type RPC struct {
	URL  string
	User string
	Pass string
}
var Coingecko RPC = RPC{
	URL: "https://api.coingecko.com",
}

func (*RPC) RPCQuery

func (c *RPC) RPCQuery(httpPath, httpMethod, rpcMethod string, in any, out any) (err error)

func (*RPC) SimQuery

func (c *RPC) SimQuery(httpPath, httpMethod string, out any) (err error)

type RPCRequest

type RPCRequest struct {
	JsonRPC string      `json:"jsonrpc"`
	ID      string      `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

type RPCResponse

type RPCResponse struct {
	Error struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
	Result interface{} `json:"result"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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