utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 9 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

This section is empty.

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"`
}

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

func GetCryptoPriceCache

func GetCryptoPriceCache(client *redis.Client, ctx context.Context, ticker string) (GeckoPriceResults, error)

GetCryptoPriceCache attempt to use cache to get info

type MarketData

type MarketData struct {
	CurrentPrice       CurrentPrice `json:"current_price"`
	PriceChange        float64      `json:"price_change_24h"`
	PriceChangePercent float64      `json:"price_change_percentage_24h"`
}

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"`
	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"`
}

Jump to

Keyboard shortcuts

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