utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeckoURL = "https://api.coingecko.com/api/v3/coins/%s"
)
View Source
const (
	YahooURL = "https://query1.finance.yahoo.com/v10/finance/quoteSummary/%s?modules=price"
)

Variables

This section is empty.

Functions

func FormatAmount

func FormatAmount(amount float64) string

Types

type Change

type Change struct {
	Raw     float64 `json:"raw"`
	Fmt     string  `json:"fmt"`
	LongFmt string  `json:"longFmt,omitempty"`
}

type CurrentPrice

type CurrentPrice struct {
	USD float64 `json:"usd"`
	BTC float64 `json:"btc"`
}

type GeckoPriceResults

type GeckoPriceResults struct {
	ID         string     `json:"id"`
	Symbol     string     `json:"symbol"`
	Name       string     `json:"name"`
	MarketData MarketData `json:"market_data"`
}

The following is the API response gecko gives

func GetCryptoPrice

func GetCryptoPrice(ticker string) (GeckoPriceResults, error)

GetCryptoPrice retrieves the price of a given ticker using the coin gecko API

type MarketData

type MarketData struct {
	CurrentPrice            CurrentPrice     `json:"current_price"`
	MarketCap               CurrentPrice     `json:"market_cap"`
	TotalValueLocked        TotalValueLocked `json:"total_value_locked"`
	PriceChangePercent      float64          `json:"price_change_percentage_24h"`
	PriceChangeCurrency     CurrentPrice     `json:"price_change_24h_in_currency"`
	MarketCapChangePercent  float64          `json:"market_cap_change_percentage_24h"`
	MarketCapChangeCurrency CurrentPrice     `json:"market_cap_change_24h_in_currency"`
	TotalSupply             float64          `json:"total_supply"`
	CirculatingSupply       float64          `json:"circulating_supply"`
}

type PriceResults

type PriceResults struct {
	QuoteSummary Results `json:"quoteSummary"`
	Error        string  `json:"error"`
}

The following is the API response yahoo gives

func GetStockPrice

func GetStockPrice(ticker string) (PriceResults, error)

GetStockPrice retrieves the price of a given ticker using the yahoo API

type Pricing

type Pricing struct {
	MaxAge                     int    `json:"maxAge"`
	PreMarketChangePercent     Change `json:"preMarketChangePercent"`
	PreMarketChange            Change `json:"preMarketChange"`
	PreMarketPrice             Change `json:"preMarketPrice"`
	PreMarketSource            string `json:"preMarketSource"`
	PostMarketChangePercent    Change `json:"postMarketChangePercent"`
	PostMarketChange           Change `json:"postMarketChange"`
	PostMarketTime             int    `json:"postMarketTime"`
	PostMarketPrice            Change `json:"postMarketPrice"`
	PostMarketSource           string `json:"postMarketSource"`
	RegularMarketChangePercent Change `json:"regularMarketChangePercent"`
	RegularMarketChange        Change `json:"regularMarketChange"`
	RegularMarketTime          int    `json:"regularMarketTime"`
	RegularMarketPrice         Change `json:"regularMarketPrice"`
	RegularMarketSource        string `json:"regularMarketSource"`
	RegularMarketDayHigh       Change `json:"regularMarketDayHigh"`
	RegularMarketDayLow        Change `json:"regularMarketDayLow"`
	RegularMarketVolume        Change `json:"regularMarketVolume"`
	AverageDailyVolume10Day    Change `json:"averageDailyVolume10Day"`
	AverageDailyVolume3Month   Change `json:"averageDailyVolume3Month"`
	RegularMarketPreviousClose Change `json:"regularMarketPreviousClose"`
	RegularMarketOpen          Change `json:"regularMarketOpen"`
	StrikePrice                Change `json:"strikePrice"`
	OpenInterest               Change `json:"openInterest"`
	Exchange                   string `json:"exchange"`
	ExchangeName               string `json:"exchangeName"`
	QuoteType                  string `json:"quoteType"`
	QuoteSourceName            string `json:"quoteSourceName"`
	ExchangeDataDelayedBy      int    `json:"exchangeDataDelayedBy"`
	MarketState                string `json:"marketState"`
	Symbol                     string `json:"symbol"`
	ShortName                  string `json:"shortName"`
	LongName                   string `json:"longName"`
	Currency                   string `json:"currency"`
	CurrencySymbol             string `json:"currencySymbol"`
	PriceHint                  Change `json:"priceHint"`
	Volume24Hr                 Change `json:"volume24Hr"`
	VolumeAllCurrencies        Change `json:"volumeAllCurrencies"`
	CirculatingSupply          Change `json:"circulatingSupply"`
	MarketCap                  Change `json:"marketCap"`
}

type Result

type Result struct {
	Price Pricing `json:"price"`
}

type Results

type Results struct {
	Results []Result `json:"result"`
}

type TotalValueLocked

type TotalValueLocked struct {
	USD float64 `json:"usd"`
	BTC float64 `json:"btc"`
}

Jump to

Keyboard shortcuts

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