Documentation
¶
Index ¶
- Constants
- func PastUnixTime(t time.Duration) int64
- func SecondsToMilli(t int64) int64
- func TelemetryFailure(n Name, mt MessageType)
- type AggregatedProviderCandles
- type AggregatedProviderPrices
- type BinanceCandle
- type BinanceCandleMetadata
- type BinancePairSummary
- type BinanceProvider
- func (p *BinanceProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *BinanceProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *BinanceProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *BinanceProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type BinanceSubscriptionMsg
- type BinanceSubscriptionResp
- type BinanceTicker
- type BitgetCandle
- type BitgetCandleResponse
- type BitgetErrResponse
- type BitgetPairData
- type BitgetPairsSummary
- type BitgetProvider
- func (p *BitgetProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *BitgetProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *BitgetProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *BitgetProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type BitgetSubscriptionArg
- type BitgetSubscriptionMsg
- type BitgetSubscriptionResponse
- type BitgetTicker
- type BitgetTickerData
- type CoinbaseErrResponse
- type CoinbasePairSummary
- type CoinbaseProvider
- func (p *CoinbaseProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *CoinbaseProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *CoinbaseProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *CoinbaseProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type CoinbaseSubscriptionMsg
- type CoinbaseTicker
- type CoinbaseTrade
- type CoinbaseTradeResponse
- type CryptoCandle
- type CryptoCandleResponse
- type CryptoCandleResult
- type CryptoHeartbeatRequest
- type CryptoHeartbeatResponse
- type CryptoInstruments
- type CryptoPairsSummary
- type CryptoProvider
- func (p *CryptoProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *CryptoProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *CryptoProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *CryptoProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type CryptoSubscriptionMsg
- type CryptoSubscriptionParams
- type CryptoTicker
- type CryptoTickerResponse
- type CryptoTickerResult
- type Endpoint
- type GateCandle
- type GateCandleResponse
- type GateCandleSubscriptionMsg
- type GateEvent
- type GateEventResult
- type GatePairSummary
- type GateProvider
- func (p *GateProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *GateProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *GateProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *GateProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type GateTicker
- type GateTickerResponse
- type GateTickerSubscriptionMsg
- type HuobiCandle
- type HuobiCandleTick
- type HuobiPairData
- type HuobiPairsSummary
- type HuobiProvider
- func (p *HuobiProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *HuobiProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *HuobiProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *HuobiProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type HuobiSubscriptionMsg
- type HuobiSubscriptionResp
- type HuobiTick
- type HuobiTicker
- type KrakenCandle
- type KrakenEvent
- type KrakenEventSubscriptionStatus
- type KrakenPairData
- type KrakenPairsSummary
- type KrakenProvider
- func (p *KrakenProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *KrakenProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *KrakenProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *KrakenProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type KrakenSubscriptionChannel
- type KrakenSubscriptionMsg
- type KrakenTicker
- type MessageHandler
- type MessageType
- type MexcCandle
- type MexcCandleResponse
- type MexcCandleSubscription
- type MexcPairSummary
- type MexcProvider
- func (p *MexcProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *MexcProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *MexcProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *MexcProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type MexcTicker
- type MexcTickerResponse
- type MexcTickerSubscription
- type MockProvider
- func (p MockProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p MockProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p MockProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p MockProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error
- type Name
- type OkxCandlePair
- type OkxCandleResponse
- type OkxID
- type OkxInstID
- type OkxPairsSummary
- type OkxProvider
- func (p *OkxProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *OkxProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *OkxProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *OkxProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type OkxSubscriptionMsg
- type OkxSubscriptionTopic
- type OkxTickerPair
- type OkxTickerResponse
- type OsmosisCandleResponse
- type OsmosisPairData
- type OsmosisPairsSummary
- type OsmosisProvider
- func (p OsmosisProvider) GetAvailablePairs() (map[string]struct{}, error)
- func (p OsmosisProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p OsmosisProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p OsmosisProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error
- type OsmosisTokenResponse
- type OsmosisV2Candle
- type OsmosisV2PairData
- type OsmosisV2PairsSummary
- type OsmosisV2Provider
- func (p *OsmosisV2Provider) GetAvailablePairs() (map[string]struct{}, error)
- func (p *OsmosisV2Provider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
- func (p *OsmosisV2Provider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
- func (p *OsmosisV2Provider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
- type OsmosisV2Ticker
- type Provider
- type WebsocketController
Constants ¶
const ( KrakenRestHost = "https://api.kraken.com" KrakenRestPath = "/0/public/AssetPairs" )
const ( MessageTypeCandle = MessageType("candle") MessageTypeTicker = MessageType("ticker") MessageTypeTrade = MessageType("trade") )
Variables ¶
This section is empty.
Functions ¶
func PastUnixTime ¶
PastUnixTime returns a millisecond timestamp that represents the unix time minus t.
func SecondsToMilli ¶
SecondsToMilli converts seconds to milliseconds for our unix timestamps.
func TelemetryFailure ¶
func TelemetryFailure(n Name, mt MessageType)
TelemetryFailure gives an standard way to add `price_feeder_failure_provider{type="x", provider="x"}` metric.
Types ¶
type AggregatedProviderCandles ¶
type AggregatedProviderCandles map[Name]map[string][]types.CandlePrice
AggregatedProviderCandles defines a type alias for a map of provider -> asset -> []types.CandlePrice
type AggregatedProviderPrices ¶
type AggregatedProviderPrices map[Name]map[string]types.TickerPrice
AggregatedProviderPrices defines a type alias for a map of provider -> asset -> TickerPrice
type BinanceCandle ¶
type BinanceCandle struct { Symbol string `json:"s"` // Symbol ex.: BTCUSDT Metadata BinanceCandleMetadata `json:"k"` // Metadata for candle }
BinanceCandle candle binance websocket channel "kline_1m" response.
type BinanceCandleMetadata ¶
type BinanceCandleMetadata struct { Close string `json:"c"` // Price at close TimeStamp int64 `json:"T"` // Close time in unix epoch ex.: 1645756200000 Volume string `json:"v"` // Volume during period }
BinanceCandleMetadata candle metadata used to compute tvwap price.
type BinancePairSummary ¶
type BinancePairSummary struct {
Symbol string `json:"symbol"`
}
BinancePairSummary defines the response structure for a Binance pair summary.
type BinanceProvider ¶
type BinanceProvider struct {
// contains filtered or unexported fields
}
BinanceProvider defines an Oracle provider implemented by the Binance public API.
REF: https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream REF: https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-streams
func NewBinanceProvider ¶
func NewBinanceProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, binanceUS bool, pairs ...types.CurrencyPair, ) (*BinanceProvider, error)
func (*BinanceProvider) GetAvailablePairs ¶
func (p *BinanceProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe. ex.: map["ATOMUSDT" => {}, "NEBULAUSDC" => {}].
func (*BinanceProvider) GetCandlePrices ¶
func (p *BinanceProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the provided pairs.
func (*BinanceProvider) GetTickerPrices ¶
func (p *BinanceProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the provided pairs.
func (*BinanceProvider) SubscribeCurrencyPairs ¶
func (p *BinanceProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type BinanceSubscriptionMsg ¶
type BinanceSubscriptionMsg struct { Method string `json:"method"` // SUBSCRIBE/UNSUBSCRIBE Params []string `json:"params"` // streams to subscribe ex.: usdtatom@ticker ID uint16 `json:"id"` // identify messages going back and forth }
BinanceSubscribeMsg Msg to subscribe all the tickers channels.
type BinanceSubscriptionResp ¶
BinanceSubscriptionResp the response structure for a binance subscription response
type BinanceTicker ¶
type BinanceTicker struct { Symbol string `json:"s"` // Symbol ex.: BTCUSDT LastPrice string `json:"c"` // Last price ex.: 0.0025 Volume string `json:"v"` // Total traded base asset volume ex.: 1000 C uint64 `json:"C"` // Statistics close time }
BinanceTicker ticker price response. https://pkg.go.dev/encoding/json#Unmarshal Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match. C field which is Statistics close time is not used, but it avoids to implement specific UnmarshalJSON.
type BitgetCandle ¶
type BitgetCandle struct { Arg BitgetSubscriptionArg // subscription event argument TimeStamp int64 // unix timestamp in milliseconds e.x. 1597026383085 Close string // Most recent price e.x. "8533.02" Volume string // volume e.x. "45247" }
type BitgetCandleResponse ¶
type BitgetCandleResponse struct { Action string `json:"action"` // e.x. "snapshot" Arg BitgetSubscriptionArg `json:"arg"` // subscription event argument Data [][]string `json:"data"` // candle data in an array at data[0]. }
BitgetCandleResponse is the response structure for the bitget ticker message.
func (BitgetCandleResponse) ToBitgetCandle ¶
func (bcr BitgetCandleResponse) ToBitgetCandle() (BitgetCandle, error)
ToBitgetCandle turns a BitgetCandleResponse into a more-readable BitgetCandle. The Close and Volume responses are at the [0][4] and [0][5] indexes respectively. Ref: https://bitgetlimited.github.io/apidoc/en/spot/#candlesticks-channel
type BitgetErrResponse ¶
type BitgetErrResponse struct { Event string `json:"event"` // e.x. "error" Code uint64 `json:"code"` // e.x. 30003 for invalid op Msg string `json:"msg"` // e.x. "INVALID op" }
BitgetErrResponse is the structure for bitget subscription errors.
type BitgetPairData ¶
type BitgetPairsSummary ¶
type BitgetPairsSummary struct { RespCode string `json:"code"` Data []BitgetPairData `json:"data"` }
BitgetPairsSummary defines the response structure for a Bitget pairs summary.
type BitgetProvider ¶
type BitgetProvider struct {
// contains filtered or unexported fields
}
BitgetProvider defines an Oracle provider implemented by the Bitget public API.
REF: https://bitgetlimited.github.io/apidoc/en/spot/#tickers-channel REF: https://bitgetlimited.github.io/apidoc/en/spot/#candlesticks-channel
func NewBitgetProvider ¶
func NewBitgetProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*BitgetProvider, error)
NewBitgetProvider returns a new Bitget provider with the WS connection and msg handler.
func (*BitgetProvider) GetAvailablePairs ¶
func (p *BitgetProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe.
func (*BitgetProvider) GetCandlePrices ¶
func (p *BitgetProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*BitgetProvider) GetTickerPrices ¶
func (p *BitgetProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*BitgetProvider) SubscribeCurrencyPairs ¶
func (p *BitgetProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type BitgetSubscriptionArg ¶
type BitgetSubscriptionMsg ¶
type BitgetSubscriptionMsg struct { Operation string `json:"op"` // Operation (e.x. "subscribe") Args []BitgetSubscriptionArg `json:"args"` // Arguments to subscribe to }
BitgetSubscriptionMsg Msg to subscribe all at once.
type BitgetSubscriptionResponse ¶
type BitgetSubscriptionResponse struct { Event string `json:"event"` // e.x. "subscribe" Arg BitgetSubscriptionArg `json:"arg"` // subscription event argument }
BitgetSubscriptionResponse is the structure for bitget subscription confirmations.
type BitgetTicker ¶
type BitgetTicker struct { Action string `json:"action"` // e.x. "snapshot" Arg BitgetSubscriptionArg `json:"arg"` // subscription event argument Data []BitgetTickerData `json:"data"` // ticker data }
BitgetTickerResponse is the structure for bitget ticker messages.
type BitgetTickerData ¶
type CoinbaseErrResponse ¶
type CoinbaseErrResponse struct { Type string `json:"type"` // should be "error" Reason string `json:"reason"` // ex.: "tickers" is not a valid channel }
CoinbaseErrResponse defines the response body for errors.
type CoinbasePairSummary ¶
type CoinbasePairSummary struct { Base string `json:"base_currency"` Quote string `json:"quote_currency"` }
CoinbasePairSummary defines the response structure for a Coinbase pair summary.
type CoinbaseProvider ¶
type CoinbaseProvider struct {
// contains filtered or unexported fields
}
CoinbaseProvider defines an Oracle provider implemented by the Coinbase public API.
REF: https://www.coinbase.io/docs/websocket/index.html
func NewCoinbaseProvider ¶
func NewCoinbaseProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*CoinbaseProvider, error)
NewCoinbaseProvider creates a new CoinbaseProvider.
func (*CoinbaseProvider) GetAvailablePairs ¶
func (p *CoinbaseProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe.
func (*CoinbaseProvider) GetCandlePrices ¶
func (p *CoinbaseProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns candles based off of the saved trades map. Candles need to be cut up into one-minute intervals.
func (*CoinbaseProvider) GetTickerPrices ¶
func (p *CoinbaseProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*CoinbaseProvider) SubscribeCurrencyPairs ¶
func (p *CoinbaseProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type CoinbaseSubscriptionMsg ¶
type CoinbaseSubscriptionMsg struct { Type string `json:"type"` // ex. "subscribe" ProductIDs []string `json:"product_ids"` // streams to subscribe ex.: ["BOT-USDT", ...] Channels []string `json:"channels"` // channels to subscribe to ex.: "ticker" }
CoinbaseSubscriptionMsg Msg to subscribe to all channels.
type CoinbaseTicker ¶
type CoinbaseTicker struct { ProductID string `json:"product_id"` // ex.: ATOM-USDT Price string `json:"price"` // ex.: 523.0 Volume string `json:"volume_24h"` // 24-hour volume }
CoinbaseTicker defines the ticker info we'd like to save.
type CoinbaseTrade ¶
type CoinbaseTrade struct { ProductID string // ex.: ATOM-USDT Time int64 // Time in unix epoch ex.: 164732388700 Size string // Size of the trade ex.: 10.41 Price string // ex.: 14.02 }
CoinbaseTrade defines the trade info we'd like to save.
type CoinbaseTradeResponse ¶
type CoinbaseTradeResponse struct { Type string `json:"type"` // "last_match" or "match" ProductID string `json:"product_id"` // ex.: ATOM-USDT Time string `json:"time"` // Time in format 2006-01-02T15:04:05.000000Z Size string `json:"size"` // Size of the trade ex.: 10.41 Price string `json:"price"` // ex.: 14.02 }
CoinbaseMatchResponse defines the response body for coinbase trades.
type CryptoCandle ¶
type CryptoCandleResponse ¶
type CryptoCandleResponse struct {
Result CryptoCandleResult `json:"result"`
}
type CryptoCandleResult ¶
type CryptoCandleResult struct { InstrumentName string `json:"instrument_name"` // ex.: ATOM_USDT Channel string `json:"channel"` // ex.: candlestick Data []CryptoCandle `json:"data"` // candlestick data }
type CryptoHeartbeatRequest ¶
type CryptoHeartbeatResponse ¶
type CryptoInstruments ¶
type CryptoInstruments struct {
Data []CryptoTicker `json:"data"`
}
type CryptoPairsSummary ¶
type CryptoPairsSummary struct {
Result CryptoInstruments `json:"result"`
}
type CryptoProvider ¶
type CryptoProvider struct {
// contains filtered or unexported fields
}
CryptoProvider defines an Oracle provider implemented by the Crypto.com public API.
REF: https://exchange-docs.crypto.com/spot/index.html#introduction
func NewCryptoProvider ¶
func NewCryptoProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*CryptoProvider, error)
func (*CryptoProvider) GetAvailablePairs ¶
func (p *CryptoProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe. ex.: map["ATOMUSDT" => {}, "NEBULAUSDC" => {}].
func (*CryptoProvider) GetCandlePrices ¶
func (p *CryptoProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the saved map
func (*CryptoProvider) GetTickerPrices ¶
func (p *CryptoProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*CryptoProvider) SubscribeCurrencyPairs ¶
func (p *CryptoProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type CryptoSubscriptionMsg ¶
type CryptoSubscriptionMsg struct { ID int64 `json:"id"` Method string `json:"method"` // subscribe, unsubscribe Params CryptoSubscriptionParams `json:"params"` Nonce int64 `json:"nonce"` // Current timestamp (milliseconds since the Unix epoch) }
type CryptoSubscriptionParams ¶
type CryptoSubscriptionParams struct {
Channels []string `json:"channels"` // Channels to be subscribed ex. ticker.ATOM_USDT
}
type CryptoTicker ¶
type CryptoTickerResponse ¶
type CryptoTickerResponse struct {
Result CryptoTickerResult `json:"result"`
}
type CryptoTickerResult ¶
type CryptoTickerResult struct { InstrumentName string `json:"instrument_name"` // ex.: ATOM_USDT Channel string `json:"channel"` // ex.: ticker Data []CryptoTicker `json:"data"` // ticker data }
type Endpoint ¶
type Endpoint struct { // Name of the provider, ex. "binance" Name Name `toml:"name"` // Rest endpoint for the provider, ex. "https://api1.binance.com" Rest string `toml:"rest"` // Websocket endpoint for the provider, ex. "stream.binance.com:9443" Websocket string `toml:"websocket"` }
Endpoint defines an override setting in our config for the hardcoded rest and websocket api endpoints.
type GateCandle ¶
type GateCandle struct { Close string // Closing price TimeStamp int64 // Unix timestamp Volume string // Total candle volume Symbol string // Total symbol }
func (*GateCandle) UnmarshalParams ¶
func (candle *GateCandle) UnmarshalParams(params [][]interface{}) error
UnmarshalParams is a helper function which unmarshals the 2d slice of interfaces from a GateCandleResponse into the GateCandle.
type GateCandleResponse ¶
type GateCandleResponse struct { Method string `json:"method"` Params [][]interface{} `json:"params"` }
GateTickerResponse defines the response body for gate tickers. The Params response is a 2D slice of multiple candles and their data.
type GateCandleSubscriptionMsg ¶
type GateCandleSubscriptionMsg struct { Method string `json:"method"` // ticker.subscribe Params []interface{} `json:"params"` // streams to subscribe ex.: ["BOT_USDT": 1800] ID uint16 `json:"id"` // identify messages going back and forth }
GateCandleSubscriptionMsg Msg to subscribe to a candle channel.
type GateEvent ¶
type GateEvent struct { ID int `json:"id"` // subscription id, ex.: 123 Result GateEventResult `json:"result"` // event result body }
GateEvent defines the response body for gate subscription statuses.
type GateEventResult ¶
type GateEventResult struct {
Status string `json:"status"` // ex. "successful"
}
GateEventResult defines the Result body for the GateEvent response.
type GatePairSummary ¶
GatePairSummary defines the response structure for a Gate pair summary.
type GateProvider ¶
type GateProvider struct {
// contains filtered or unexported fields
}
GateProvider defines an Oracle provider implemented by the Gate public API.
REF: https://www.gate.io/docs/websocket/index.html
func NewGateProvider ¶
func NewGateProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*GateProvider, error)
NewGateProvider creates a new GateProvider.
func (*GateProvider) GetAvailablePairs ¶
func (p *GateProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe.
func (*GateProvider) GetCandlePrices ¶
func (p *GateProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the saved map
func (*GateProvider) GetTickerPrices ¶
func (p *GateProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*GateProvider) SubscribeCurrencyPairs ¶
func (p *GateProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type GateTicker ¶
type GateTickerResponse ¶
type GateTickerResponse struct { Method string `json:"method"` Params []interface{} `json:"params"` }
GateTickerResponse defines the response body for gate tickers.
type GateTickerSubscriptionMsg ¶
type GateTickerSubscriptionMsg struct { Method string `json:"method"` // ticker.subscribe Params []string `json:"params"` // streams to subscribe ex.: BOT_USDT ID uint16 `json:"id"` // identify messages going back and forth }
GateTickerSubscriptionMsg Msg to subscribe all the tickers channels.
type HuobiCandle ¶
type HuobiCandle struct { CH string `json:"ch"` // Channel name. Format:market.$symbol.kline.$period Tick HuobiCandleTick `json:"tick"` }
HuobiCandle defines the response type for the channel and the tick object for a given ticker/symbol.
type HuobiCandleTick ¶
type HuobiCandleTick struct { Close float64 `json:"close"` // Closing price during this period TimeStamp int64 `json:"id"` // TimeStamp for this as an ID Volume float64 `json:"vol"` // Volume during this period }
HuobiCandleTick defines the response type for the candle.
type HuobiPairData ¶
type HuobiPairData struct {
Symbol string `json:"symbol"`
}
HuobiPairData defines the data response structure for an Huobi pair.
type HuobiPairsSummary ¶
type HuobiPairsSummary struct {
Data []HuobiPairData `json:"data"`
}
HuobiPairsSummary defines the response structure for an Huobi pairs summary.
type HuobiProvider ¶
type HuobiProvider struct {
// contains filtered or unexported fields
}
HuobiProvider defines an Oracle provider implemented by the Huobi public API.
REF: https://huobiapi.github.io/docs/spot/v1/en/#market-ticker REF: https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles
func NewHuobiProvider ¶
func NewHuobiProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*HuobiProvider, error)
NewHuobiProvider returns a new Huobi provider with the WS connection and msg handler.
func (*HuobiProvider) GetAvailablePairs ¶
func (p *HuobiProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe.
func (*HuobiProvider) GetCandlePrices ¶
func (p *HuobiProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*HuobiProvider) GetTickerPrices ¶
func (p *HuobiProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*HuobiProvider) SubscribeCurrencyPairs ¶
func (p *HuobiProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type HuobiSubscriptionMsg ¶
type HuobiSubscriptionMsg struct {
Sub string `json:"sub"` // channel to subscribe market.$symbol.ticker
}
HuobiSubscriptionMsg Msg to subscribe to one ticker channel at time.
type HuobiSubscriptionResp ¶
type HuobiSubscriptionResp struct {
Status string `json:"status"`
}
HuobiSubscriptionResp the response structure for a Huobi subscription response
type HuobiTick ¶
type HuobiTick struct { Vol float64 `json:"vol"` // Accumulated trading value of last 24 hours LastPrice float64 `json:"lastPrice"` // Last traded price }
HuobiTick defines the response type for the last 24h market summary and the last traded price for a given ticker/symbol.
type HuobiTicker ¶
type HuobiTicker struct { CH string `json:"ch"` // Channel name. Format:market.$symbol.ticker Tick HuobiTick `json:"tick"` }
HuobiTicker defines the response type for the channel and the tick object for a given ticker/symbol.
type KrakenCandle ¶
type KrakenCandle struct { Close string // Close price during this period TimeStamp int64 // Linux epoch timestamp Volume string // Volume during this period Symbol string // Symbol for this candle }
KrakenCandle candle response from Kraken candle channel. REF: https://docs.kraken.com/websockets/#message-ohlc
func (*KrakenCandle) UnmarshalJSON ¶
func (candle *KrakenCandle) UnmarshalJSON(buf []byte) error
type KrakenEvent ¶
type KrakenEvent struct {
Event string `json:"event"` // events from kraken ex.: systemStatus | subscriptionStatus
}
KrakenEvent wraps the possible events from the provider.
type KrakenEventSubscriptionStatus ¶
type KrakenEventSubscriptionStatus struct { Status string `json:"status"` // subscribed|unsubscribed|error Pair string `json:"pair"` // Pair symbol base/quote ex.: "XBT/USD" ErrorMessage string `json:"errorMessage"` // error description }
KrakenEventSubscriptionStatus parse the subscriptionStatus event message.
type KrakenPairData ¶
type KrakenPairData struct {
WsName string `json:"wsname"`
}
KrakenPairData defines the data response structure for an Kraken pair.
type KrakenPairsSummary ¶
type KrakenPairsSummary struct {
Result map[string]KrakenPairData `json:"result"`
}
KrakenPairsSummary defines the response structure for an Kraken pairs summary.
type KrakenProvider ¶
type KrakenProvider struct {
// contains filtered or unexported fields
}
KrakenProvider defines an Oracle provider implemented by the Kraken public API.
REF: https://docs.kraken.com/websockets/#overview
func NewKrakenProvider ¶
func NewKrakenProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*KrakenProvider, error)
NewKrakenProvider returns a new Kraken provider with the WS connection and msg handler.
func (*KrakenProvider) GetAvailablePairs ¶
func (p *KrakenProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe.
func (*KrakenProvider) GetCandlePrices ¶
func (p *KrakenProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the saved map.
func (*KrakenProvider) GetTickerPrices ¶
func (p *KrakenProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*KrakenProvider) SubscribeCurrencyPairs ¶
func (p *KrakenProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type KrakenSubscriptionChannel ¶
type KrakenSubscriptionChannel struct {
Name string `json:"name"` // channel to be subscribed ex.: ticker
}
KrakenSubscriptionChannel Msg with the channel name to be subscribed.
type KrakenSubscriptionMsg ¶
type KrakenSubscriptionMsg struct { Event string `json:"event"` // subscribe/unsubscribe Pair []string `json:"pair"` // Array of currency pairs ex.: "BTC/USDT", Subscription KrakenSubscriptionChannel `json:"subscription"` // subscription object }
KrakenSubscriptionMsg Msg to subscribe to all the pairs at once.
type KrakenTicker ¶
type KrakenTicker struct { C []string `json:"c"` // Close with Price in the first position V []string `json:"v"` // Volume with the value over last 24 hours in the second position }
KrakenTicker ticker price response from Kraken ticker channel. REF: https://docs.kraken.com/websockets/#message-ticker
type MessageHandler ¶
type MessageType ¶
type MessageType string
func (MessageType) String ¶
func (mt MessageType) String() string
String cast provider MessageType to string.
type MexcCandle ¶
type MexcCandleResponse ¶
type MexcCandleResponse struct { Symbol string `json:"symbol"` // Symbol ex.: ATOM_USDT Metadata MexcCandle `json:"data"` // Metadata for candle }
MexcCandle is the candle websocket response object.
type MexcCandleSubscription ¶
type MexcCandleSubscription struct { OP string `json:"op"` // kline Symbol string `json:"symbol"` // streams to subscribe ex.: atom_usdt Interval string `json:"interval"` // Min1、Min5、Min15、Min30 }
MexcCandleSubscription Msg to subscribe all the candle channels.
type MexcPairSummary ¶
type MexcPairSummary struct {
Symbol string `json:"symbol"`
}
MexcPairSummary defines the response structure for a Mexc pair summary.
type MexcProvider ¶
type MexcProvider struct {
// contains filtered or unexported fields
}
MexcProvider defines an Oracle provider implemented by the Mexc public API.
REF: https://mxcdevelop.github.io/apidocs/spot_v2_en/#ticker-information REF: https://mxcdevelop.github.io/apidocs/spot_v2_en/#k-line REF: https://mxcdevelop.github.io/apidocs/spot_v2_en/#overview
func NewMexcProvider ¶
func NewMexcProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*MexcProvider, error)
func (*MexcProvider) GetAvailablePairs ¶
func (p *MexcProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe. ex.: map["ATOMUSDT" => {}, "NEBULAUSDC" => {}].
func (*MexcProvider) GetCandlePrices ¶
func (p *MexcProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the provided pairs.
func (*MexcProvider) GetTickerPrices ¶
func (p *MexcProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the provided pairs.
func (*MexcProvider) SubscribeCurrencyPairs ¶
func (p *MexcProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type MexcTicker ¶
type MexcTickerResponse ¶
type MexcTickerResponse struct {
Symbol map[string]MexcTicker `json:"data"` // e.x. ATOM_USDT
}
MexcTickerResponse is the ticker price response object.
type MexcTickerSubscription ¶
type MexcTickerSubscription struct {
OP string `json:"op"` // kline
}
MexcTickerSubscription Msg to subscribe all the ticker channels.
type MockProvider ¶
type MockProvider struct {
// contains filtered or unexported fields
}
MockProvider defines a mocked exchange rate provider using a published Google sheets document to fetch mocked/fake exchange rates.
func NewMockProvider ¶
func NewMockProvider() *MockProvider
func (MockProvider) GetAvailablePairs ¶
func (p MockProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs return all available pairs symbol to susbscribe.
func (MockProvider) GetCandlePrices ¶
func (p MockProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
func (MockProvider) GetTickerPrices ¶
func (p MockProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
func (MockProvider) SubscribeCurrencyPairs ¶
func (p MockProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error
SubscribeCurrencyPairs performs a no-op since mock does not use websockets
type Name ¶
type Name string
Name name of an oracle provider. Usually it is an exchange but this can be any provider name that can give token prices examples.: "binance", "osmosis", "kraken".
const ( ProviderKraken Name = "kraken" ProviderBinance Name = "binance" ProviderBinanceUS Name = "binanceus" ProviderOsmosis Name = "osmosis" ProviderOsmosisV2 Name = "osmosisv2" ProviderHuobi Name = "huobi" ProviderOkx Name = "okx" ProviderGate Name = "gate" ProviderCoinbase Name = "coinbase" ProviderBitget Name = "bitget" ProviderMexc Name = "mexc" ProviderCrypto Name = "crypto" ProviderMock Name = "mock" )
type OkxCandlePair ¶
type OkxCandlePair struct { Close string `json:"c"` // Close price for this time period TimeStamp int64 `json:"ts"` // Linux epoch timestamp Volume string `json:"vol"` // Volume for this time period InstID string `json:"instId"` // Instrument ID ex.: BTC-USDT }
OkxCandlePair defines a candle for Okx.
type OkxCandleResponse ¶
OkxCandleResponse defines the response structure of a Okx candle request.
type OkxInstID ¶
type OkxInstID struct {
InstID string `json:"instId"` // Instrument ID ex.: BTC-USDT
}
OkxInstId defines the id Symbol of an pair.
type OkxPairsSummary ¶
type OkxPairsSummary struct {
Data []OkxInstID `json:"data"`
}
OkxPairsSummary defines the response structure for an Okx pairs summary.
type OkxProvider ¶
type OkxProvider struct {
// contains filtered or unexported fields
}
OkxProvider defines an Oracle provider implemented by the Okx public API.
REF: https://www.okx.com/docs-v5/en/#websocket-api-public-channel-tickers-channel
func NewOkxProvider ¶
func NewOkxProvider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*OkxProvider, error)
NewOkxProvider creates a new OkxProvider.
func (*OkxProvider) GetAvailablePairs ¶
func (p *OkxProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs return all available pairs symbol to subscribe.
func (*OkxProvider) GetCandlePrices ¶
func (p *OkxProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the saved map
func (*OkxProvider) GetTickerPrices ¶
func (p *OkxProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*OkxProvider) SubscribeCurrencyPairs ¶
func (p *OkxProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type OkxSubscriptionMsg ¶
type OkxSubscriptionMsg struct { Op string `json:"op"` // Operation ex.: subscribe Args []OkxSubscriptionTopic `json:"args"` }
OkxSubscriptionMsg Message to subscribe/unsubscribe with N Topics.
type OkxSubscriptionTopic ¶
type OkxSubscriptionTopic struct { Channel string `json:"channel"` // Channel name ex.: tickers InstID string `json:"instId"` // Instrument ID ex.: BTC-USDT }
OkxSubscriptionTopic Topic with the ticker to be subscribed/unsubscribed.
type OkxTickerPair ¶
type OkxTickerPair struct { OkxInstID Last string `json:"last"` // Last traded price ex.: 43508.9 Vol24h string `json:"vol24h"` // 24h trading volume ex.: 11159.87127845 }
OkxTickerPair defines a ticker pair of Okx.
type OkxTickerResponse ¶
type OkxTickerResponse struct { Data []OkxTickerPair `json:"data"` ID OkxID `json:"arg"` }
OkxTickerResponse defines the response structure of a Okx ticker request.
type OsmosisCandleResponse ¶
type OsmosisCandleResponse struct { Time int64 `json:"time"` Close float64 `json:"close"` Volume float64 `json:"volume"` }
OsmosisCandleResponse defines the response structure for an Osmosis candle request.
type OsmosisPairData ¶
OsmosisPairData defines the data response structure for an Osmosis pair.
type OsmosisPairsSummary ¶
type OsmosisPairsSummary struct {
Data []OsmosisPairData `json:"data"`
}
OsmosisPairsSummary defines the response structure for an Osmosis pairs summary.
type OsmosisProvider ¶
type OsmosisProvider struct {
// contains filtered or unexported fields
}
OsmosisProvider defines an Oracle provider implemented by the Osmosis public API.
REF: https://api-osmosis.imperator.co/swagger/
func NewOsmosisProvider ¶
func NewOsmosisProvider(endpoint Endpoint) *OsmosisProvider
func (OsmosisProvider) GetAvailablePairs ¶
func (p OsmosisProvider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs return all available pairs symbol to susbscribe.
func (OsmosisProvider) GetCandlePrices ¶
func (p OsmosisProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
func (OsmosisProvider) GetTickerPrices ¶
func (p OsmosisProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
func (OsmosisProvider) SubscribeCurrencyPairs ¶
func (p OsmosisProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error
SubscribeCurrencyPairs performs a no-op since osmosis does not use websockets
type OsmosisTokenResponse ¶
type OsmosisTokenResponse struct { Price float64 `json:"price"` Symbol string `json:"symbol"` Volume float64 `json:"volume_24h"` }
OsmosisTokenResponse defines the response structure for an Osmosis token request.
type OsmosisV2Candle ¶
type OsmosisV2PairData ¶
type OsmosisV2PairData struct { Base string `json:"base_symbol"` Quote string `json:"quote_symbol"` }
OsmosisV2PairData defines the data response structure for an Osmosis pair.
type OsmosisV2PairsSummary ¶
type OsmosisV2PairsSummary struct {
Data []OsmosisPairData `json:"data"`
}
OsmosisV2PairsSummary defines the response structure for an Osmosis pairs summary.
type OsmosisV2Provider ¶
type OsmosisV2Provider struct {
// contains filtered or unexported fields
}
OsmosisV2Provider defines an Oracle provider implemented by NEBULA's Osmosis API.
REF: https://github.com/umee-network/osmosis-api
func NewOsmosisV2Provider ¶
func NewOsmosisV2Provider( ctx context.Context, logger zerolog.Logger, endpoints Endpoint, pairs ...types.CurrencyPair, ) (*OsmosisV2Provider, error)
func (*OsmosisV2Provider) GetAvailablePairs ¶
func (p *OsmosisV2Provider) GetAvailablePairs() (map[string]struct{}, error)
GetAvailablePairs returns all pairs to which the provider can subscribe. ex.: map["ATOMUSDT" => {}, "NEBULAUSDC" => {}].
func (*OsmosisV2Provider) GetCandlePrices ¶
func (p *OsmosisV2Provider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]types.CandlePrice, error)
GetCandlePrices returns the candlePrices based on the saved map
func (*OsmosisV2Provider) GetTickerPrices ¶
func (p *OsmosisV2Provider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]types.TickerPrice, error)
GetTickerPrices returns the tickerPrices based on the saved map.
func (*OsmosisV2Provider) SubscribeCurrencyPairs ¶
func (p *OsmosisV2Provider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error
SubscribeCurrencyPairs sends the new subscription messages to the websocket and adds them to the providers subscribedPairs array
type OsmosisV2Ticker ¶
type Provider ¶
type Provider interface { // GetTickerPrices returns the tickerPrices based on the provided pairs. GetTickerPrices(...types.CurrencyPair) (map[string]types.TickerPrice, error) // GetCandlePrices returns the candlePrices based on the provided pairs. GetCandlePrices(...types.CurrencyPair) (map[string][]types.CandlePrice, error) // GetAvailablePairs return all available pairs symbol to subscribe. GetAvailablePairs() (map[string]struct{}, error) // SubscribeCurrencyPairs sends subscription messages for the new currency // pairs and adds them to the providers subscribed pairs SubscribeCurrencyPairs(...types.CurrencyPair) error }
Provider defines an interface an exchange price provider must implement.
type WebsocketController ¶
type WebsocketController struct {
// contains filtered or unexported fields
}
WebsocketController defines a provider agnostic websocket handler that manages reconnecting, subscribing, and receiving messages
func NewWebsocketController ¶
func NewWebsocketController( ctx context.Context, providerName Name, websocketURL url.URL, subscriptionMsgs []interface{}, messageHandler MessageHandler, pingDuration time.Duration, pingMessageType uint, logger zerolog.Logger, ) *WebsocketController
NewWebsocketController does nothing except initialize a new WebsocketController and provider a reminder for what fields need to be passed in.
func (*WebsocketController) AddSubscriptionMsgs ¶
func (wsc *WebsocketController) AddSubscriptionMsgs(msgs []interface{}) error
AddSubscriptionMsgs immediately sends the new subscription messages and adds them to the subscriptionMsgs array if successful
func (*WebsocketController) SendJSON ¶
func (wsc *WebsocketController) SendJSON(msg interface{}) error
SendJSON sends a json message to the websocket connection using the Websocket Controller mutex to ensure multiple writes do not happen at once
func (*WebsocketController) Start ¶
func (wsc *WebsocketController) Start()
Start will continuously loop and attempt connecting to the websocket until a successful connection is made. It then starts the ping service and read listener in new go routines and sends subscription messages using the passed in subscription messages