api

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAssets

func GetAssets(ctx context.Context, dataChannel chan AssetData, sendData *bool) error

GetAssets serves data about top 100 coins for the main page

func GetCoinDetails

func GetCoinDetails(ctx context.Context, id string, dataChannel chan CoinData) error

GetCoinDetails fetches details for a coin specified by id and sends the data on dataChannel

func GetCoinHistory

func GetCoinHistory(ctx context.Context, id string, intervalChannel chan string, dataChannel chan CoinData) error

GetCoinHistory gets price history of a coin specified by id, for an interval received through the interval channel. The default interval is set as 24 Hours

func GetFavouritePrices

func GetFavouritePrices(ctx context.Context, favourites map[string]bool, dataChannel chan CoinData) error

GetFavouritePrices gets coin prices for coins specified by favourites. This data is returned on the dataChannel.

func GetLivePrice

func GetLivePrice(ctx context.Context, id string, dataChannel chan string) error

GetLivePrice uses a websocket to stream realtime prices of a coin specified by id. The prices are sent on the dataChannel

func GetPercentageChangeForDuration

func GetPercentageChangeForDuration(coinData geckoTypes.CoinsMarketItem, duration string) float64

GetPercentageChangeForDuration returns price change percentage given a CoinsMarketItem and a duration, If the specified duration does not exist, 24 Hour change percent is returned

Types

type AssetData

type AssetData struct {
	TopCoinData [][]float64
	MaxPrices   []float64
	MinPrices   []float64
	TopCoins    []string
	AllCoinData geckoTypes.CoinsMarket
}

AssetData is used to hold details of multiple coins and the price history of top ranked coins along with their names

type CoinCapAsset

type CoinCapAsset struct {
	ID                string `json:"id"`
	Rank              string `json:"rank"`
	Symbol            string `json:"symbol"`
	Name              string `json:"name"`
	Supply            string `json:"supply"`
	MaxSupply         string `json:"maxSupply"`
	MarketCapUsd      string `json:"marketCapUsd"`
	VolumeUsd24Hr     string `json:"volumeUsd24Hr"`
	PriceUsd          string `json:"priceUsd"`
	ChangePercent24Hr string `json:"changePercent24Hr"`
	Vwap24Hr          string `json:"vwap24Hr"`
	Explorer          string `json:"explorer"`
}

CoinCapAsset is used to marshal asset data from coinCap APIs

type CoinCapData

type CoinCapData struct {
	Data      []CoinCapAsset `json:"data"`
	Timestamp uint           `json:"timestamp"`
}

CoinCapData is used to marshall multiple assets from CoinCap APIs

type CoinData

type CoinData struct {
	Type         string
	PriceHistory []float64
	MinPrice     float64
	MaxPrice     float64
	Details      CoinDetails
	Favourites   map[string]float64
}

CoinData Holds data pertaining to a single coin. This is used to serve per coin details. It additionally holds a map of favourite coins.

type CoinDetails

type CoinDetails struct {
	Name           string
	Symbol         string
	Rank           string
	BlockTime      string
	MarketCap      float64
	Website        string
	Explorers      [][]string
	ATH            float64
	ATHDate        string
	ATL            float64
	ATLDate        string
	High24         float64
	Low24          float64
	TotalVolume    float64
	ChangePercents [][]string
	TotalSupply    float64
	CurrentSupply  float64
	LastUpdate     string
}

CoinDetails holds information about a coin

type CoinID

type CoinID struct {
	CoinGeckoID string
	CoinCapID   string
}

CoinID holds the ID of a coin as stored in CoinGecko and CoinCap

type CoinIDMap

type CoinIDMap map[string]CoinID

CoinIDMap maps a symbol to it's respective ID

func NewCoinIDMap

func NewCoinIDMap() CoinIDMap

NewCoinIDMap returns an instance of CoinIDMap

func (CoinIDMap) Populate

func (c CoinIDMap) Populate()

Populate updates values into the CoinIDMap

Jump to

Keyboard shortcuts

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