Documentation ¶
Index ¶
- Constants
- Variables
- func UseLogger(logger slog.Logger)
- type AddressState
- type AgendaAPIResponse
- type AgendaVoteChoices
- type BaseState
- type BinanceTickerResponse
- type BittrexMarketSummaryResponse
- type BittrexTickerResponse
- type BlockDataBasic
- type CommonRateSource
- func (cs *CommonRateSource) AddRateListener(listener *RateListener, uniqueID string) error
- func (cs *CommonRateSource) GetTicker(market string, cacheOnly bool) *Ticker
- func (cs *CommonRateSource) LastUpdate() time.Time
- func (cs *CommonRateSource) Name() string
- func (cs *CommonRateSource) Ready() bool
- func (cs *CommonRateSource) Refresh(force bool)
- func (cs *CommonRateSource) Refreshing() bool
- func (cs *CommonRateSource) RemoveRateListener(uniqueID string)
- func (cs *CommonRateSource) ToggleSource(newSource string) error
- func (cs *CommonRateSource) ToggleStatus(disable bool)
- type ExchangeRates
- type ExchangeState
- type KuCoinTicker
- type RateListener
- type RateSource
- type Service
- func (s *Service) GetAddress(address string) (addressState *AddressState, err error)
- func (s *Service) GetAgendaDetails(agendaID string) (agendaDetails *AgendaAPIResponse, err error)
- func (s *Service) GetAgendas() (agendas *[]apiTypes.AgendasInfo, err error)
- func (s *Service) GetBestBlock() int32
- func (s *Service) GetBestBlockTimeStamp() int64
- func (s *Service) GetCurrentAgendaStatus() (agenda *chainjson.GetVoteInfoResult, err error)
- func (s *Service) GetExchangeRate() (rates *ExchangeRates, err error)
- func (s *Service) GetExchanges() (state *ExchangeState, err error)
- func (s *Service) GetNHighestTicketDetails(nHighest int) (ticketDetails *apiTypes.MempoolTicketDetails, err error)
- func (s *Service) GetNHighestTicketFeeRate(nHighest int) (ticketFeeRate *apiTypes.MempoolTicketFees, err error)
- func (s *Service) GetTicketDetails() (ticketDetails *apiTypes.MempoolTicketDetails, err error)
- func (s *Service) GetTicketFeeRate() (ticketFeeRate *apiTypes.MempoolTicketFees, err error)
- func (s *Service) GetTicketFeeRateSummary() (ticketInfo *apiTypes.MempoolTicketFeeInfo, err error)
- func (s *Service) GetTreasuryBalance() (bal int64, err error)
- func (s *Service) GetTreasuryDetails() (treasuryDetails *TreasuryDetails, err error)
- func (s *Service) GetXpub(xPub string) (xPubBalAndTxs *XpubBalAndTxs, err error)
- type Ticker
- type TreasuryDetails
- type WebsocketProcessor
- type XpubAddress
- type XpubBalAndTxs
Constants ¶
const ( // These are method names for expected bittrex specific websocket messages. BittrexMsgHeartbeat = "heartbeat" BittrexMarketSummary = "marketSummary" BittrexTicker = "ticker" // MktSep is used repo wide to separate market symbols. MktSep = "-" )
const ( BlockBook = "blockbook" DcrData = "dcrdata" )
Variables ¶
var ( // Rate sources should be refreshed every RateRefreshDuration to replace // expired rates and reconnect websocket if need be. RateRefreshDuration = 60 * time.Minute )
Functions ¶
Types ¶
type AddressState ¶
type AddressState struct { Address string `json:"address"` Balance int64 `json:"balance,string"` TotalReceived int64 `json:"totalReceived,string"` TotalSent int64 `json:"totalSent,string"` UnconfirmedBalance int64 `json:"unconfirmedBalance,string"` UnconfirmedTxs int64 `json:"unconfirmedTxs"` Txs int32 `json:"txs"` TxIds []string `json:"txids"` }
AddressState models the address balances and transactions.
type AgendaAPIResponse ¶
type AgendaAPIResponse struct { ByHeight *AgendaVoteChoices `json:"by_height"` ByTime *AgendaVoteChoices `json:"by_time"` }
AgendaAPIResponse holds two sets of AgendaVoteChoices charts data.
type AgendaVoteChoices ¶
type AgendaVoteChoices struct { Abstain []uint64 `json:"abstain"` Yes []uint64 `json:"yes"` No []uint64 `json:"no"` Total []uint64 `json:"total"` Height []uint64 `json:"height,omitempty"` Time []time.Time `json:"time,omitempty"` }
AgendaVoteChoices contains the vote counts on multiple intervals of time. The interval length may be either a single block, in which case Height contains the block heights, or a day, in which case Time contains the time stamps of each interval. Total is always the sum of Yes, No, and Abstain.
type BaseState ¶
type BaseState struct { Price float64 `json:"price"` // BaseVolume is poorly named. This is the volume in terms of (usually) // BTC, not the base asset of any particular market. BaseVolume float64 `json:"base_volume,omitempty"` Volume float64 `json:"volume,omitempty"` Change float64 `json:"change,omitempty"` Stamp int64 `json:"timestamp,omitempty"` }
BaseState are the non-iterable fields of the ExchangeState, which embeds BaseState.
type BinanceTickerResponse ¶ added in v1.1.0
type BinanceTickerResponse struct { Symbol string `json:"symbol"` LastPrice float64 `json:"lastPrice,string"` PriceChangePercent float64 `json:"priceChangePercent,string"` }
BinanceTickerResponse models binance specific ticker information.
type BittrexMarketSummaryResponse ¶ added in v1.1.0
type BittrexMarketSummaryResponse struct { Symbol string `json:"symbol"` PercentChange float64 `json:"percentChange,string"` }
BittrexMarketSummaryResponse is the response from markets/{market}/summary.
type BittrexTickerResponse ¶ added in v1.1.0
type BittrexTickerResponse struct { Symbol string `json:"symbol"` LastTradeRate float64 `json:"lastTradeRate,string"` }
BittrexTickerResponse models bittrex specific ticker information from markets/{market}/ticker.
type BlockDataBasic ¶
type BlockDataBasic struct { Height uint32 `json:"height"` Size uint32 `json:"size"` Hash string `json:"hash"` Difficulty float64 `json:"diff"` StakeDiff float64 `json:"sdiff"` Time types.TimeAPI `json:"time"` NumTx uint32 `json:"txlength"` MiningFee *int64 `json:"fees,omitempty"` TotalSent *int64 `json:"total_sent,omitempty"` // TicketPoolInfo may be nil for side chain blocks. PoolInfo *types.TicketPoolInfo `json:"ticket_pool,omitempty"` }
BlockDataBasic models primary information about a block.
type CommonRateSource ¶ added in v1.1.0
type CommonRateSource struct {
// contains filtered or unexported fields
}
CommonRateSource is an external rate source for fiat and crypto-currency rates. These rates are estimates and maybe be affected by server latency and should not be used for actual buy or sell orders except to display reasonable estimates. CommonRateSource is embedded in all of the rate sources supported.
func NewCommonRateSource ¶ added in v1.1.0
func NewCommonRateSource(ctx context.Context, source string) (*CommonRateSource, error)
Used to initialize a rate source.
func (*CommonRateSource) AddRateListener ¶ added in v1.1.0
func (cs *CommonRateSource) AddRateListener(listener *RateListener, uniqueID string) error
func (*CommonRateSource) GetTicker ¶ added in v1.1.0
func (cs *CommonRateSource) GetTicker(market string, cacheOnly bool) *Ticker
GetTicker retrieves ticker information for the provided market. Data will be retrieved from cache if its available and still valid. Returns nil if valid, cached isn't available and cacheOnly is true. If cacheOnly is false and no valid, cached data is available, a network call will be made to fetch the latest ticker information and update the cache.
func (*CommonRateSource) LastUpdate ¶ added in v1.1.0
func (cs *CommonRateSource) LastUpdate() time.Time
func (*CommonRateSource) Name ¶ added in v1.1.0
func (cs *CommonRateSource) Name() string
Name is the string associated with the rate source for display.
func (*CommonRateSource) Ready ¶ added in v1.1.0
func (cs *CommonRateSource) Ready() bool
func (*CommonRateSource) Refresh ¶ added in v1.1.0
func (cs *CommonRateSource) Refresh(force bool)
Refresh refreshes all expired rates and reconnects the rates websocket if it was previously disconnect. This method takes some time to refresh the rates and should be executed a a goroutine.
func (*CommonRateSource) Refreshing ¶ added in v1.1.0
func (cs *CommonRateSource) Refreshing() bool
func (*CommonRateSource) RemoveRateListener ¶ added in v1.1.0
func (cs *CommonRateSource) RemoveRateListener(uniqueID string)
func (*CommonRateSource) ToggleSource ¶ added in v1.1.0
func (cs *CommonRateSource) ToggleSource(newSource string) error
ToggleSource changes the rate source to newSource. This method takes some time to refresh the rates and should be executed a a goroutine.
func (*CommonRateSource) ToggleStatus ¶ added in v1.1.0
func (cs *CommonRateSource) ToggleStatus(disable bool)
type ExchangeRates ¶
type ExchangeRates struct { BtcIndex string `json:"btcIndex"` DcrPrice float64 `json:"dcrPrice"` BtcPrice float64 `json:"btcPrice"` Exchanges map[string]BaseState `json:"exchanges"` }
ExchangeRates is the dcr and btc prices converted to fiat.
type ExchangeState ¶
type ExchangeState struct { BtcIndex string `json:"btc_index"` BtcPrice float64 `json:"btc_fiat_price"` Price float64 `json:"price"` Volume float64 `json:"volume"` DcrBtc map[string]*ExchangeState `json:"dcr_btc_exchanges"` FiatIndices map[string]*ExchangeState `json:"btc_indices"` }
ExchangeState models the dcrdata supported exchanges state.
type KuCoinTicker ¶
type KuCoinTicker struct { Code int `json:"code,string"` Data struct { Time int64 `json:"time"` Sequence int64 `json:"sequence,string"` Price float64 `json:"price,string"` Size float64 `json:"size,string"` BestBid float64 `json:"bestBid,string"` BestBidSize float64 `json:"bestBidSize,string"` BestAsk float64 `json:"bestAsk,string"` BestAskSize float64 `json:"bestAskSize,string"` } `json:"data"` }
KuCoinTicker models Kucoin's specific ticker information.
type RateListener ¶ added in v1.1.0
type RateListener struct {
OnRateUpdated func()
}
RateListener listens for new tickers and rate source change notifications.
type RateSource ¶ added in v1.1.0
type RateSource interface { Name() string Ready() bool Refresh(force bool) Refreshing() bool LastUpdate() time.Time GetTicker(market string, cacheOnly bool) *Ticker ToggleStatus(disable bool) ToggleSource(newSource string) error AddRateListener(listener *RateListener, uniqueID string) error RemoveRateListener(uniqueID string) }
RateSource is the interface that binds different rate sources. Most of the methods are implemented by CommonRateSource, but Refresh is implemented in the individual rate source.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provide functionality for retrieving data from 3rd party services or external resources.
func NewService ¶
NewService configures and return a news instance of the service type.
func (*Service) GetAddress ¶
func (s *Service) GetAddress(address string) (addressState *AddressState, err error)
GetAddress returns the balances and transactions of an address. The returned transactions are sorted by block height, newest blocks first.
func (*Service) GetAgendaDetails ¶
func (s *Service) GetAgendaDetails(agendaID string) (agendaDetails *AgendaAPIResponse, err error)
GetAgendaDetails returns the details for agenda with agendaId
func (*Service) GetAgendas ¶
func (s *Service) GetAgendas() (agendas *[]apiTypes.AgendasInfo, err error)
GetAgendas returns all agendas high level details
func (*Service) GetBestBlock ¶
GetBestBlock returns the best block height as int32.
func (*Service) GetBestBlockTimeStamp ¶
GetBestBlockTimeStamp returns best block time, as unix timestamp.
func (*Service) GetCurrentAgendaStatus ¶
func (s *Service) GetCurrentAgendaStatus() (agenda *chainjson.GetVoteInfoResult, err error)
GetCurrentAgendaStatus returns the current agenda and its status.
func (*Service) GetExchangeRate ¶
func (s *Service) GetExchangeRate() (rates *ExchangeRates, err error)
GetExchangeRate fetches exchange rate data summary.
func (*Service) GetExchanges ¶
func (s *Service) GetExchanges() (state *ExchangeState, err error)
GetExchanges fetches the current known state of all exchanges.
func (*Service) GetNHighestTicketDetails ¶
func (s *Service) GetNHighestTicketDetails(nHighest int) (ticketDetails *apiTypes.MempoolTicketDetails, err error)
GetNHighestTicketDetails returns the {nHighest} ticket details.
func (*Service) GetNHighestTicketFeeRate ¶
func (s *Service) GetNHighestTicketFeeRate(nHighest int) (ticketFeeRate *apiTypes.MempoolTicketFees, err error)
GetNHighestTicketFeeRate returns the {nHighest} ticket fees. For cases where total number of ticker is less than {nHighest} it returns the fee rate for the total number of tickets.
func (*Service) GetTicketDetails ¶
func (s *Service) GetTicketDetails() (ticketDetails *apiTypes.MempoolTicketDetails, err error)
GetTicketDetails returns all ticket details see drcdata's MempoolTicketDetails for the specific information returned.
func (*Service) GetTicketFeeRate ¶
func (s *Service) GetTicketFeeRate() (ticketFeeRate *apiTypes.MempoolTicketFees, err error)
GetTicketFeeRate returns top 25 ticket fees. Note: in cases where n < 25 and n == number of all ticket fees, It returns n.
func (*Service) GetTicketFeeRateSummary ¶
func (s *Service) GetTicketFeeRateSummary() (ticketInfo *apiTypes.MempoolTicketFeeInfo, err error)
GetTicketFeeRateSummary returns the current ticket fee rate summary. See dcrdata's MempoolTicketFeeInfo for the specific data returned.
func (*Service) GetTreasuryBalance ¶
GetTreasuryBalance returns the current treasury balance as int64.
func (*Service) GetTreasuryDetails ¶
func (s *Service) GetTreasuryDetails() (treasuryDetails *TreasuryDetails, err error)
GetTreasuryDetails the current treasury balance, spent amount, added amount, and tx count for the treasury.
type Ticker ¶
type Ticker struct { Market string LastTradePrice float64 PriceChangePercent *float64 // contains filtered or unexported fields }
Ticker is the generic ticker information that is returned to a caller of GetTicker function.
type TreasuryDetails ¶
type TreasuryDetails struct { Height int64 `json:"height"` MaturityHeight int64 `json:"maturity_height"` Balance int64 `json:"balance"` TxCount int64 `json:"output_count"` AddCount int64 `json:"add_count"` Added int64 `json:"added"` SpendCount int64 `json:"spend_count"` Spent int64 `json:"spent"` TBaseCount int64 `json:"tbase_count"` TBase int64 `json:"tbase"` ImmatureCount int64 `json:"immature_count"` Immature int64 `json:"immature"` }
TreasuryDetails is the current balance, spent amount, and tx count for the treasury.
type WebsocketProcessor ¶ added in v1.1.0
WebsocketProcessor is a callback for new websocket messages from the server.
type XpubAddress ¶
type XpubAddress struct { Address string `json:"name"` Path string `json:"path"` Transfers int32 `json:"transfers"` Decimals int32 `json:"decimals"` Balance int64 `json:"balance,string"` TotalReceived int64 `json:"totalReceived,string"` TotalSent int64 `json:"totalSent,string"` }
XpubAddress models data about a specific xpub token.
type XpubBalAndTxs ¶
type XpubBalAndTxs struct { Xpub string `json:"address"` Balance int64 `json:"balance,string"` TotalReceived int64 `json:"totalReceived,string"` TotalSent int64 `json:"totalSent,string"` UnconfirmedBalance int64 `json:"unconfirmedBalance,string"` UnconfirmedTxs int64 `json:"unconfirmedTxs"` Txs int32 `json:"txs"` TxIds []string `json:"txids"` UsedTokens int32 `json:"usedTokens"` XpubAddress []XpubAddress `json:"tokens"` }
XpubBalAndTxs models xpub transactions and balance.