dia

package
v1.3.6-rc-8 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: GPL-2.0 Imports: 15 Imported by: 56

Documentation

Index

Constants

View Source
const (
	AnyswapExchange    = "Anyswap"
	BalancerExchange   = "Balancer"
	GnosisExchange     = "Gnosis"
	KrakenExchange     = "Kraken"
	BitfinexExchange   = "Bitfinex"
	BinanceExchange    = "Binance"
	FTXExchange        = "FTX"
	Opyn               = "OPYN"
	Premia             = "Premia"
	BitBayExchange     = "BitBay"
	BittrexExchange    = "Bittrex"
	CoinBaseExchange   = "CoinBase"
	HitBTCExchange     = "HitBTC"
	SimexExchange      = "Simex"
	OKExExchange       = "OKEx"
	HuobiExchange      = "Huobi"
	LBankExchange      = "LBank"
	GateIOExchange     = "GateIO"
	ZBExchange         = "ZB"
	QuoineExchange     = "Quoine"
	UnknownExchange    = "Unknown"
	BlockSizeSeconds   = 120
	FilterKing         = "MAIR120"
	BancorExchange     = "Bancor"
	UniswapExchange    = "Uniswap"
	UniswapExchangeV3  = "UniswapV3"
	LoopringExchange   = "Loopring"
	CurveFIExchange    = "Curvefi"
	MakerExchange      = "Maker"
	KuCoinExchange     = "KuCoin"
	SushiSwapExchange  = "SushiSwap"
	PanCakeSwap        = "PanCakeSwap"
	DforceExchange     = "Dforce"
	ZeroxExchange      = "0x"
	KyberExchange      = "Kyber"
	BitMaxExchange     = "Bitmax"
	CREX24Exchange     = "CREX24"
	STEXExchange       = "STEX"
	Deribit            = "Deribit"
	DfynNetwork        = "DFYN"
	UbeswapExchange    = "Ubeswap"
	SpookyswapExchange = "Spookyswap"
	SpiritswapExchange = "Spiritswap"
	QuickswapExchange  = "Quickswap"
	SerumExchange      = "Serum"
	SolarbeamExchange  = "Solarbeam"
	TrisolarisExchange = "Trisolaris"
)
View Source
const (
	Diadata                                 = "diadata.org"
	PROOF_OF_STAKE    VerificationMechanism = "pos"
	PROOF_OF_WORK     VerificationMechanism = "pow"
	BITCOIN                                 = "Bitcoin"
	ETHEREUM                                = "Ethereum"
	BINANCESMARTCHAIN                       = "BinanceSmartChain"
	POLYGON                                 = "Polygon"
	CELO                                    = "Celo"
	FANTOM                                  = "Fantom"
	NEAR                                    = "Near"
	AURORA                                  = "Aurora"
	SOLANA                                  = "Solana"
	FLOW                                    = "Flow"
	MOONRIVER                               = "Moonriver"
	AVALANCHE                               = "Avalanche"
	FIAT                                    = "Fiat"
)
View Source
const BaseUrl string = "https://api.diadata.org/"

Variables

This section is empty.

Functions

func ContainsExchangePair added in v1.2.0

func ContainsExchangePair(pairs []ExchangePair, pair ExchangePair) bool

ContainsExchangePair returns true iff @pair is contained in pairs. Here, equality refers to the unique identifier (exchange,foreignName).

func Exchanges

func Exchanges() []string

func GetAllSymbolsFromPairs added in v1.2.0

func GetAllSymbolsFromPairs(pairs []ExchangePair) ([]string, error)

GetAllSymbolsFromPairs returns a unique list of symbols which constitute @pairs.

func GetPairSymbols added in v1.2.0

func GetPairSymbols(pair ExchangePair) ([]string, error)

GetPairSymbols returns the two symbol tickers of @pair.

func GetSymbolsList

func GetSymbolsList(url string) ([]string, error)

TODO remove URL

Types

type Asset added in v1.2.0

type Asset struct {
	Symbol     string
	Name       string
	Address    string
	Decimals   uint8
	Blockchain string
}

Asset is the data type for all assets, ranging from fiat to crypto.

func GetAllAssetsFromPairs added in v1.2.0

func GetAllAssetsFromPairs(pairs []ExchangePair) (assets []Asset)

GetAllAssetsFromPairs returns the unique slice of assets underlying the exchange pairs @pairs.

func (*Asset) MarshalBinary added in v1.2.0

func (a *Asset) MarshalBinary() ([]byte, error)

MarshalBinary is a custom marshaller for Asset type

func (*Asset) UnmarshalBinary added in v1.2.0

func (a *Asset) UnmarshalBinary(data []byte) error

UnmarshalBinary is a custom unmarshaller for Asset type

type BlockChain

type BlockChain struct {
	Name string `json:"Name"`
	// Genesis date is a Unix timestamp
	GenesisDate int64 `json:"GenesisDate"`
	NativeToken Asset `json:"NativeToken"`
	// Verificationmechanism is in short notation, such as pos for proof-of-stake
	VerificationMechanism VerificationMechanism `json:"VerificationMechanism"`
	// ChainID refers to EVM based chains and is thereby optional.
	ChainID string `json:"ChainID"`
}

BlockChain is the type for blockchains. Uniquely defined by its @Name.

func (*BlockChain) MarshalBinary added in v1.2.0

func (bc *BlockChain) MarshalBinary() ([]byte, error)

MarshalBinary is a custom marshaller for BlockChain type

func (*BlockChain) UnmarshalBinary added in v1.2.0

func (bc *BlockChain) UnmarshalBinary(data []byte) error

UnmarshalBinary is a custom unmarshaller for BlockChain type

type BlockData added in v1.2.0

type BlockData struct {
	// Name of the blockchain, as found for instance in dia.ETHEREUM
	BlockchainName string
	// In order to keep it general, BlockNumber is a string
	BlockNumber int64
	Data        map[string]interface{}
}

BlockData stores information on a specific block in a given blockchain.

type Client

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

func NewClient

func NewClient(config *ConfigApi) *Client

func NewClientWithUrl

func NewClientWithUrl(config *ConfigApi, url string) *Client

func (*Client) DoRequest

func (c *Client) DoRequest(req *http.Request, refresh bool) ([]byte, error)

func (*Client) SendSupply

func (c *Client) SendSupply(s *Supply) error

func (*Client) SendSupplyWithForceOption

func (c *Client) SendSupplyWithForceOption(s *Supply, force bool) error

type ConfigApi

type ConfigApi struct {
	ApiKey    string
	SecretKey string
}

func GetConfig

func GetConfig(exchange string) (*ConfigApi, error)

func GetConfigApi

func GetConfigApi() *ConfigApi

func GetConfigFromEnv added in v1.2.0

func GetConfigFromEnv(exchange string) (*ConfigApi, error)

type ConfigConnector

type ConfigConnector struct {
	Coins []ExchangePair
}

type CviDataPoint

type CviDataPoint struct {
	Timestamp time.Time
	Value     float64
}

type DefiProtocol

type DefiProtocol struct {
	Name                 string
	Address              string
	UnderlyingBlockchain string
	Token                string
}

func (*DefiProtocol) MarshalBinary

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

MarshalBinary for DefiProtocol

func (*DefiProtocol) UnmarshalBinary

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

UnmarshalBinary for DefiProtocol

type DefiProtocolState

type DefiProtocolState struct {
	TotalUSD  float64
	TotalETH  float64
	Timestamp time.Time
	Protocol  DefiProtocol
}

func (*DefiProtocolState) MarshalBinary

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

MarshalBinary for DefiProtocolState

func (*DefiProtocolState) UnmarshalBinary

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

UnmarshalBinary for DefiProtocolState

type DefiRate

type DefiRate struct {
	Timestamp     time.Time
	LendingRate   float64
	BorrowingRate float64
	Asset         string
	Protocol      string
}

func (*DefiRate) MarshalBinary

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

MarshalBinary for DefiRate

func (*DefiRate) UnmarshalBinary

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

UnmarshalBinary for DefiRate

type EthereumBlockData added in v1.2.0

type EthereumBlockData struct {
	GasLimit    uint64             `json:"gas_limit"`
	GasUsed     uint64             `json:"gas_used"`
	Difficulty  *big.Int           `json:"difficulty"`
	Time        uint64             `json:"time"`
	Size        common.StorageSize `json:"size"`
	Number      uint64             `json:"number"`
	MixDigest   common.Hash        `json:"mix_digest"`
	Nonce       uint64             `json:"nonce"`
	Coinbase    common.Address     `json:"coinbase"`
	Root        common.Hash        `json:"root"`
	ParentHash  common.Hash        `json:"parent_hash"`
	TxHash      common.Hash        `json:"tx_hash"`
	ReceiptHash common.Hash        `json:"receipt_hash"`
	UncleHash   common.Hash        `json:"uncle_hash"`
	Extra       []byte             `json:"extra"`
}

type Exchange

type Exchange struct {
	Name          string         `json:"Name"`
	Centralized   bool           `json:"Centralized"`
	Contract      common.Address `json:"Contract"`
	BlockChain    BlockChain     `json:"BlockChain"`
	WatchdogDelay int            `json:"WatchdogDelay"`
}

type ExchangePair added in v1.2.0

type ExchangePair struct {
	Symbol         string
	ForeignName    string
	Exchange       string
	Verified       bool
	UnderlyingPair Pair
}

ExchangePair is the container for a pair as used by exchanges. Across exchanges, these pairs cannot be uniquely mapped on asset pairs.

func MergeExchangePairs added in v1.2.0

func MergeExchangePairs(pairs1, pairs2 []ExchangePair) []ExchangePair

MergeExchangePairs appends @pairs2 to @pairs1 without repetition.

func (*ExchangePair) MarshalBinary added in v1.2.0

func (ep *ExchangePair) MarshalBinary() ([]byte, error)

MarshalBinary is a custom marshaller for ExchangePair type

func (*ExchangePair) UnmarshalBinary added in v1.2.0

func (ep *ExchangePair) UnmarshalBinary(data []byte) error

UnmarshalBinary is a custom unmarshaller for ExchangePair type

type FilterPoint

type FilterPoint struct {
	Asset Asset
	Value float64
	Name  string
	Time  time.Time
}

FilterPoint contains the resulting value of a filter applied to an asset.

type FiltersBlock

type FiltersBlock struct {
	BlockHash        string
	FiltersBlockData FiltersBlockData
}

func (*FiltersBlock) MarshalBinary

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

MarshalBinary -

func (*FiltersBlock) UnmarshalBinary

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

UnmarshalBinary -

type FiltersBlockData

type FiltersBlockData struct {
	TradesBlockHash string
	BeginTime       time.Time
	EndTime         time.Time
	FilterPoints    []FilterPoint
	FiltersNumber   int
}

type IndexBlock

type IndexBlock struct {
	BlockHash      string
	IndexBlockData IndexBlockData
}

func (IndexBlock) Hash

func (ib IndexBlock) Hash() string

func (*IndexBlock) MarshalBinary

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

MarshalBinary -

func (*IndexBlock) UnmarshalBinary

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

UnmarshalBinary -

type IndexBlockData

type IndexBlockData struct {
	FiltersBlockHash    string
	SuppliesBlockHash   string
	VolatilityBlockHash string
	IndexElements       []IndexElement
	IndexElementsNumber int
	Time                time.Time
	IndexValue          float64
	ValueTokenette      float64
	ValueToken          float64
	USDPerPointsOfIndex float64
}

type IndexElement

type IndexElement struct {
	Name            string
	Symbol          string
	Percentage      float64
	FilteredPoint   FilterPoint
	Supply          Supply
	VolatilityRatio VolatilityRatio
}

type ItinToken

type ItinToken struct {
	Itin               string
	Symbol             string
	Label              string
	Url_website        string
	Coinmarketcap_url  string
	Coinmarketcap_slug string
}

func (*ItinToken) MarshalBinary

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

MarshalBinary -

func (*ItinToken) UnmarshalBinary

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

UnmarshalBinary -

type NFT

type NFT struct {
	NFTClass       NFTClass
	TokenID        string
	CreationTime   time.Time
	CreatorAddress string
	URI            string
	// @Attributes is a collection of attributes from on- and off-chain
	// TO DO: Should we split up into two fields?
	Attributes NFTAttributes
}

NFT is the container for a specific NFT defined by the pair (address,tokenID).

func (*NFT) MarshalBinary

func (n *NFT) MarshalBinary() ([]byte, error)

MarshalBinary for DefiProtocolState

func (*NFT) UnmarshalBinary

func (n *NFT) UnmarshalBinary(data []byte) error

UnmarshalBinary for DefiProtocolState

type NFTAttributes

type NFTAttributes map[string]interface{}

NFTAttributes can be stored as jasonb in postgres: https://www.alexedwards.net/blog/using-postgresql-jsonb

func (*NFTAttributes) Scan

func (a *NFTAttributes) Scan(value interface{}) error

func (NFTAttributes) Value

func (a NFTAttributes) Value() (driver.Value, error)

type NFTBid added in v1.2.0

type NFTBid struct {
	NFT         NFT
	Value       *big.Int
	FromAddress string

	CurrencySymbol   string
	CurrencyAddress  string
	CurrencyDecimals int32

	BlockNumber   uint64
	BlockPosition uint64
	Timestamp     time.Time
	TxHash        string
	Exchange      string
}

func (*NFTBid) MarshalBinary added in v1.2.0

func (nb *NFTBid) MarshalBinary() ([]byte, error)

MarshalBinary for DefiProtocolState

func (*NFTBid) UnmarshalBinary added in v1.2.0

func (nb *NFTBid) UnmarshalBinary(data []byte) error

UnmarshalBinary for DefiProtocolState

type NFTClass

type NFTClass struct {
	Address      string
	Symbol       string
	Name         string
	Blockchain   string
	ContractType string
	Category     string
}

NFTClass is the container for an nft class defined by a contract (address) on a blockchain.

func (*NFTClass) MarshalBinary

func (nc *NFTClass) MarshalBinary() ([]byte, error)

MarshalBinary for DefiProtocolState

func (*NFTClass) UnmarshalBinary

func (nc *NFTClass) UnmarshalBinary(data []byte) error

UnmarshalBinary for DefiProtocolState

type NFTOffer added in v1.2.0

type NFTOffer struct {
	NFT NFT
	// Start and EndValue are for auction types. Otherwise, use StartValue
	// and leave EndValue blank.
	StartValue *big.Int
	EndValue   *big.Int
	// Duration of the offer/auction measured in seconds
	Duration    time.Duration
	FromAddress string
	// Type of offer can be auction, simple offer,...
	AuctionType string

	CurrencySymbol   string
	CurrencyAddress  string
	CurrencyDecimals int32

	BlockNumber   uint64
	BlockPosition uint64
	Timestamp     time.Time
	TxHash        string
	Exchange      string
}

func (*NFTOffer) MarshalBinary added in v1.2.0

func (no *NFTOffer) MarshalBinary() ([]byte, error)

MarshalBinary for DefiProtocolState

func (*NFTOffer) UnmarshalBinary added in v1.2.0

func (no *NFTOffer) UnmarshalBinary(data []byte) error

UnmarshalBinary for DefiProtocolState

type NFTTrade

type NFTTrade struct {
	NFT              NFT
	Price            *big.Int
	PriceUSD         float64
	FromAddress      string
	ToAddress        string
	CurrencySymbol   string
	CurrencyAddress  string
	CurrencyDecimals int32
	BlockNumber      uint64
	Timestamp        time.Time
	TxHash           string
	Exchange         string
}

func (*NFTTrade) MarshalBinary

func (ns *NFTTrade) MarshalBinary() ([]byte, error)

MarshalBinary for DefiProtocolState

func (*NFTTrade) UnmarshalBinary

func (ns *NFTTrade) UnmarshalBinary(data []byte) error

UnmarshalBinary for DefiProtocolState

type OptionMeta

type OptionMeta struct {
	InstrumentName string
	BaseCurrency   string
	ExpirationTime time.Time
	StrikePrice    float64
	OptionType     OptionType
}

func (*OptionMeta) MarshalBinary

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

func (*OptionMeta) UnmarshalBinary

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

type OptionMetaForward

type OptionMetaForward struct {
	GeneralizedInstrumentName string
	StrikePrice               float64
	CallPrice                 float64
	PutPrice                  float64 // this, as well as the above is defined as the bid price at a given strike price
	ExpirationTime            time.Time
}

type OptionMetaIndex

type OptionMetaIndex struct {
	OptionMeta
	OptionOrderbookDatum
}

type OptionOrderbookDatum

type OptionOrderbookDatum struct {
	InstrumentName  string
	ObservationTime time.Time
	AskPrice        float64
	BidPrice        float64
	AskSize         float64
	BidSize         float64
	StrikePrice     float64
	ExpirationTime  time.Time
}

type OptionType

type OptionType int
const (
	CallOption OptionType = iota + 1
	PutOption
)

signals if the option is call or a put

type Pair

type Pair struct {
	BaseToken  Asset
	QuoteToken Asset
}

Pair substitues the old dia.Pair. It includes the new asset type.

func (*Pair) ForeignName

func (p *Pair) ForeignName() string

ForeignName returns the foreign name of the pair @p, i.e. the string Quotetoken-Basetoken

type Pairs

type Pairs []ExchangePair

func (*Pairs) MarshalBinary

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

MarshalBinary -

func (*Pairs) UnmarshalBinary

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

UnmarshalBinary -

type SuppliesBlock

type SuppliesBlock struct {
	BlockHash string
	BlockData SuppliesBlockData
}

func (*SuppliesBlock) MarshalBinary

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

MarshalBinary -

func (*SuppliesBlock) UnmarshalBinary

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

UnmarshalBinary -

type SuppliesBlockData

type SuppliesBlockData struct {
	Time     time.Time
	Supplies []Supply
}

type Supply

type Supply struct {
	Asset             Asset
	Supply            float64
	CirculatingSupply float64
	Source            string
	Time              time.Time
}

func GetSupply

func GetSupply(symbol string) (*Supply, error)

func (*Supply) MarshalBinary

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

MarshalBinary -

func (*Supply) UnmarshalBinary

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

UnmarshalBinary -

type Symbols

type Symbols struct {
	Symbols []string
}

type Trade

type Trade struct {
	// TO DO: Deprecated fields. Delete as soon as token-to-type branch is deployed.
	Symbol string
	Pair   string
	// Final fields for trade
	QuoteToken        Asset
	BaseToken         Asset
	Price             float64
	Volume            float64 // Quantity of bought/sold units of Quote token. Negative if result of Market order Sell
	Time              time.Time
	ForeignTradeID    string
	EstimatedUSDPrice float64 // will be filled by the TradesBlockService
	Source            string
	VerifiedPair      bool // will be filled by the pairDiscoveryService
}

Trade remark: In a pair A-B, we call A the Quote token and B the Base token

func SwapTrade

func SwapTrade(t Trade) (Trade, error)

SwapTrade swaps base and quote token of a trade and inverts the price accordingly

func (*Trade) GetBaseToken added in v1.2.0

func (t *Trade) GetBaseToken() string

GetBaseToken returns the base token of a trading pair TO DO (20/11/2020): This method is no longer needed once we switch to new Token/Trade structs

func (*Trade) MarshalBinary

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

MarshalBinary -

func (*Trade) UnmarshalBinary

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

UnmarshalBinary -

type TradesBlock

type TradesBlock struct {
	BlockHash       string
	TradesBlockData TradesBlockData
}

func (*TradesBlock) MarshalBinary

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

MarshalBinary -

func (*TradesBlock) UnmarshalBinary

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

UnmarshalBinary -

type TradesBlockData

type TradesBlockData struct {
	BeginTime    time.Time
	EndTime      time.Time
	TradesNumber int
	Trades       []Trade
}

type VerificationMechanism

type VerificationMechanism string

type VolatilityRatio

type VolatilityRatio struct {
	Symbol    string
	Threehold float64
	DaysAbove int64
	DaysBelow int64
	Time      time.Time
	Selected  bool
}

Directories

Path Synopsis
nft
scraper
service

Jump to

Keyboard shortcuts

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