provider

package
v0.0.0-...-f42d900 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KrakenRestHost = "https://api.kraken.com"
	KrakenRestPath = "/0/public/AssetPairs"
)

Variables

This section is empty.

Functions

func PastUnixTime

func PastUnixTime(t time.Duration) int64

PastUnixTime returns a millisecond timestamp that represents the unix time minus t.

Types

type AggregatedProviderCandles

type AggregatedProviderCandles map[string]map[string][]CandlePrice

AggregatedProviderCandles defines a type alias for a map of provider -> asset -> []CandlePrice

type AggregatedProviderPrices

type AggregatedProviderPrices map[string]map[string]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 config.ProviderEndpoint,
	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" => {}, "UMEEUSDC" => {}].

func (*BinanceProvider) GetCandlePrices

func (p *BinanceProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]CandlePrice, error)

GetCandlePrices returns the candlePrices based on the provided pairs.

func (*BinanceProvider) GetTickerPrices

func (p *BinanceProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the provided pairs.

func (*BinanceProvider) SubscribeCurrencyPairs

func (p *BinanceProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.

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 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 CandlePrice

type CandlePrice struct {
	Price     sdk.Dec // last trade price
	Volume    sdk.Dec // volume
	TimeStamp int64   // timestamp
}

CandlePrice defines price, volume, and time information for an exchange rate.

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 config.ProviderEndpoint,
	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][]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]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*CoinbaseProvider) SubscribeCurrencyPairs

func (p *CoinbaseProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribes to websockets for all currency pairs.

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 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.

REF: https://www.gate.io/docs/websocket/index.html

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

type GatePairSummary struct {
	Base  string `json:"base"`
	Quote string `json:"quote"`
}

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 config.ProviderEndpoint,
	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][]CandlePrice, error)

GetCandlePrices returns the candlePrices based on the saved map

func (*GateProvider) GetTickerPrices

func (p *GateProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*GateProvider) SubscribeCurrencyPairs

func (p *GateProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe to ticker and candle channels for all pairs.

type GateTicker

type GateTicker struct {
	Last   string `json:"last"`       // Last traded price ex.: 43508.9
	Vol    string `json:"baseVolume"` // Trading volume ex.: 11159.87127845
	Symbol string `json:"symbol"`     // Symbol ex.: ATOM_UDST
}

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 config.ProviderEndpoint,
	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][]CandlePrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*HuobiProvider) GetTickerPrices

func (p *HuobiProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*HuobiProvider) SubscribeCurrencyPairs

func (p *HuobiProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.

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 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 KrakenEventSystemStatus

type KrakenEventSystemStatus struct {
	Status string `json:"status"` // online|maintenance|cancel_only|limit_only|post_only
}

KrakenEventSystemStatus parse the systemStatus 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 config.ProviderEndpoint,
	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][]CandlePrice, error)

GetCandlePrices returns the candlePrices based on the saved map.

func (*KrakenProvider) GetTickerPrices

func (p *KrakenProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*KrakenProvider) SubscribeCurrencyPairs

func (p *KrakenProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.

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 MexcCandle

type MexcCandle struct {
	// Channel  string             `json:"channel"` // expect "push.kline"
	Symbol   string             `json:"symbol"` // Symbol ex.: ATOM_USDT
	Metadata MexcCandleMetadata `json:"data"`   // Metadata for candle
}

MexcCandle candle Mexc websocket channel "kline_1m" response.

type MexcCandleMetadata

type MexcCandleMetadata struct {
	Close     float64 `json:"c"` // Price at close
	TimeStamp int64   `json:"t"` // Close time in unix epoch ex.: 1645756200000
	Volume    float64 `json:"v"` // Volume during period
}

MexcCandleMetadata candle metadata used to compute tvwap price.

type MexcCandleSubscriptionMsg

type MexcCandleSubscriptionMsg struct {
	OP       string `json:"op"`       // kline
	Symbol   string `json:"symbol"`   // streams to subscribe ex.: atom_usdt
	Interval string `json:"interval"` // Min1、Min5、Min15、Min30
}

MexcSubscribeMsg Msg to subscribe all the tickers 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 config.ProviderEndpoint,
	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" => {}, "UMEEUSDC" => {}].

func (*MexcProvider) GetCandlePrices

func (p *MexcProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]CandlePrice, error)

GetCandlePrices returns the candlePrices based on the provided pairs.

func (*MexcProvider) GetTickerPrices

func (p *MexcProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the provided pairs.

func (*MexcProvider) SubscribeCurrencyPairs

func (p *MexcProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.

type MexcTicker

type MexcTicker struct {
	Symbol    string `json:"symbol"` // Symbol ex.: ATOM_USDT
	LastPrice string `json:"p"`      // Last price ex.: 0.0025
	Volume    string `json:"v"`      // Total traded base asset volume ex.: 1000
	C         uint64 `json:"C"`      // Statistics close time
}

type MexcTickerData

type MexcTickerData struct {
	LastPrice float64 `json:"p"` // Last price ex.: 0.0025
	Volume    float64 `json:"v"` // Total traded base asset volume ex.: 1000
}

type MexcTickerResult

type MexcTickerResult struct {
	Channel string                    `json:"channel"` // expect "push.overview"
	Symbol  map[string]MexcTickerData `json:"data"`    // this key is the Symbol ex.: ATOM_USDT
}

type MexcTickerSubscriptionMsg

type MexcTickerSubscriptionMsg struct {
	OP string `json:"op"` // kline
}

MexcSubscribeMsg Msg to subscribe all the tickers 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][]CandlePrice, error)

func (MockProvider) GetTickerPrices

func (p MockProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]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 MockProviderServer

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

func NewMockProviderServer

func NewMockProviderServer() MockProviderServer

func (*MockProviderServer) Close

func (m *MockProviderServer) Close()

func (*MockProviderServer) GetBaseURL

func (m *MockProviderServer) GetBaseURL() string

func (*MockProviderServer) GetWebsocketURL

func (m *MockProviderServer) GetWebsocketURL() string

func (*MockProviderServer) InjectServerCertificatesIntoDefaultDialer

func (m *MockProviderServer) InjectServerCertificatesIntoDefaultDialer()

func (*MockProviderServer) SetHandler

func (m *MockProviderServer) SetHandler(handler http.HandlerFunc)

func (*MockProviderServer) Start

func (m *MockProviderServer) Start()

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

type OkxCandleResponse struct {
	Data [][]string `json:"data"`
	ID   OkxID      `json:"arg"`
}

OkxCandleResponse defines the response structure of a Okx candle request.

type OkxID

type OkxID struct {
	OkxInstID
	Channel string `json:"channel"`
}

OkxInst defines the structure containing ID information for the OkxResponses.

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 config.ProviderEndpoint,
	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 susbscribe.

func (*OkxProvider) GetCandlePrices

func (p *OkxProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[string][]CandlePrice, error)

GetCandlePrices returns the candlePrices based on the saved map

func (*OkxProvider) GetTickerPrices

func (p *OkxProvider) GetTickerPrices(pairs ...types.CurrencyPair) (map[string]TickerPrice, error)

GetTickerPrices returns the tickerPrices based on the saved map.

func (*OkxProvider) SubscribeCurrencyPairs

func (p *OkxProvider) SubscribeCurrencyPairs(cps ...types.CurrencyPair) error

SubscribeCurrencyPairs subscribe all currency pairs into ticker and candle channels.

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 Provider

type Provider interface {
	// GetTickerPrices returns the tickerPrices based on the provided pairs.
	GetTickerPrices(...types.CurrencyPair) (map[string]TickerPrice, error)

	// GetCandlePrices returns the candlePrices based on the provided pairs.
	GetCandlePrices(...types.CurrencyPair) (map[string][]CandlePrice, error)

	// GetAvailablePairs return all available pairs symbol to susbscribe.
	GetAvailablePairs() (map[string]struct{}, error)

	// SubscribeCurrencyPairs subscribe to ticker and candle channels for all pairs.
	SubscribeCurrencyPairs(...types.CurrencyPair) error
}

Provider defines an interface an exchange price provider must implement.

type TickerPrice

type TickerPrice struct {
	Price  sdk.Dec // last trade price
	Volume sdk.Dec // 24h volume
}

TickerPrice defines price and volume information for a symbol or ticker exchange rate.

Jump to

Keyboard shortcuts

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