models

package
v1.2.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: GPL-2.0 Imports: 23 Imported by: 65

Documentation

Index

Constants

View Source
const (
	WindowYesterday = 24 * 60 * 60
	Window1h        = 60 * 60
	Window7d        = 7 * 24 * 60 * 60
	Window14d       = 7 * 24 * 60 * 60
	Window30d       = 30 * 24 * 60 * 60
	Window2         = 24 * 60 * 60 * 8
	BufferTTL       = 60 * 60
	BiggestWindow   = Window2
	TimeOutRedis    = time.Duration(time.Second * (BiggestWindow + BufferTTL))
)
View Source
const (
	TimeLayoutRedis = "2006-01-02 15:04:05 +0000 UTC"
)
View Source
const (
	WindowVolume = 60 * 60 * 24
)

Variables

This section is empty.

Functions

func StraightRates

func StraightRates(intRates []*InterestRate) map[time.Time]float64

StraightRates returns a map which maps a rate to each day in the time period. This includes (artificial) rate values for non-business days. intRates must be sorted by date in increasing order.

func WeightedRates

func WeightedRates(intRates []*InterestRate, dateInit, dateFinal time.Time, holidays []time.Time, startIndex int) (map[time.Time]float64, int)

WeightedRates returns a map which maps a rate to each business day in the time period given by @dateInit and @dateFinal. Rates are weighted by the rate factor. intRates must be sorted by date in increasing order.

Types

type Author

type Author struct {
	Name  string
	Email string
}

type Change

type Change struct {
	USD []CurrencyChange
}

func (*Change) MarshalBinary

func (e *Change) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*Change) UnmarshalBinary

func (e *Change) UnmarshalBinary(data []byte) error

UnmarshalBinary -

type Coin

type Coin struct {
	Symbol             string
	Name               string
	Price              float64
	PriceYesterday     *float64
	VolumeYesterdayUSD *float64
	Time               time.Time
	CirculatingSupply  *float64
	ITIN               string
}

func (*Coin) MarshalBinary

func (e *Coin) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*Coin) UnmarshalBinary

func (e *Coin) UnmarshalBinary(data []byte) error

type CoinSymbolAndName

type CoinSymbolAndName struct {
	Symbol string
	Name   string
}

type Coins

type Coins struct {
	CompleteCoinList []CoinSymbolAndName
	Change           *Change
	Coins            []Coin
}

func (*Coins) MarshalBinary

func (e *Coins) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*Coins) UnmarshalBinary

func (e *Coins) UnmarshalBinary(data []byte) error

UnmarshalBinary -

type CryptoIndex

type CryptoIndex struct {
	Name              string
	Value             float64
	Price             float64
	Price1h           float64
	Price24h          float64
	Price7d           float64
	Price14d          float64
	Price30d          float64
	Volume24hUSD      float64
	CirculatingSupply float64
	Divisor           float64
	CalculationTime   time.Time
	Constituents      []CryptoIndexConstituent
}

CryptoIndex is the container for API endpoint CryptoIndex

func (*CryptoIndex) MarshalBinary

func (e *CryptoIndex) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*CryptoIndex) UnmarshalBinary

func (e *CryptoIndex) UnmarshalBinary(data []byte) error

UnmarshalBinary -

type CryptoIndexConstituent

type CryptoIndexConstituent struct {
	Name              string
	Symbol            string
	Address           string
	Price             float64
	PriceYesterday    float64
	PriceYesterweek   float64
	CirculatingSupply float64
	Weight            float64
	Percentage        float64
	CappingFactor     float64
	NumBaseTokens     float64
}

type CryptoIndexMintAmount

type CryptoIndexMintAmount struct {
	Name          string
	Symbol        string
	Address       string
	Amount        uint64
	RebalanceTime time.Time
}

type CurrencyChange

type CurrencyChange struct {
	Symbol        string
	Rate          float64
	RateYesterday float64
}

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDataStore

func NewDataStore() (*DB, error)

func NewDataStoreWithOptions

func NewDataStoreWithOptions(withRedis bool, withInflux bool) (*DB, error)

func NewDataStoreWithoutInflux

func NewDataStoreWithoutInflux() (*DB, error)

func NewDataStoreWithoutRedis

func NewDataStoreWithoutRedis() (*DB, error)

func NewInfluxDataStore

func NewInfluxDataStore() (*DB, error)

func NewRedisDataStore

func NewRedisDataStore() (*DB, error)

func (*DB) ExistInterestRate

func (db *DB) ExistInterestRate(symbol, date string) bool

ExistInterestRate returns true if a database entry with given date stamp exists, and false otherwise. @date should be a substring of a string formatted as "yyyy-mm-dd hh:mm:ss".

func (*DB) Flush

func (db *DB) Flush() error

func (*DB) GetAllSymbols

func (db *DB) GetAllSymbols() []string

func (*DB) GetAllTrades

func (db *DB) GetAllTrades(t time.Time, maxTrades int) ([]dia.Trade, error)

GetAllTrades returns at most @maxTrades trades from influx with timestamp > @t. Only used by replayInflux option.

func (*DB) GetAvailablePairsForExchange

func (db *DB) GetAvailablePairsForExchange(exchange string) ([]dia.Pair, error)

GetAvailablePairsForExchange a slice of all pairs available in the exchange in the internal redis db

func (*DB) GetCVIInflux

func (db *DB) GetCVIInflux(starttime time.Time, endtime time.Time, symbol string) ([]dia.CviDataPoint, error)

func (*DB) GetChartPoints7Days

func (db *DB) GetChartPoints7Days(symbol string) (r []Point, err error)

> SELECT MEAN(value) FROM filters WHERE "symbol"='BTC' and "filter"='MA120' GROUP BY TIME(10m) ORDER by time desc limit 10;

func (*DB) GetCoins

func (db *DB) GetCoins() (*Coins, error)

func (*DB) GetCommitByDate

func (db *DB) GetCommitByDate(user, repository string, date time.Time) (GithubCommit, error)

GetCommitByDate returns the latest commit from @repository of github user @user before @date.

func (*DB) GetCommitByHash

func (db *DB) GetCommitByHash(user, repository, hash string) (GithubCommit, error)

GetCommitByHash returns the commit from @repository of github user @user with hash @hash.

func (*DB) GetCompoundedAvg

func (db *DB) GetCompoundedAvg(symbol string, date time.Time, calDays, daysPerYear int, rounding int) (*InterestRate, error)

GetCompoundedAvg returns the compounded average of the index @symbol over rolling @calDays calendar days.

func (*DB) GetCompoundedAvgDIARange

func (db *DB) GetCompoundedAvgDIARange(symbol string, dateInit, dateFinal time.Time, calDays, daysPerYear int, rounding int) (values []*InterestRate, err error)

GetCompoundedAvgDIARange returns the compounded average DIA index of @symbol over rolling @calDays calendar days.

func (*DB) GetCompoundedAvgRange

func (db *DB) GetCompoundedAvgRange(symbol string, dateInit, dateFinal time.Time, calDays, daysPerYear int, rounding int) (values []*InterestRate, err error)

GetCompoundedAvgRange returns the compounded average of the index @symbol over rolling @calDays calendar days.

func (*DB) GetCompoundedIndex

func (db *DB) GetCompoundedIndex(symbol string, date time.Time, daysPerYear int, rounding int) (*InterestRate, error)

GetCompoundedIndex returns the compounded index over the maximal period of existence of @symbol

func (*DB) GetCompoundedIndexRange

func (db *DB) GetCompoundedIndexRange(symbol string, dateInit, dateFinal time.Time, daysPerYear int, rounding int) (values []*InterestRate, err error)

GetCompoundedIndexRange returns the compounded average of the index @symbol over rolling @calDays calendar days.

func (*DB) GetCompoundedRate

func (db *DB) GetCompoundedRate(symbol string, dateInit, date time.Time, daysPerYear int, rounding int) (*InterestRate, error)

GetCompoundedRate returns the compounded rate for the period @dateInit to @date. It computes the rate for all days for which an entry is present in the database. All other days are assumed to be holidays (or weekends).

func (*DB) GetConfigTogglePairDiscovery

func (db *DB) GetConfigTogglePairDiscovery() (bool, error)

func (*DB) GetCryptoIndex

func (db *DB) GetCryptoIndex(starttime time.Time, endtime time.Time, name string) ([]CryptoIndex, error)

func (*DB) GetCryptoIndexConstituentPrice

func (db *DB) GetCryptoIndexConstituentPrice(symbol string, date time.Time) (float64, error)

func (*DB) GetCryptoIndexConstituents

func (db *DB) GetCryptoIndexConstituents(starttime time.Time, endtime time.Time, symbol string, indexSymbol string) ([]CryptoIndexConstituent, error)

func (*DB) GetCryptoIndexMintAmounts

func (db *DB) GetCryptoIndexMintAmounts(symbol string) ([]CryptoIndexMintAmount, error)

WIP: Returns the amounts of constituents tokens needed to mint an index token For now we hard-code amounts. TO DO: Set and Get data to and from influx/config

func (*DB) GetCurrencyChange

func (db *DB) GetCurrencyChange() (*Change, error)

func (*DB) GetDefiProtocol

func (db *DB) GetDefiProtocol(name string) (dia.DefiProtocol, error)

GetDefiProtocol returns the die protocol struct by name

func (*DB) GetDefiProtocols

func (db *DB) GetDefiProtocols() ([]dia.DefiProtocol, error)

GetDefiProtocols returns a slice of all available DeFi protocols

func (*DB) GetDefiRateInflux

func (db *DB) GetDefiRateInflux(starttime time.Time, endtime time.Time, asset string, protocol string) ([]dia.DefiRate, error)

func (*DB) GetDefiStateInflux

func (db *DB) GetDefiStateInflux(starttime time.Time, endtime time.Time, protocol string) (retval []dia.DefiProtocolState, err error)

func (*DB) GetDiaCirculatingSupply added in v1.4.2

func (db *DB) GetDiaCirculatingSupply() (float64, error)

func (*DB) GetDiaTotalSupply added in v1.4.2

func (db *DB) GetDiaTotalSupply() (float64, error)

func (*DB) GetExchanges

func (db *DB) GetExchanges() (allExchanges []string)

GetExchanges returns all available trading places. Comment: Think about getting the exchanges from redis.

func (*DB) GetExchangesForSymbol

func (db *DB) GetExchangesForSymbol(symbol string) ([]string, error)

func (*DB) GetFarmingPoolData

func (db *DB) GetFarmingPoolData(starttime, endtime time.Time, protocol, poolID string) ([]FarmingPool, error)

GetFarmingPoolData returns all farming pool states in the given time range time, balance, blocknumber, inputAssets, outputAssets, poolID, protocol, rate

func (*DB) GetFarmingPools

func (db *DB) GetFarmingPools() ([]FarmingPoolType, error)

GetFarmingPools returns all farming pool states in the given time range time, balance, blocknumber, inputAssets, outputAssets, poolID, protocol, rate

func (*DB) GetFilterPoints

func (db *DB) GetFilterPoints(filter string, exchange string, symbol string, scale string, starttime time.Time, endtime time.Time) (*Points, error)

GetFilterPoints returns filter points from either a specific exchange or all exchanges

func (*DB) GetFirstDate

func (db *DB) GetFirstDate(symbol string) (time.Time, error)

GetFirstDate returns the oldest date written in the database for the rate with symbol @symbol

func (*DB) GetForeignPriceYesterday

func (db *DB) GetForeignPriceYesterday(symbol, source string) (float64, error)

GetForeignPriceYesterday returns the average price of @symbol on @source from yesterday

func (*DB) GetForeignQuotationInflux

func (db *DB) GetForeignQuotationInflux(symbol, source string, timestamp time.Time) (ForeignQuotation, error)

GetForeignQuotationInflux returns the last quotation of @symbol before @timestamp

func (*DB) GetForeignSymbolsInflux

func (db *DB) GetForeignSymbolsInflux(source string) (symbols []SymbolShort, err error)

GetForeignSymbolsInflux returns a list with all symbols available for quotation from @source, along with their ITIN.

func (*DB) GetInterestRate

func (db *DB) GetInterestRate(symbol, date string) (*InterestRate, error)

GetInterestRate returns the interest rate value for the last time stamp before @date. If @date is an empty string it returns the rate at the latest time stamp. @symbol is the shorthand symbol for the requested interest rate. @date is a string in the format yyyy-mm-dd.

func (*DB) GetInterestRateRange

func (db *DB) GetInterestRateRange(symbol, dateInit, dateFinal string) ([]*InterestRate, error)

GetInterestRateRange returns the interest rate values for a range of timestamps. @symbol is the shorthand symbol for the requested interest rate. @dateInit and @dateFinal are strings in the format yyyy-mm-dd.

func (*DB) GetIssuer

func (db *DB) GetIssuer(symbol string) (string, error)

GetIssuer returns the issuing entity of the rate given by @symbol

func (*DB) GetItinBySymbol

func (db *DB) GetItinBySymbol(symbol string) (dia.ItinToken, error)

func (*DB) GetLastPriceBefore

func (db *DB) GetLastPriceBefore(symbol string, filter string, exchange string, timestamp time.Time) (Price, error)

func (*DB) GetLastTradeTimeForExchange

func (db *DB) GetLastTradeTimeForExchange(symbol string, exchange string) (*time.Time, error)

func (*DB) GetLastTrades

func (db *DB) GetLastTrades(symbol string, exchange string, maxTrades int) ([]dia.Trade, error)

func (*DB) GetLastTradesAllExchanges

func (db *DB) GetLastTradesAllExchanges(symbol string, maxTrades int) ([]dia.Trade, error)

func (*DB) GetLatestCommit

func (db *DB) GetLatestCommit(user, repository string) (GithubCommit, error)

GetLatestCommit returns the latest commit from influx. Returns empty struct and nil if no commits are in the database.

func (*DB) GetLatestSupply

func (db *DB) GetLatestSupply(symbol string) (*dia.Supply, error)

func (*DB) GetOptionMeta

func (db *DB) GetOptionMeta(baseCurrency string) ([]dia.OptionMeta, error)

func (*DB) GetOptionOrderbookDataInflux

func (db *DB) GetOptionOrderbookDataInflux(t dia.OptionMeta) (dia.OptionOrderbookDatum, error)

func (*DB) GetPairs

func (db *DB) GetPairs(exchange string) ([]dia.Pair, error)

exchange = "" for all exchanges

func (*DB) GetPaxgQuotationGrams

func (db *DB) GetPaxgQuotationGrams() (*Quotation, error)

func (*DB) GetPaxgQuotationOunces

func (db *DB) GetPaxgQuotationOunces() (*Quotation, error)

func (*DB) GetPrice

func (db *DB) GetPrice(symbol string, exchange string) (float64, error)

func (*DB) GetPrice14d

func (db *DB) GetPrice14d(symbol string, exchange string) (float64, error)

func (*DB) GetPrice1h

func (db *DB) GetPrice1h(symbol string, exchange string) (float64, error)

func (*DB) GetPrice30d

func (db *DB) GetPrice30d(symbol string, exchange string) (float64, error)

func (*DB) GetPrice7d

func (db *DB) GetPrice7d(symbol string, exchange string) (float64, error)

func (*DB) GetPriceUSD

func (db *DB) GetPriceUSD(symbol string) (float64, error)

func (*DB) GetPriceYesterday

func (db *DB) GetPriceYesterday(symbol string, exchange string) (float64, error)

func (*DB) GetQuotation

func (db *DB) GetQuotation(symbol string) (*Quotation, error)

func (*DB) GetRates

func (db *DB) GetRates() []string

GetRates returns a (unique) slice of all rates that have been written into the database

func (*DB) GetRatesMeta

func (db *DB) GetRatesMeta() (RatesMeta []InterestRateMeta, err error)

GetRatesMeta returns a list of all available rate symbols along with their first timestamp in the database.

func (*DB) GetStockQuotation added in v1.2.0

func (db *DB) GetStockQuotation(source string, symbol string, timeInit time.Time, timeFinal time.Time) ([]StockQuotation, error)

GetStockQuotationInflux returns the last quotation of @symbol before @timestamp.

func (*DB) GetStockSymbols added in v1.4.0

func (db *DB) GetStockSymbols() (map[Stock]string, error)

GetStockSymbols returns all symbols available from @source.

func (*DB) GetSupply

func (db *DB) GetSupply(symbol string, starttime, endtime time.Time) ([]dia.Supply, error)

func (*DB) GetSupplyInflux

func (db *DB) GetSupplyInflux(symbol string, starttime time.Time, endtime time.Time) ([]dia.Supply, error)

func (*DB) GetSymbolDetails

func (db *DB) GetSymbolDetails(symbol string) (*SymbolDetails, error)

func (*DB) GetSymbolExchangeDetails

func (db *DB) GetSymbolExchangeDetails(symbol string, exchange string) (*SymbolExchangeDetails, error)

func (*DB) GetSymbols

func (db *DB) GetSymbols(exchange string) ([]string, error)

func (*DB) GetSymbolsByExchange

func (db *DB) GetSymbolsByExchange(e string) []string

func (*DB) GetTradeInflux

func (db *DB) GetTradeInflux(symbol string, exchange string, timestamp time.Time) (*dia.Trade, error)

func (*DB) GetTradePrice14d

func (db *DB) GetTradePrice14d(symbol string, exchange string) (*dia.Trade, error)

func (*DB) GetTradePrice1h

func (db *DB) GetTradePrice1h(symbol string, exchange string) (*dia.Trade, error)

func (*DB) GetTradePrice24h

func (db *DB) GetTradePrice24h(symbol string, exchange string) (*dia.Trade, error)

func (*DB) GetTradePrice30d

func (db *DB) GetTradePrice30d(symbol string, exchange string) (*dia.Trade, error)

func (*DB) GetTradePrice7d

func (db *DB) GetTradePrice7d(symbol string, exchange string) (*dia.Trade, error)

func (*DB) GetTradePriceBefore

func (db *DB) GetTradePriceBefore(symbol string, exchange string, timestamp time.Time) (*dia.Trade, error)

func (*DB) GetVolume

func (db *DB) GetVolume(symbol string) (*float64, error)

func (*DB) GetVolumeExchange

func (db *DB) GetVolumeExchange(symbol string, exchange string) (*float64, error)

func (*DB) GetVolumeInflux

func (db *DB) GetVolumeInflux(symbol string, starttime time.Time, endtime time.Time) (float64, error)

GetVolumeInflux returns the trade volume of @symbol in the time range @starttime - @endtime. It uses the VOL filter from the filter services.

func (*DB) RemoveExpiredOptionMeta

func (db *DB) RemoveExpiredOptionMeta(baseCurrency string) error

func (*DB) SaveCVIInflux

func (db *DB) SaveCVIInflux(cviValue float64, observationTime time.Time) error

func (*DB) SaveETHCVIInflux

func (db *DB) SaveETHCVIInflux(cviValue float64, observationTime time.Time) error

func (*DB) SaveFilterInflux

func (db *DB) SaveFilterInflux(filter string, symbol string, exchange string, value float64, t time.Time) error

func (*DB) SaveForeignQuotationInflux

func (db *DB) SaveForeignQuotationInflux(fq ForeignQuotation) error

SaveForeignQuotationInflux stores a quotation which is not from DIA to an influx batch

func (*DB) SaveOptionOrderbookDatumInflux

func (db *DB) SaveOptionOrderbookDatumInflux(t dia.OptionOrderbookDatum) error

func (*DB) SaveSupplyInflux

func (db *DB) SaveSupplyInflux(supply *dia.Supply) error

func (*DB) SaveTradeInflux

func (db *DB) SaveTradeInflux(t *dia.Trade) error

func (*DB) SetAvailablePairsForExchange

func (db *DB) SetAvailablePairsForExchange(exchange string, pairs []dia.Pair) error

SetAvailablePairsForExchange stores a json containing all pairs available in the exchange in the internal redis db

func (*DB) SetCommit

func (db *DB) SetCommit(commit *GithubCommit) error

SetCommit stores a github commit in influx

func (*DB) SetCryptoIndex

func (db *DB) SetCryptoIndex(index *CryptoIndex) error

func (*DB) SetCryptoIndexConstituent

func (db *DB) SetCryptoIndexConstituent(constituent *CryptoIndexConstituent, indexSymbol string) error

func (*DB) SetCurrencyChange

func (db *DB) SetCurrencyChange(cc *Change) error

func (*DB) SetDefiProtocol

func (db *DB) SetDefiProtocol(protocol dia.DefiProtocol) error

SetDefiProtocol writes @protocol into redis

func (*DB) SetDefiRateInflux

func (db *DB) SetDefiRateInflux(rate *dia.DefiRate) error

func (*DB) SetDefiStateInflux

func (db *DB) SetDefiStateInflux(state *dia.DefiProtocolState) error

func (*DB) SetDiaCirculatingSupply added in v1.4.2

func (db *DB) SetDiaCirculatingSupply(circulatingSupply float64) error

func (*DB) SetDiaTotalSupply added in v1.4.2

func (db *DB) SetDiaTotalSupply(totalSupply float64) error

func (*DB) SetFarmingPool

func (db *DB) SetFarmingPool(pool *FarmingPool) error

func (*DB) SetFilter

func (db *DB) SetFilter(filter string, symbol string, exchange string, volume float64, t time.Time) error

func (*DB) SetInterestRate

func (db *DB) SetInterestRate(ir *InterestRate) error

SetInterestRate writes the interest rate struct ir into the Redis database and writes rate type into a set of all available rates (if not done yet).

func (*DB) SetItinData

func (db *DB) SetItinData(token dia.ItinToken) error

func (*DB) SetLastTradeTimeForExchange

func (db *DB) SetLastTradeTimeForExchange(symbol string, exchange string, t time.Time) error

func (*DB) SetOptionMeta

func (db *DB) SetOptionMeta(optionMeta *dia.OptionMeta) error

func (*DB) SetPriceEUR

func (a *DB) SetPriceEUR(symbol string, price float64) error

func (*DB) SetPriceUSD

func (db *DB) SetPriceUSD(symbol string, price float64) error

func (*DB) SetPriceZSET

func (db *DB) SetPriceZSET(symbol string, exchange string, price float64, t time.Time) error

func (*DB) SetQuotation

func (db *DB) SetQuotation(quotation *Quotation) error

func (*DB) SetQuotationEUR

func (db *DB) SetQuotationEUR(quotation *Quotation) error

func (*DB) SetStockQuotation added in v1.2.0

func (db *DB) SetStockQuotation(sq StockQuotation) error

SetStockQuotationInflux stores a stock quotation to an influx batch.

func (*DB) SetSupply

func (db *DB) SetSupply(supply *dia.Supply) error

func (*DB) SetVolume

func (db *DB) SetVolume(symbol string, exchange string, volume float64, t time.Time) error

func (*DB) Sum24HoursExchange

func (db *DB) Sum24HoursExchange(exchange string) (float64, error)

Sum24HoursExchange returns 24h trade volumes summed up for all assets on @exchange, using VOL120 filtered data from influx.

func (*DB) Sum24HoursInflux

func (db *DB) Sum24HoursInflux(symbol string, exchange string, filter string) (*float64, error)

Sum24HoursInflux returns the 24h volume of @symbol on @exchange using the filter @filter.

func (*DB) SymbolsWithASupply

func (db *DB) SymbolsWithASupply() ([]string, error)

func (*DB) UpdateSymbolDetails

func (db *DB) UpdateSymbolDetails(symbol string, rank int)

func (*DB) WriteBatchInflux

func (db *DB) WriteBatchInflux() error

type Datastore

type Datastore interface {
	SetVolume(symbol string, exchange string, volume float64, t time.Time) error
	GetVolume(symbol string) (*float64, error)
	SymbolsWithASupply() ([]string, error)
	SetPriceUSD(symbol string, price float64) error
	SetPriceEUR(symbol string, price float64) error
	GetPriceUSD(symbol string) (float64, error)
	GetQuotation(symbol string) (*Quotation, error)
	SetQuotation(quotation *Quotation) error
	SetQuotationEUR(quotation *Quotation) error
	GetLatestSupply(string) (*dia.Supply, error)
	GetSupply(string, time.Time, time.Time) ([]dia.Supply, error)
	SetSupply(supply *dia.Supply) error
	SetDiaTotalSupply(float64) error
	GetDiaTotalSupply() (float64, error)
	SetDiaCirculatingSupply(float64) error
	GetDiaCirculatingSupply() (float64, error)
	SetPriceZSET(symbol string, exchange string, price float64, t time.Time) error
	GetChartPoints7Days(symbol string) ([]Point, error)
	GetPairs(exchange string) ([]dia.Pair, error)
	GetSymbols(exchange string) ([]string, error)
	GetExchangesForSymbol(symbol string) ([]string, error)
	GetSymbolExchangeDetails(symbol string, exchange string) (*SymbolExchangeDetails, error)
	GetLastTradeTimeForExchange(symbol string, exchange string) (*time.Time, error)
	SetLastTradeTimeForExchange(symbol string, exchange string, t time.Time) error
	SaveTradeInflux(t *dia.Trade) error
	GetTradeInflux(string, string, time.Time) (*dia.Trade, error)
	SaveFilterInflux(filter string, symbol string, exchange string, value float64, t time.Time) error
	GetLastTrades(symbol string, exchange string, maxTrades int) ([]dia.Trade, error)
	GetLastTradesAllExchanges(string, int) ([]dia.Trade, error)
	GetAllTrades(t time.Time, maxTrades int) ([]dia.Trade, error)
	Flush() error
	GetFilterPoints(filter string, exchange string, symbol string, scale string, starttime time.Time, endtime time.Time) (*Points, error)
	SetFilter(filterName string, symbol string, exchange string, value float64, t time.Time) error
	GetLastPriceBefore(symbol string, filter string, exchange string, timestamp time.Time) (Price, error)
	SetAvailablePairsForExchange(exchange string, pairs []dia.Pair) error
	GetAvailablePairsForExchange(exchange string) ([]dia.Pair, error)
	SetCurrencyChange(cc *Change) error
	GetCurrencyChange() (*Change, error)
	GetAllSymbols() []string
	GetSymbolsByExchange(string) []string
	GetCoins() (*Coins, error)
	GetSymbolDetails(symbol string) (*SymbolDetails, error)
	UpdateSymbolDetails(symbol string, rank int)
	GetConfigTogglePairDiscovery() (bool, error)
	GetExchanges() []string
	SetOptionMeta(optionMeta *dia.OptionMeta) error
	GetOptionMeta(baseCurrency string) ([]dia.OptionMeta, error)
	SaveCVIInflux(float64, time.Time) error
	GetCVIInflux(time.Time, time.Time, string) ([]dia.CviDataPoint, error)
	GetSupplyInflux(string, time.Time, time.Time) ([]dia.Supply, error)
	GetVolumeInflux(string, time.Time, time.Time) (float64, error)
	// Get24Volume(symbol string, exchange string) (float64, error)
	// Get24VolumeExchange(exchange string) (float64, error)
	Sum24HoursExchange(exchange string) (float64, error)

	// Interest rates' methods
	SetInterestRate(ir *InterestRate) error
	GetInterestRate(symbol, date string) (*InterestRate, error)
	GetInterestRateRange(symbol, dateInit, dateFinal string) ([]*InterestRate, error)
	GetRatesMeta() (RatesMeta []InterestRateMeta, err error)
	GetCompoundedIndex(symbol string, date time.Time, daysPerYear int, rounding int) (*InterestRate, error)
	GetCompoundedIndexRange(symbol string, dateInit, dateFinal time.Time, daysPerYear int, rounding int) ([]*InterestRate, error)
	GetCompoundedAvg(symbol string, date time.Time, calDays, daysPerYear int, rounding int) (*InterestRate, error)
	GetCompoundedAvgRange(symbol string, dateInit, dateFinal time.Time, calDays, daysPerYear int, rounding int) ([]*InterestRate, error)
	GetCompoundedAvgDIARange(symbol string, dateInit, dateFinal time.Time, calDays, daysPerYear int, rounding int) ([]*InterestRate, error)

	// Pool  methods
	SetFarmingPool(pr *FarmingPool) error
	GetFarmingPoolData(starttime, endtime time.Time, protocol, poolID string) ([]FarmingPool, error)
	GetFarmingPools() ([]FarmingPoolType, error)

	// Itin methods
	SetItinData(token dia.ItinToken) error
	GetItinBySymbol(symbol string) (dia.ItinToken, error)

	// Defi rates
	SetDefiProtocol(dia.DefiProtocol) error
	GetDefiProtocol(string) (dia.DefiProtocol, error)
	GetDefiProtocols() ([]dia.DefiProtocol, error)

	GetDefiRateInflux(time.Time, time.Time, string, string) ([]dia.DefiRate, error)
	SetDefiRateInflux(rate *dia.DefiRate) error

	GetDefiStateInflux(time.Time, time.Time, string) ([]dia.DefiProtocolState, error)
	SetDefiStateInflux(state *dia.DefiProtocolState) error

	// Foreign quotation methods
	SaveForeignQuotationInflux(fq ForeignQuotation) error
	GetForeignQuotationInflux(symbol, source string, timestamp time.Time) (ForeignQuotation, error)
	GetForeignPriceYesterday(symbol, source string) (float64, error)
	GetForeignSymbolsInflux(source string) (symbols []SymbolShort, err error)

	// Gold token methods
	GetPaxgQuotationOunces() (*Quotation, error)
	GetPaxgQuotationGrams() (*Quotation, error)
	// Crypto Index methods
	GetCryptoIndex(time.Time, time.Time, string) ([]CryptoIndex, error)
	SetCryptoIndex(index *CryptoIndex) error
	GetCryptoIndexConstituents(time.Time, time.Time, string, string) ([]CryptoIndexConstituent, error)
	SetCryptoIndexConstituent(*CryptoIndexConstituent, string) error
	GetCryptoIndexConstituentPrice(symbol string, date time.Time) (float64, error)
	GetCryptoIndexMintAmounts(symbol string) ([]CryptoIndexMintAmount, error)

	// Github methods
	SetCommit(commit *GithubCommit) error
	GetCommitByDate(user, repository string, date time.Time) (GithubCommit, error)
	GetCommitByHash(user, repository, hash string) (GithubCommit, error)
	GetLatestCommit(user, repository string) (GithubCommit, error)

	// Stock methods
	SetStockQuotation(sq StockQuotation) error
	GetStockQuotation(source string, symbol string, timeInit time.Time, timeFinal time.Time) ([]StockQuotation, error)
	GetStockSymbols() (map[Stock]string, error)
}

type DefiScore

type DefiScore struct {
	Protocol        string
	Symbol          string
	Score           float64
	LiquidityIndex  float64
	CollateralIndex float64
}

type FarmingPool

type FarmingPool struct {
	// Rate is the pool rate. More information: https://docs.diadata.org/documentation/methodology/digital-assets/return-rates-in-crypto-farming
	Rate float64
	// Balance is the total supply of pool token
	Balance      float64
	ProtocolName string
	BlockNumber  int64
	PoolID       string // hold pool id respective to protocol
	TimeStamp    time.Time
	// OutputAsset is the list of tokens that you get back for staking.
	OutputAsset []string
	InputAsset  []string // some pools have more than 2 input assets
}

func (*FarmingPool) MarshalBinary

func (fp *FarmingPool) MarshalBinary() ([]byte, error)

func (*FarmingPool) UnmarshalBinary

func (fp *FarmingPool) UnmarshalBinary(data []byte) error

type FarmingPoolType

type FarmingPoolType struct {
	ProtocolName string
	InputAsset   []string
	PoolID       string
}

type ForeignQuotation

type ForeignQuotation struct {
	Symbol             string
	Name               string
	Price              float64
	PriceYesterday     float64
	VolumeYesterdayUSD float64
	Source             string
	Time               time.Time
	ITIN               string
}

func (*ForeignQuotation) MarshalBinary

func (fq *ForeignQuotation) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*ForeignQuotation) UnmarshalBinary

func (fq *ForeignQuotation) UnmarshalBinary(data []byte) error

UnmarshalBinary -

type GithubCommit

type GithubCommit struct {
	User            string
	Repository      string
	Hash            string
	Timestamp       time.Time
	Author          Author
	NumAdditions    int
	NumDeletions    int
	NumChangedFiles int
	Message         string
}

type InterestRate

type InterestRate struct {
	Symbol          string
	Value           float64
	PublicationTime time.Time
	EffectiveDate   time.Time
	Source          string
}

func (*InterestRate) MarshalBinary

func (e *InterestRate) MarshalBinary() ([]byte, error)

MarshalBinary for interest rates

func (*InterestRate) UnmarshalBinary

func (e *InterestRate) UnmarshalBinary(data []byte) error

UnmarshalBinary for interest rates

type InterestRateMeta

type InterestRateMeta struct {
	Symbol    string
	FirstDate time.Time
	Decimals  int
	Issuer    string
}

type Pairs

type Pairs struct {
	Pairs []dia.Pair
}

type Point

type Point struct {
	UnixTime int64
	Value    float64
}

type Points

type Points struct {
	DataPoints []clientInfluxdb.Result
}

func (*Points) MarshalBinary

func (e *Points) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*Points) UnmarshalBinary

func (e *Points) UnmarshalBinary(data []byte) error

type Price

type Price struct {
	Symbol string
	Name   string
	Price  float64
	Time   time.Time
}

type Quotation

type Quotation struct {
	Symbol             string
	Name               string
	Price              float64
	PriceYesterday     *float64
	VolumeYesterdayUSD *float64
	Source             string
	Time               time.Time
	ITIN               string
}

func (*Quotation) MarshalBinary

func (e *Quotation) MarshalBinary() ([]byte, error)

MarshalBinary for quotations

func (*Quotation) UnmarshalBinary

func (e *Quotation) UnmarshalBinary(data []byte) error

UnmarshalBinary for quotations

type RelDB

type RelDB struct {
	URI string
	// contains filtered or unexported fields
}

RelDB is a relative database with redis caching layer.

func NewCachingLayer

func NewCachingLayer() (*RelDB, error)

NewCachingLayer returns a datastore with redis caching layer and without postgres client.

func NewPostgresDataStore

func NewPostgresDataStore() (*RelDB, error)

NewPostgresDataStore returns a datastore with postgres client and without redis caching layer.

func NewRelDataStore

func NewRelDataStore() (*RelDB, error)

NewRelDataStore returns a datastore with postgres client and redis cache.

func NewRelDataStoreWithOptions

func NewRelDataStoreWithOptions(withPostgres bool, withRedis bool) (*RelDB, error)

NewRelDataStoreWithOptions returns a postgres datastore and/or redis caching layer.

func (*RelDB) GetAllNFTClasses

func (rdb *RelDB) GetAllNFTClasses(blockchain string) (nftClasses []dia.NFTClass, err error)

GetAllNFTClasses returns all NFT classes on @blockchain.

func (*RelDB) GetBlockData added in v1.2.0

func (rdb *RelDB) GetBlockData(blockchain string, blocknumber int64) (dia.BlockData, error)

GetBlockData returns information on the block with @blocknumber on @blockchain.

func (*RelDB) GetKeys

func (rdb *RelDB) GetKeys(table string) (keys []string, err error)

GetKeys returns a slice of strings holding the names of the keys of @table in postgres

func (*RelDB) GetLastBlockBlockscraper added in v1.2.0

func (rdb *RelDB) GetLastBlockBlockscraper(blockchain string) (blockNumber int64, err error)

GetLastBlockBlockscraper returns the last scraped block on @blockchain for block data scrapers.

func (*RelDB) GetLastBlockNFTBid added in v1.2.0

func (rdb *RelDB) GetLastBlockNFTBid(nftclass dia.NFTClass) (blocknumber uint64, err error)

GetLastBlockNFTBid returns the last blocknumber that was scraped in @nftclass.

func (*RelDB) GetLastBlockNFTTradeScraper added in v1.2.0

func (rdb *RelDB) GetLastBlockNFTTradeScraper(nftclass dia.NFTClass) (blocknumber uint64, err error)

func (*RelDB) GetLastBlockheightTopshot added in v1.2.0

func (rdb *RelDB) GetLastBlockheightTopshot(upperBound time.Time) (uint64, error)

GetLastBlockheightTopshot returns the last block number before timestamp given by @upperBound.

func (*RelDB) GetLastNFTBid added in v1.2.0

func (rdb *RelDB) GetLastNFTBid(address string, blockchain string, tokenID string, blockNumber uint64, blockPosition uint) (nftBid dia.NFTBid, err error)

GetLastNFTBid returns the last bid on the nft with @address and @tokenID. Here, 'last' refers to block number and block position smaller or equal (in the case of block number) than @blockNumber and @blockPosition resp.

func (*RelDB) GetLastNFTOffer added in v1.2.0

func (rdb *RelDB) GetLastNFTOffer(address string, blockchain string, tokenID string, blockNumber uint64, blockPosition uint) (offer dia.NFTOffer, err error)

GetLastNFTOffer returns the last offer on the nft with @address and @tokenID. Here, 'last' refers to block number and block position smaller or equal (in the case of block number) than @blockNumber and @blockPosition resp.

func (*RelDB) GetNFT

func (rdb *RelDB) GetNFT(address string, blockchain string, tokenID string) (dia.NFT, error)

func (*RelDB) GetNFTCategories

func (rdb *RelDB) GetNFTCategories() (categories []string, err error)

GetNFTCategories returns all available NFT categories.

func (*RelDB) GetNFTClass

func (rdb *RelDB) GetNFTClass(address string, blockchain string) (nftclass dia.NFTClass, err error)

func (*RelDB) GetNFTClassByID

func (rdb *RelDB) GetNFTClassByID(id string) (nftclass dia.NFTClass, err error)

func (*RelDB) GetNFTClassID

func (rdb *RelDB) GetNFTClassID(address string, blockchain string) (ID string, err error)

func (*RelDB) GetNFTClasses

func (rdb *RelDB) GetNFTClasses(limit, offset uint64) (nftClasses []dia.NFTClass, err error)

GetNFTClassPage returns @limit NFT classes with @offset.

func (*RelDB) GetNFTID added in v1.2.0

func (rdb *RelDB) GetNFTID(address string, blockchain string, tokenID string) (ID string, err error)

func (*RelDB) GetNFTPrice30Days added in v1.2.0

func (rdb *RelDB) GetNFTPrice30Days(nftclass dia.NFTClass) (float64, error)

GetNFTPrice30Days returns the average price of all NFTs in @nftclass over the last 30 days.

func (*RelDB) GetNFTTrades added in v1.2.0

func (rdb *RelDB) GetNFTTrades(nft dia.NFT) (trades []dia.NFTTrade, err error)

GetNFTTrades returns all trades done on @nft.

func (*RelDB) GetScraperConfig added in v1.2.0

func (rdb *RelDB) GetScraperConfig(ctx context.Context, scraperName string, config ScraperConfig) error

func (*RelDB) GetScraperState added in v1.2.0

func (rdb *RelDB) GetScraperState(ctx context.Context, scraperName string, state ScraperState) error

func (*RelDB) SetBlockData added in v1.2.0

func (rdb *RelDB) SetBlockData(blockdata dia.BlockData) error

SetBlockData stores @blockdata in postgres.

func (*RelDB) SetNFT

func (rdb *RelDB) SetNFT(nft dia.NFT) error

func (*RelDB) SetNFTBid added in v1.2.0

func (rdb *RelDB) SetNFTBid(bid dia.NFTBid) error

SetNFTBid stores @bid.

func (*RelDB) SetNFTClass

func (rdb *RelDB) SetNFTClass(nftClass dia.NFTClass) error

SetNFTClass stores @nftClass in postgres.

func (*RelDB) SetNFTOffer added in v1.2.0

func (rdb *RelDB) SetNFTOffer(offer dia.NFTOffer) error

SetNFTOffer stores @offer in postgres.

func (*RelDB) SetNFTTrade

func (rdb *RelDB) SetNFTTrade(trade dia.NFTTrade) error

SetNFTTTrade stores @trade.

func (*RelDB) SetScraperConfig added in v1.2.0

func (rdb *RelDB) SetScraperConfig(ctx context.Context, scraperName string, config ScraperConfig) error

func (*RelDB) SetScraperState added in v1.2.0

func (rdb *RelDB) SetScraperState(ctx context.Context, scraperName string, state ScraperState) error

func (*RelDB) UpdateNFTClassCategory

func (rdb *RelDB) UpdateNFTClassCategory(nftclassID string, category string) (bool, error)

type RelDatastore

type RelDatastore interface {

	// NFT class methods
	SetNFTClass(nftClass dia.NFTClass) error
	GetAllNFTClasses(blockchain string) (nftClasses []dia.NFTClass, err error)
	GetNFTClasses(limit, offset uint64) (nftClasses []dia.NFTClass, err error)
	GetNFTClass(address string, blockchain string) (nftclass dia.NFTClass, err error)
	GetNFTClassID(address string, blockchain string) (ID string, err error)
	GetNFTClassByID(id string) (nftclass dia.NFTClass, err error)
	UpdateNFTClassCategory(nftclassID string, category string) (bool, error)
	GetNFTCategories() ([]string, error)

	// NFT methods
	SetNFT(nft dia.NFT) error
	GetNFT(address string, blockchain string, tokenID string) (dia.NFT, error)
	GetNFTID(address string, blockchain string, tokenID string) (string, error)

	// NFT trading and bidding methods
	SetNFTTrade(trade dia.NFTTrade) error
	GetNFTTrades(nft dia.NFT) ([]dia.NFTTrade, error)
	GetNFTPrice30Days(nftclass dia.NFTClass) (float64, error)
	GetLastBlockheightTopshot(upperBound time.Time) (uint64, error)
	GetLastBlockNFTTradeScraper(nftclass dia.NFTClass) (uint64, error)
	SetNFTBid(bid dia.NFTBid) error
	GetLastNFTBid(address string, blockchain string, tokenID string, blockNumber uint64, blockPosition uint) (dia.NFTBid, error)
	GetLastBlockNFTBid(nftclass dia.NFTClass) (uint64, error)
	SetNFTOffer(offer dia.NFTOffer) error
	GetLastNFTOffer(address string, blockchain string, tokenID string, blockNumber uint64, blockPosition uint) (offer dia.NFTOffer, err error)

	// General methods
	GetKeys(table string) ([]string, error)

	// Scraper config and state
	GetScraperState(ctx context.Context, scraperName string, state ScraperState) error
	SetScraperState(ctx context.Context, scraperName string, state ScraperState) error
	GetScraperConfig(ctx context.Context, scraperName string, config ScraperConfig) error
	SetScraperConfig(ctx context.Context, scraperName string, config ScraperConfig) error

	// Blockchain data
	SetBlockData(dia.BlockData) error
	GetBlockData(blockchain string, blocknumber int64) (dia.BlockData, error)
	GetLastBlockBlockscraper(blockchain string) (int64, error)
}

RelDatastore is a (persistent) relational database with an additional redis caching layer

type ScraperConfig added in v1.2.0

type ScraperConfig interface{}

ScraperConfig is a JSON compatible struct to keep the configuration of a scraper

type ScraperState added in v1.2.0

type ScraperState interface{}

ScraperState is a JSON compatible struct to keep the state of a scraper

type Stock added in v1.4.0

type Stock struct {
	Symbol string
	Name   string
	ISIN   string
}

type StockQuotation added in v1.2.0

type StockQuotation struct {
	Symbol     string
	Name       string
	PriceAsk   float64
	PriceBid   float64
	SizeAskLot float64
	SizeBidLot float64
	Source     string
	Time       time.Time
	ISIN       string
}

type SymbolDetails

type SymbolDetails struct {
	Change    *Change
	Coin      Coin
	Rank      int
	Exchanges []SymbolExchangeDetails
	Gfx1      *Points
}

func (*SymbolDetails) MarshalBinary

func (e *SymbolDetails) MarshalBinary() ([]byte, error)

MarshalBinary -

func (*SymbolDetails) UnmarshalBinary

func (e *SymbolDetails) UnmarshalBinary(data []byte) error

UnmarshalBinary -

type SymbolExchangeDetails

type SymbolExchangeDetails struct {
	Name               string
	Price              float64
	PriceYesterday     *float64
	VolumeYesterdayUSD *float64
	Time               *time.Time
	LastTrades         []dia.Trade
}

type SymbolShort

type SymbolShort struct {
	Symbol string
	ITIN   string
}

Jump to

Keyboard shortcuts

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