Documentation ¶
Index ¶
- Constants
- Variables
- func AllDataSourcesList() []string
- func CommodityOpen(reference time.Time) bool
- func CorrectCasing(in string) string
- func ForexOpen(reference time.Time) bool
- func IsMarketOpen(asset string, reference time.Time) bool
- func ParseKitco(line string, kData *KitcoData)
- func PollingExponentialBackOff() *backoff.ExponentialBackOff
- func TruncateTo4(v float64) float64
- func TruncateTo8(v float64) float64
- type APILayerDataSource
- type APILayerError
- type APILayerResponse
- type AlternativeMeDataSource
- func (d *AlternativeMeDataSource) ApiUrl() string
- func (d *AlternativeMeDataSource) AssetMapping() map[string]int
- func (d *AlternativeMeDataSource) CallAlternativeMe() (*AlternativeMeDataSourceResponse, error)
- func (d *AlternativeMeDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *AlternativeMeDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *AlternativeMeDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *AlternativeMeDataSource) Name() string
- func (d *AlternativeMeDataSource) ParseFetchedPrices(data []byte) (*AlternativeMeDataSourceResponse, error)
- func (d *AlternativeMeDataSource) SupportedPegs() []string
- func (d *AlternativeMeDataSource) Url() string
- type AlternativeMeDataSourceMetadata
- type AlternativeMeDataSourceQuote
- type AlternativeMeDataSourceRate
- type AlternativeMeDataSourceResponse
- type CoinCapDataSource
- func (d CoinCapDataSource) CallCoinCap(config *config.Config) (CoinCapResponse, error)
- func (d *CoinCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *CoinCapDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *CoinCapDataSource) Name() string
- func (d *CoinCapDataSource) SupportedPegs() []string
- func (d *CoinCapDataSource) Url() string
- type CoinCapRecord
- type CoinCapResponse
- type CoinGeckoDataSource
- func (d *CoinGeckoDataSource) ApiUrl() string
- func (d *CoinGeckoDataSource) CallCoinGecko() (map[string]CoinGeckoDataSourceResponse, error)
- func (d *CoinGeckoDataSource) CurrencyIDMapping() map[string]string
- func (d *CoinGeckoDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *CoinGeckoDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *CoinGeckoDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *CoinGeckoDataSource) Name() string
- func (d *CoinGeckoDataSource) ParseFetchedPrices(data []byte) (map[string]CoinGeckoDataSourceResponse, error)
- func (d *CoinGeckoDataSource) SupportedPegs() []string
- func (d *CoinGeckoDataSource) Url() string
- type CoinGeckoDataSourceResponse
- type CoinMarketCapCurrency
- type CoinMarketCapDataSource
- func (d *CoinMarketCapDataSource) ApiUrl() string
- func (d *CoinMarketCapDataSource) CallCoinMarketCap() (*CoinMarketCapResponse, error)
- func (d *CoinMarketCapDataSource) CurrencyIDMapping() map[string]int
- func (d *CoinMarketCapDataSource) DateFormat() string
- func (d *CoinMarketCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *CoinMarketCapDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *CoinMarketCapDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *CoinMarketCapDataSource) Name() string
- func (d *CoinMarketCapDataSource) ParseFetchedPrices(data []byte) (*CoinMarketCapResponse, error)
- func (d *CoinMarketCapDataSource) SupportedPegs() []string
- func (d *CoinMarketCapDataSource) Url() string
- type CoinMarketCapQuote
- type CoinMarketCapResponse
- type DataSourceWithPriority
- type DataSources
- func (ds *DataSources) AssetPriorityString(asset string) string
- func (ds *DataSources) PriorityListString() string
- func (d *DataSources) PullAllPEGAssets(oprversion uint8) (pa PegAssets, err error)
- func (d *DataSources) PullBestPrice(asset string, reference time.Time, sources map[string]IDataSource) (pa PegItem, err error)
- type ExchangeRatesAPIResponse
- type ExchangeRatesDataSource
- func (d *ExchangeRatesDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *ExchangeRatesDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *ExchangeRatesDataSource) Name() string
- func (d *ExchangeRatesDataSource) SupportedPegs() []string
- func (d *ExchangeRatesDataSource) Url() string
- type FactoshiioDataResponse
- type FactoshiioDataSource
- func (d *FactoshiioDataSource) ApiUrl() string
- func (d *FactoshiioDataSource) CallFactoshiio() (*FactoshiioDataResponse, error)
- func (d *FactoshiioDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *FactoshiioDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *FactoshiioDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *FactoshiioDataSource) Name() string
- func (d *FactoshiioDataSource) ParseFetchedPrices(data []byte) (*FactoshiioDataResponse, error)
- func (d *FactoshiioDataSource) SupportedPegs() []string
- func (d *FactoshiioDataSource) Url() string
- type FixedUSDDataSource
- type FreeForexAPIDataSource
- func (d *FreeForexAPIDataSource) ApiUrl() string
- func (d *FreeForexAPIDataSource) CallFreeForexAPI() (*FreeForexAPIDataSourceResponse, error)
- func (d *FreeForexAPIDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *FreeForexAPIDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *FreeForexAPIDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *FreeForexAPIDataSource) Name() string
- func (d *FreeForexAPIDataSource) ParseFetchedPrices(data []byte) (*FreeForexAPIDataSourceResponse, error)
- func (d *FreeForexAPIDataSource) ParseFetchedPricesVariation2(data []byte) (*FreeForexAPIDataSourceResponse, error)
- func (d *FreeForexAPIDataSource) SupportedPegs() []string
- func (d *FreeForexAPIDataSource) Url() string
- type FreeForexAPIDataSourceRate
- type FreeForexAPIDataSourceResponse
- type FreeForexAPIDataSourceResponseVariation2
- type IDataSource
- type KitcoData
- type KitcoDataSource
- type KitcoRecord
- type OneForgeDataSource
- func (d *OneForgeDataSource) ApiUrl() string
- func (d *OneForgeDataSource) AssetMapping() map[string]string
- func (d *OneForgeDataSource) Call1Forge() ([]OneForgeDataSourceRate, error)
- func (d *OneForgeDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *OneForgeDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *OneForgeDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *OneForgeDataSource) Name() string
- func (d *OneForgeDataSource) ParseFetchedPrices(data []byte) ([]OneForgeDataSourceRate, error)
- func (d *OneForgeDataSource) SupportedPegs() []string
- func (d *OneForgeDataSource) Url() string
- type OneForgeDataSourceRate
- type OneTimeUseCache
- type OpenExchangeRatesDataSource
- func (d *OpenExchangeRatesDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *OpenExchangeRatesDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *OpenExchangeRatesDataSource) Name() string
- func (d *OpenExchangeRatesDataSource) SupportedPegs() []string
- func (d *OpenExchangeRatesDataSource) Url() string
- type OpenExchangeRatesResponse
- type PegAssets
- type PegItem
- type PegnetMarketCapDataSource
- func (d *PegnetMarketCapDataSource) ApiUrl() string
- func (d *PegnetMarketCapDataSource) CallPegnetMarketCap() (map[string]PegnetMarketCapResponse, error)
- func (d *PegnetMarketCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
- func (d *PegnetMarketCapDataSource) FetchPegPrices() (peg PegAssets, err error)
- func (d *PegnetMarketCapDataSource) FetchPeggedPrices() ([]byte, error)
- func (d *PegnetMarketCapDataSource) Name() string
- func (d *PegnetMarketCapDataSource) ParseFetchedPrices(data []byte) (map[string]PegnetMarketCapResponse, error)
- func (d *PegnetMarketCapDataSource) SupportedPegs() []string
- func (d *PegnetMarketCapDataSource) Url() string
- type PegnetMarketCapResponse
- type TimedDataSourceCache
Constants ¶
const ( DefaultInitialInterval = 800 * time.Millisecond DefaultRandomizationFactor = 0.5 DefaultMultiplier = 1.5 DefaultMaxInterval = 3 * time.Second DefaultMaxElapsedTime = 10 * time.Second // max 10 seconds )
Default values for PollingExponentialBackOff.
Variables ¶
var AllDataSources = map[string]IDataSource{ "APILayer": new(APILayerDataSource), "CoinCap": new(CoinCapDataSource), "FixedUSD": new(FixedUSDDataSource), "Kitco": new(KitcoDataSource), "OpenExchangeRates": new(OpenExchangeRatesDataSource), "CoinMarketCap": new(CoinMarketCapDataSource), "FreeForexAPI": new(FreeForexAPIDataSource), "1Forge": new(OneForgeDataSource), "AlternativeMe": new(AlternativeMeDataSource), "PegnetMarketCap": new(PegnetMarketCapDataSource), "CoinGecko": new(CoinGeckoDataSource), }
AllDataSources is just a hard coded list of all the available assets. This list is copied in `NewDataSource`. These are the only two spots the list should be hard coded. The reason I have the `new(DataSource` is so I can get the name, url, and supported pegs from this map. It's useful in the cmdline to fetch the datasources dynamically.
var CoinCapIOCryptoAssetNames = map[string]string{
"XBT": "bitcoin",
"ETH": "ethereum",
"LTC": "litecoin",
"RVN": "ravencoin",
"XBC": "bitcoin-cash",
"FCT": "factom",
"BNB": "binance-coin",
"XLM": "stellar",
"ADA": "cardano",
"XMR": "monero",
"DASH": "dash",
"ZEC": "zcash",
"DCR": "decred",
"EOS": "eos",
"LINK": "chainlink",
"ATOM": "cosmos",
"BAT": "basic-attention-token",
"XTZ": "tezos",
}
CoinCapIOCryptoAssetNames is used by coincapio to query for the crypto we care about
var NewHTTPClient = func() *http.Client { return &http.Client{} }
NewHTTPClient is a variable so we can override it in unit tests. Some data sources might build clients off of this base one
var NewTestingDataSource = func(config *config.Config, source string) (IDataSource, error) { return nil, fmt.Errorf("this is a testing datasource for unit tests only") }
NewTestingDataSource is for unit test. Having a testing data source is for unit test mocking
Functions ¶
func AllDataSourcesList ¶ added in v0.1.0
func AllDataSourcesList() []string
func CommodityOpen ¶ added in v0.3.0
CommodityOpen returns if the commodity markets are open
This is a rough estimate, which we use to allow stale quote data. There is a 1hr window where it is closed during the day, however I do not see that on chain, and a fallback to the next datasource is not a bad result of letting the stale quote fallback.
https://www.forex.com/en-us/support/trading-hours/ Opens:
6:00 pm ET Sunday -> 22:00 UTC Sunday Closes: 5:00 pm ET Friday -> 21:00 UTC Friday
func CorrectCasing ¶ added in v0.1.0
CorrectCasing converts the case insensitive to the correct casing for the exchange This is mainly to handle user input from the command line.
func ForexOpen ¶ added in v0.3.0
ForexOpen returns if the forex markets are open
This is a rough estimate, which we use to allow stale quote data.
https://www.forex.com/en-us/support/trading-hours/ Opens:
5:00 pm ET Sunday -> 21:00 UTC Sunday Closes: 5:00 pm ET Friday -> 21:00 UTC Friday
func IsMarketOpen ¶ added in v0.3.0
IsMarketOpen is used to determine is a stale quote is due to a closed market. If the market is closed, we will allow stale quotes without having to fallback to a backup datasource. This 'MarketOpen' does not have to be perfect, as if they market is closed, but say it is open, then the polling will return the most recent quote it can find. This is not bad behavior.
func ParseKitco ¶
func PollingExponentialBackOff ¶ added in v0.1.0
func PollingExponentialBackOff() *backoff.ExponentialBackOff
PollingExponentialBackOff creates an instance of ExponentialBackOff
func TruncateTo4 ¶ added in v0.2.0
func TruncateTo8 ¶ added in v0.2.0
Types ¶
type APILayerDataSource ¶ added in v0.1.0
type APILayerDataSource struct {
// contains filtered or unexported fields
}
APILayerDataSource is the datasource at http://www.apilayer.net
func NewAPILayerDataSource ¶ added in v0.1.0
func NewAPILayerDataSource(config *config.Config) (*APILayerDataSource, error)
func (*APILayerDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *APILayerDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*APILayerDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *APILayerDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*APILayerDataSource) Name ¶ added in v0.1.0
func (d *APILayerDataSource) Name() string
func (*APILayerDataSource) SupportedPegs ¶ added in v0.1.0
func (d *APILayerDataSource) SupportedPegs() []string
func (*APILayerDataSource) Url ¶ added in v0.1.0
func (d *APILayerDataSource) Url() string
type APILayerError ¶ added in v0.1.0
type APILayerResponse ¶
type APILayerResponse struct { Success bool `json:"success"` Terms string `json:"terms"` Privacy string `json:"privacy"` Timestamp int64 `json:"timestamp"` Source string `json:"source"` Quotes map[string]float64 `json:"quotes"` Error APILayerError `json:"error"` }
func CallAPILayer ¶
func CallAPILayer(c *config.Config) (response APILayerResponse, err error)
type AlternativeMeDataSource ¶ added in v0.1.0
type AlternativeMeDataSource struct {
// contains filtered or unexported fields
}
AlternativeMeDataSource is the datasource at https://alternative.me/crypto/api/
Notes: - Price quotes are every 5 minutes
func NewAlternativeMeDataSource ¶ added in v0.1.0
func NewAlternativeMeDataSource(config *config.Config) (*AlternativeMeDataSource, error)
func (*AlternativeMeDataSource) ApiUrl ¶ added in v0.1.0
func (d *AlternativeMeDataSource) ApiUrl() string
func (*AlternativeMeDataSource) AssetMapping ¶ added in v0.1.0
func (d *AlternativeMeDataSource) AssetMapping() map[string]int
AssetMapping changes some asset symbols to others to match 1forge
func (*AlternativeMeDataSource) CallAlternativeMe ¶ added in v0.1.0
func (d *AlternativeMeDataSource) CallAlternativeMe() (*AlternativeMeDataSourceResponse, error)
func (*AlternativeMeDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *AlternativeMeDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*AlternativeMeDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *AlternativeMeDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*AlternativeMeDataSource) FetchPeggedPrices ¶ added in v0.1.0
func (d *AlternativeMeDataSource) FetchPeggedPrices() ([]byte, error)
func (*AlternativeMeDataSource) Name ¶ added in v0.1.0
func (d *AlternativeMeDataSource) Name() string
func (*AlternativeMeDataSource) ParseFetchedPrices ¶ added in v0.1.0
func (d *AlternativeMeDataSource) ParseFetchedPrices(data []byte) (*AlternativeMeDataSourceResponse, error)
func (*AlternativeMeDataSource) SupportedPegs ¶ added in v0.1.0
func (d *AlternativeMeDataSource) SupportedPegs() []string
func (*AlternativeMeDataSource) Url ¶ added in v0.1.0
func (d *AlternativeMeDataSource) Url() string
type AlternativeMeDataSourceMetadata ¶ added in v0.1.0
type AlternativeMeDataSourceQuote ¶ added in v0.1.0
type AlternativeMeDataSourceQuote struct { Price float64 `json:"price"` Volume24H float64 `json:"volume_24h"` MarketCap float64 `json:"market_cap"` PercentageChange1H float64 `json:"percentage_change_1h"` PercentageChange24H float64 `json:"percentage_change_24h"` PercentageChange7D float64 `json:"percentage_change_7d"` }
type AlternativeMeDataSourceRate ¶ added in v0.1.0
type AlternativeMeDataSourceRate struct { ID int `json:"id"` Name string `json:"name"` Symbol string `json:"symbol"` WebsiteSlug string `json:"website_slug"` Rank int `json:"rank"` CirculatingSupply float64 `json:"circulating_supply"` TotalSupply float64 `json:"total_supply"` MaxSupply float64 `json:"max_supply"` Quotes map[string]AlternativeMeDataSourceQuote `json:"quotes"` LastUpdated int64 `json:"last_updated"` }
type AlternativeMeDataSourceResponse ¶ added in v0.1.0
type AlternativeMeDataSourceResponse struct { Data map[string]AlternativeMeDataSourceRate `json:"data"` Metadata AlternativeMeDataSourceMetadata `json:"metadata"` }
type CoinCapDataSource ¶ added in v0.1.0
type CoinCapDataSource struct {
// contains filtered or unexported fields
}
CoinCapDataSource is the datasource at https://coincap.io/
func NewCoinCapDataSource ¶ added in v0.1.0
func NewCoinCapDataSource(config *config.Config) (*CoinCapDataSource, error)
func (CoinCapDataSource) CallCoinCap ¶ added in v0.5.0
func (d CoinCapDataSource) CallCoinCap(config *config.Config) (CoinCapResponse, error)
func (*CoinCapDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *CoinCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*CoinCapDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *CoinCapDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*CoinCapDataSource) Name ¶ added in v0.1.0
func (d *CoinCapDataSource) Name() string
func (*CoinCapDataSource) SupportedPegs ¶ added in v0.1.0
func (d *CoinCapDataSource) SupportedPegs() []string
func (*CoinCapDataSource) Url ¶ added in v0.1.0
func (d *CoinCapDataSource) Url() string
type CoinCapRecord ¶
type CoinCapRecord 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"` }
type CoinCapResponse ¶
type CoinCapResponse struct { Data []CoinCapRecord `json:"data"` Timestamp int64 `json:"timestamp"` }
func (CoinCapResponse) UnixTimestamp ¶ added in v0.3.0
func (c CoinCapResponse) UnixTimestamp() int64
type CoinGeckoDataSource ¶ added in v0.3.0
type CoinGeckoDataSource struct { }
CoinGeckoDataSource is the datasource at https://www.coingecko.com
func NewCoinGeckoDataSource ¶ added in v0.3.0
func NewCoinGeckoDataSource() (*CoinGeckoDataSource, error)
func (*CoinGeckoDataSource) ApiUrl ¶ added in v0.3.0
func (d *CoinGeckoDataSource) ApiUrl() string
func (*CoinGeckoDataSource) CallCoinGecko ¶ added in v0.3.0
func (d *CoinGeckoDataSource) CallCoinGecko() (map[string]CoinGeckoDataSourceResponse, error)
func (*CoinGeckoDataSource) CurrencyIDMapping ¶ added in v0.3.0
func (d *CoinGeckoDataSource) CurrencyIDMapping() map[string]string
CurrencyIDMapping finds the coingecko name for each currency vs using the syms.
func (*CoinGeckoDataSource) FetchPegPrice ¶ added in v0.3.0
func (d *CoinGeckoDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*CoinGeckoDataSource) FetchPegPrices ¶ added in v0.3.0
func (d *CoinGeckoDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*CoinGeckoDataSource) FetchPeggedPrices ¶ added in v0.3.0
func (d *CoinGeckoDataSource) FetchPeggedPrices() ([]byte, error)
func (*CoinGeckoDataSource) Name ¶ added in v0.3.0
func (d *CoinGeckoDataSource) Name() string
func (*CoinGeckoDataSource) ParseFetchedPrices ¶ added in v0.3.0
func (d *CoinGeckoDataSource) ParseFetchedPrices(data []byte) (map[string]CoinGeckoDataSourceResponse, error)
func (*CoinGeckoDataSource) SupportedPegs ¶ added in v0.3.0
func (d *CoinGeckoDataSource) SupportedPegs() []string
func (*CoinGeckoDataSource) Url ¶ added in v0.3.0
func (d *CoinGeckoDataSource) Url() string
type CoinGeckoDataSourceResponse ¶ added in v0.3.0
type CoinMarketCapCurrency ¶ added in v0.1.0
type CoinMarketCapCurrency struct { ID int `json:"id"` Name string `json:"name"` Symbol string `json:"symbol"` Slug string `json:"slug"` NumMarketPairs int `json:"num_market_pairs"` DateAdded time.Time `json:"date_added"` Tags []string `json:"tags"` MaxSupply float64 `json:"max_supply"` CirculatingSupply float64 `json:"circulating_supply"` TotalSupply float64 `json:"total_supply"` //Platform string `json:"platform"` CmcRank int `json:"cmc_rank"` LastUpdated string `json:"last_updated"` Quote map[string]CoinMarketCapQuote `json:"quote"` }
type CoinMarketCapDataSource ¶ added in v0.1.0
type CoinMarketCapDataSource struct {
// contains filtered or unexported fields
}
CoinMarketCapDataSource is the datasource at https://coinmarketcap.com/
func NewCoinMarketCapDataSource ¶ added in v0.1.0
func NewCoinMarketCapDataSource(config *config.Config) (*CoinMarketCapDataSource, error)
func (*CoinMarketCapDataSource) ApiUrl ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) ApiUrl() string
func (*CoinMarketCapDataSource) CallCoinMarketCap ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) CallCoinMarketCap() (*CoinMarketCapResponse, error)
func (*CoinMarketCapDataSource) CurrencyIDMapping ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) CurrencyIDMapping() map[string]int
RecordIDMapping finds the coinmarketcap ids for each currency vs using the symbols.
func (*CoinMarketCapDataSource) DateFormat ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) DateFormat() string
func (*CoinMarketCapDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*CoinMarketCapDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*CoinMarketCapDataSource) FetchPeggedPrices ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) FetchPeggedPrices() ([]byte, error)
func (*CoinMarketCapDataSource) Name ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) Name() string
func (*CoinMarketCapDataSource) ParseFetchedPrices ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) ParseFetchedPrices(data []byte) (*CoinMarketCapResponse, error)
func (*CoinMarketCapDataSource) SupportedPegs ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) SupportedPegs() []string
func (*CoinMarketCapDataSource) Url ¶ added in v0.1.0
func (d *CoinMarketCapDataSource) Url() string
type CoinMarketCapQuote ¶ added in v0.1.0
type CoinMarketCapQuote struct { Price float64 `json:"price"` Volume24H float64 `json:"volume_24h"` PercentChange1H float64 `json:"percent_change_1h"` PercentChange24H float64 `json:"percent_change_24h"` PercentChange7D float64 `json:"percent_change_7d"` MarketCap float64 `json:"market_cap"` LastUpdated string `json:"last_updated"` }
type CoinMarketCapResponse ¶ added in v0.1.0
type CoinMarketCapResponse struct { Status struct { Timestamp string `json:"timestamp"` ErrorCode int `json:"error_code"` ErrorMessage string `json:"error_message"` Elapsed int `json:"elapsed"` CreditCount int `json:"credit_count"` } `json:"status"` Data map[string]CoinMarketCapCurrency `json:"data"` }
type DataSourceWithPriority ¶ added in v0.1.0
type DataSourceWithPriority struct { DataSource IDataSource Priority int }
type DataSources ¶ added in v0.1.0
type DataSources struct { // AssetSources are listed in priority order. // If the asset is missing, we will walk through the data sources to find the // price of an asset // Key -> CurrencyISO // Value -> List of data sources by name AssetSources map[string][]string // DataSources is all the data sources we support // Key -> Data source name // Value -> Data source struct DataSources map[string]IDataSource // The list of data sources by priority. PriorityList []DataSourceWithPriority // contains filtered or unexported fields }
DataSources will initialize all data sources and handle pulling of all the assets.
func NewDataSources ¶ added in v0.1.0
func NewDataSources(config *config.Config) *DataSources
NewDataSources reads the config and sets everything up for polling
func (*DataSources) AssetPriorityString ¶ added in v0.1.0
func (ds *DataSources) AssetPriorityString(asset string) string
AssetPriorityString will print all the data sources for it in the priority order.
func (*DataSources) PriorityListString ¶ added in v0.1.0
func (ds *DataSources) PriorityListString() string
PriorityListString is for the cmd line, it will print all the data sources in their priority order.
func (*DataSources) PullAllPEGAssets ¶ added in v0.1.0
func (d *DataSources) PullAllPEGAssets(oprversion uint8) (pa PegAssets, err error)
PullAllPEGAssets will pull prices for every asset we are tracking. We pull assets from the sources in their priority order when possible. If an asset from priority 1 is missing, we resort to priority 2 ONLY for that missing asset.
Params: oprversion is passed in. Once we get past version 2, we can drop that from the params and default to the version 2 behavior
TODO: Currently we lazy eval prices, so we make the API call when we
first need a price from that source. These calls should be quick, but it might be faster to eager eval all the data sources concurrently.
func (*DataSources) PullBestPrice ¶ added in v0.3.0
func (d *DataSources) PullBestPrice(asset string, reference time.Time, sources map[string]IDataSource) (pa PegItem, err error)
PullBestPrice pulls the best asset price we can find for a given asset. Params:
asset Asset to pull pricing data reference Time reference to determine 'staleness' from sources Map of datasources to pull the price quote from.
type ExchangeRatesAPIResponse ¶ added in v0.1.0
type ExchangeRatesAPIResponse struct { Date string `json:"date"` Base string `json:"base"` Rates map[string]float64 `json:"rates"` }
func CallExchangeRatesAPI ¶ added in v0.1.0
func CallExchangeRatesAPI(c *config.Config) (ExchangeRatesAPIResponse, error)
type ExchangeRatesDataSource ¶ added in v0.1.0
type ExchangeRatesDataSource struct {
// contains filtered or unexported fields
}
ExchangeRatesDataSource is the datasource at "https://exchangeratesapi.io"
func NewExchangeRatesDataSource ¶ added in v0.1.0
func NewExchangeRatesDataSource(config *config.Config) (*ExchangeRatesDataSource, error)
func (*ExchangeRatesDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *ExchangeRatesDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*ExchangeRatesDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *ExchangeRatesDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*ExchangeRatesDataSource) Name ¶ added in v0.1.0
func (d *ExchangeRatesDataSource) Name() string
func (*ExchangeRatesDataSource) SupportedPegs ¶ added in v0.1.0
func (d *ExchangeRatesDataSource) SupportedPegs() []string
func (*ExchangeRatesDataSource) Url ¶ added in v0.1.0
func (d *ExchangeRatesDataSource) Url() string
type FactoshiioDataResponse ¶ added in v0.3.0
type FactoshiioDataSource ¶ added in v0.3.0
type FactoshiioDataSource struct { }
FactoshiioDataSource is the datasource at https://pegapi.factoshi.io/
func NewFactoshiioDataSource ¶ added in v0.3.0
func NewFactoshiioDataSource() (*FactoshiioDataSource, error)
func (*FactoshiioDataSource) ApiUrl ¶ added in v0.3.0
func (d *FactoshiioDataSource) ApiUrl() string
func (*FactoshiioDataSource) CallFactoshiio ¶ added in v0.3.0
func (d *FactoshiioDataSource) CallFactoshiio() (*FactoshiioDataResponse, error)
func (*FactoshiioDataSource) FetchPegPrice ¶ added in v0.3.0
func (d *FactoshiioDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*FactoshiioDataSource) FetchPegPrices ¶ added in v0.3.0
func (d *FactoshiioDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*FactoshiioDataSource) FetchPeggedPrices ¶ added in v0.3.0
func (d *FactoshiioDataSource) FetchPeggedPrices() ([]byte, error)
func (*FactoshiioDataSource) Name ¶ added in v0.3.0
func (d *FactoshiioDataSource) Name() string
func (*FactoshiioDataSource) ParseFetchedPrices ¶ added in v0.3.0
func (d *FactoshiioDataSource) ParseFetchedPrices(data []byte) (*FactoshiioDataResponse, error)
func (*FactoshiioDataSource) SupportedPegs ¶ added in v0.3.0
func (d *FactoshiioDataSource) SupportedPegs() []string
func (*FactoshiioDataSource) Url ¶ added in v0.3.0
func (d *FactoshiioDataSource) Url() string
type FixedUSDDataSource ¶ added in v0.1.0
type FixedUSDDataSource struct {
// contains filtered or unexported fields
}
FixedUSDDataSource is the datasource for USD. USD is always 1 USD = 1USD.
func NewFixedUSDDataSource ¶ added in v0.1.0
func NewFixedUSDDataSource(config *config.Config) (*FixedUSDDataSource, error)
func (*FixedUSDDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *FixedUSDDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*FixedUSDDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *FixedUSDDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*FixedUSDDataSource) Name ¶ added in v0.1.0
func (d *FixedUSDDataSource) Name() string
func (*FixedUSDDataSource) SupportedPegs ¶ added in v0.1.0
func (d *FixedUSDDataSource) SupportedPegs() []string
func (*FixedUSDDataSource) Url ¶ added in v0.1.0
func (d *FixedUSDDataSource) Url() string
type FreeForexAPIDataSource ¶ added in v0.1.0
type FreeForexAPIDataSource struct {
// contains filtered or unexported fields
}
FreeForexAPIDataSource is the datasource at https://www.freeforexapi.com
Notes: - Price quotes are every minute
func NewFreeForexAPIDataSource ¶ added in v0.1.0
func NewFreeForexAPIDataSource(config *config.Config) (*FreeForexAPIDataSource, error)
func (*FreeForexAPIDataSource) ApiUrl ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) ApiUrl() string
func (*FreeForexAPIDataSource) CallFreeForexAPI ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) CallFreeForexAPI() (*FreeForexAPIDataSourceResponse, error)
func (*FreeForexAPIDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*FreeForexAPIDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*FreeForexAPIDataSource) FetchPeggedPrices ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) FetchPeggedPrices() ([]byte, error)
func (*FreeForexAPIDataSource) Name ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) Name() string
func (*FreeForexAPIDataSource) ParseFetchedPrices ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) ParseFetchedPrices(data []byte) (*FreeForexAPIDataSourceResponse, error)
func (*FreeForexAPIDataSource) ParseFetchedPricesVariation2 ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) ParseFetchedPricesVariation2(data []byte) (*FreeForexAPIDataSourceResponse, error)
ParseFetchedPricesVariation2 is when the api returns a different variation. For some reason this variation is missing XAG and XAU. For now, let's just let the original parse fail and exponentially retry. TODO: Figure out what the heck is going on when the response format is changed.
Also the date was more than 2 weeks old. So I think this variation is.... bad
func (*FreeForexAPIDataSource) SupportedPegs ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) SupportedPegs() []string
func (*FreeForexAPIDataSource) Url ¶ added in v0.1.0
func (d *FreeForexAPIDataSource) Url() string
type FreeForexAPIDataSourceRate ¶ added in v0.1.0
type FreeForexAPIDataSourceResponse ¶ added in v0.1.0
type FreeForexAPIDataSourceResponse struct { Code int `json:"code"` Rates map[string]FreeForexAPIDataSourceRate `json:"rates"` }
type FreeForexAPIDataSourceResponseVariation2 ¶ added in v0.1.0
type IDataSource ¶ added in v0.1.0
type IDataSource interface { // Include some human friendly things. Name() string // Human friendly name Url() string // Url to their website // FetchPegPrices is a rest based API call to the data source to fetch // the prices for the supported pegs. FetchPegPrices() (peg PegAssets, err error) // FetchPegPrice only fetches the price for a single peg FetchPegPrice(peg string) (PegItem, error) // SupportedPegs tells us what supported pegs the exchange supports. // All exchanges should have a list of pegs they support. This should // be defined up front. SupportedPegs() []string }
IDataSource is the implementation all data sources need to adheer to.
func NewDataSource ¶ added in v0.1.0
func NewDataSource(source string, config *config.Config) (IDataSource, error)
func NewTimedDataSourceCache ¶ added in v0.1.0
func NewTimedDataSourceCache(s IDataSource, cacheLength time.Duration) IDataSource
type KitcoData ¶
type KitcoData struct { Silver KitcoRecord Gold KitcoRecord Platinum KitcoRecord Palladium KitcoRecord Rhodium KitcoRecord }
func CallKitcoWeb ¶
type KitcoDataSource ¶ added in v0.1.0
type KitcoDataSource struct {
// contains filtered or unexported fields
}
KitcoDataSource is the datasource at "https://www.kitco.com/"
func NewKitcoDataSource ¶ added in v0.1.0
func NewKitcoDataSource(config *config.Config) (*KitcoDataSource, error)
func (*KitcoDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *KitcoDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*KitcoDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *KitcoDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*KitcoDataSource) Name ¶ added in v0.1.0
func (d *KitcoDataSource) Name() string
func (*KitcoDataSource) SupportedPegs ¶ added in v0.1.0
func (d *KitcoDataSource) SupportedPegs() []string
func (*KitcoDataSource) Url ¶ added in v0.1.0
func (d *KitcoDataSource) Url() string
type KitcoRecord ¶
type OneForgeDataSource ¶ added in v0.1.0
type OneForgeDataSource struct {
// contains filtered or unexported fields
}
OneForgeDataSource is the datasource at https://1forge.com
func NewOneForgeDataSourceDataSource ¶ added in v0.1.0
func NewOneForgeDataSourceDataSource(config *config.Config) (*OneForgeDataSource, error)
func (*OneForgeDataSource) ApiUrl ¶ added in v0.1.0
func (d *OneForgeDataSource) ApiUrl() string
func (*OneForgeDataSource) AssetMapping ¶ added in v0.1.0
func (d *OneForgeDataSource) AssetMapping() map[string]string
AssetMapping changes some asset symbols to others to match 1forge
func (*OneForgeDataSource) Call1Forge ¶ added in v0.1.0
func (d *OneForgeDataSource) Call1Forge() ([]OneForgeDataSourceRate, error)
func (*OneForgeDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *OneForgeDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*OneForgeDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *OneForgeDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*OneForgeDataSource) FetchPeggedPrices ¶ added in v0.1.0
func (d *OneForgeDataSource) FetchPeggedPrices() ([]byte, error)
func (*OneForgeDataSource) Name ¶ added in v0.1.0
func (d *OneForgeDataSource) Name() string
func (*OneForgeDataSource) ParseFetchedPrices ¶ added in v0.1.0
func (d *OneForgeDataSource) ParseFetchedPrices(data []byte) ([]OneForgeDataSourceRate, error)
func (*OneForgeDataSource) SupportedPegs ¶ added in v0.1.0
func (d *OneForgeDataSource) SupportedPegs() []string
func (*OneForgeDataSource) Url ¶ added in v0.1.0
func (d *OneForgeDataSource) Url() string
type OneForgeDataSourceRate ¶ added in v0.1.0
type OneTimeUseCache ¶ added in v0.1.0
type OneTimeUseCache struct { IDataSource Cache PegAssets }
OneTimeUseCache will cache the data source response so we can query for prices individually without making a new api call. This cache is only to be used for 1 moment, rather than being used as a cache across multiple actions/rountines.
func NewCachedDataSource ¶ added in v0.1.0
func NewCachedDataSource(d IDataSource) *OneTimeUseCache
func (*OneTimeUseCache) FetchPegPrice ¶ added in v0.1.0
func (d *OneTimeUseCache) FetchPegPrice(peg string) (i PegItem, err error)
func (*OneTimeUseCache) FetchPegPrices ¶ added in v0.1.0
func (d *OneTimeUseCache) FetchPegPrices() (peg PegAssets, err error)
type OpenExchangeRatesDataSource ¶ added in v0.1.0
type OpenExchangeRatesDataSource struct {
// contains filtered or unexported fields
}
OpenExchangeRatesDataSource is the datasource at "https://openexchangerates.org/"
func NewOpenExchangeRatesDataSource ¶ added in v0.1.0
func NewOpenExchangeRatesDataSource(config *config.Config) (*OpenExchangeRatesDataSource, error)
func (*OpenExchangeRatesDataSource) FetchPegPrice ¶ added in v0.1.0
func (d *OpenExchangeRatesDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*OpenExchangeRatesDataSource) FetchPegPrices ¶ added in v0.1.0
func (d *OpenExchangeRatesDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*OpenExchangeRatesDataSource) Name ¶ added in v0.1.0
func (d *OpenExchangeRatesDataSource) Name() string
func (*OpenExchangeRatesDataSource) SupportedPegs ¶ added in v0.1.0
func (d *OpenExchangeRatesDataSource) SupportedPegs() []string
func (*OpenExchangeRatesDataSource) Url ¶ added in v0.1.0
func (d *OpenExchangeRatesDataSource) Url() string
type OpenExchangeRatesResponse ¶ added in v0.1.0
type OpenExchangeRatesResponse struct { Disclaimer string `json:"disclaimer"` License string `json:"license"` Timestamp int64 `json:"timestamp"` Base string `json:"base"` Error bool `json:"error"` Status int64 `json:"status"` Message string `json:"message"` Description string `json:"description"` Rates map[string]float64 `json:"rates"` }
func CallOpenExchangeRates ¶
func CallOpenExchangeRates(c *config.Config) (response OpenExchangeRatesResponse, err error)
type PegItem ¶ added in v0.1.0
type PegnetMarketCapDataSource ¶ added in v0.3.0
type PegnetMarketCapDataSource struct { }
PegnetMarketCap is the datasource at https://pegnetmarketcap.com/
func NewPegnetMarketCapDataSource ¶ added in v0.3.0
func NewPegnetMarketCapDataSource() (*PegnetMarketCapDataSource, error)
func (*PegnetMarketCapDataSource) ApiUrl ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) ApiUrl() string
func (*PegnetMarketCapDataSource) CallPegnetMarketCap ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) CallPegnetMarketCap() (map[string]PegnetMarketCapResponse, error)
func (*PegnetMarketCapDataSource) FetchPegPrice ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) FetchPegPrice(peg string) (i PegItem, err error)
func (*PegnetMarketCapDataSource) FetchPegPrices ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) FetchPegPrices() (peg PegAssets, err error)
func (*PegnetMarketCapDataSource) FetchPeggedPrices ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) FetchPeggedPrices() ([]byte, error)
func (*PegnetMarketCapDataSource) Name ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) Name() string
func (*PegnetMarketCapDataSource) ParseFetchedPrices ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) ParseFetchedPrices(data []byte) (map[string]PegnetMarketCapResponse, error)
func (*PegnetMarketCapDataSource) SupportedPegs ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) SupportedPegs() []string
func (*PegnetMarketCapDataSource) Url ¶ added in v0.3.0
func (d *PegnetMarketCapDataSource) Url() string
type PegnetMarketCapResponse ¶ added in v0.3.0
type TimedDataSourceCache ¶ added in v0.1.0
type TimedDataSourceCache struct { IDataSource LastCall time.Time CacheDuration time.Duration Cache PegAssets }
TimedDataSourceCache will limit the number of calls by caching the results for X period of time
func (*TimedDataSourceCache) FetchPegPrice ¶ added in v0.1.0
func (d *TimedDataSourceCache) FetchPegPrice(peg string) (i PegItem, err error)
func (*TimedDataSourceCache) FetchPegPrices ¶ added in v0.1.0
func (d *TimedDataSourceCache) FetchPegPrices() (peg PegAssets, err error)