Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertBytesToJsonNumberArray(raw_bytes []byte) ([]interface{}, error)
- type Asynchronous
- type AsynchronousFactory
- type AuthEvent
- type AuthState
- type BookFactory
- func (f *BookFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
- func (f *BookFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
- func (s BookFactory) Close()
- func (s BookFactory) ListenDisconnect() <-chan error
- func (s BookFactory) Reset() []*subscription
- type CandlesFactory
- func (f *CandlesFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
- func (f *CandlesFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
- func (s CandlesFactory) Close()
- func (s CandlesFactory) ListenDisconnect() <-chan error
- func (s CandlesFactory) Reset() []*subscription
- type Capabilities
- type Capability
- type Client
- func New() *Client
- func NewWithAsyncFactory(async AsynchronousFactory) *Client
- func NewWithAsyncFactoryNonce(async AsynchronousFactory, nonce utils.NonceGenerator) *Client
- func NewWithParams(params *Parameters) *Client
- func NewWithParamsAsyncFactory(params *Parameters, async AsynchronousFactory) *Client
- func NewWithParamsAsyncFactoryNonce(params *Parameters, async AsynchronousFactory, nonce utils.NonceGenerator) *Client
- func NewWithParamsNonce(params *Parameters, nonce utils.NonceGenerator) *Client
- func (c *Client) CancelOnDisconnect(cxl bool) *Client
- func (c *Client) Close()
- func (c *Client) Connect() error
- func (c *Client) Credentials(key string, secret string) *Client
- func (c *Client) EnableFlag(ctx context.Context, flag int) (string, error)
- func (c *Client) GetOrderbook(symbol string) (*Orderbook, error)
- func (c *Client) IsConnected() bool
- func (c *Client) Listen() <-chan interface{}
- func (c *Client) LookupSubsIDByChannel(symbol, channel string) (string, error)
- func (c *Client) LookupSubsIDsBySymbol(symbol string) (ret []string)
- func (c *Client) LookupSubscription(subID string) (*SubscriptionRequest, error)
- func (c *Client) Send(ctx context.Context, msg interface{}) error
- func (c *Client) SubmitCancel(ctx context.Context, cancel *bitfinex.OrderCancelRequest) error
- func (c *Client) SubmitCancelMulti(ctx context.Context, cancelMulti *bitfinex.MultiOrderCancelRequest) error
- func (c *Client) SubmitOrder(ctx context.Context, order *bitfinex.OrderNewRequest) error
- func (c *Client) SubmitUpdateOrder(ctx context.Context, orderUpdate *bitfinex.OrderUpdateRequest) error
- func (c *Client) Subscribe(ctx context.Context, req *SubscriptionRequest) (string, error)
- func (c *Client) SubscribeBook(ctx context.Context, symbol string, precision bitfinex.BookPrecision, ...) (string, error)
- func (c *Client) SubscribeCandles(ctx context.Context, symbol string, resolution bitfinex.CandleResolution) (string, error)
- func (c *Client) SubscribeTicker(ctx context.Context, symbol string) (string, error)
- func (c *Client) SubscribeTrades(ctx context.Context, symbol string) (string, error)
- func (c *Client) Unsubscribe(ctx context.Context, id string) error
- type ConfEvent
- type ErrorEvent
- type FlagRequest
- type InfoEvent
- type Orderbook
- func (ob *Orderbook) Asks() []bitfinex.BookUpdate
- func (ob *Orderbook) Bids() []bitfinex.BookUpdate
- func (ob *Orderbook) Checksum() uint32
- func (ob *Orderbook) SetWithSnapshot(bs *bitfinex.BookUpdateSnapshot)
- func (ob *Orderbook) Symbol() string
- func (ob *Orderbook) UpdateWith(bu *bitfinex.BookUpdate)
- type Parameters
- type PlatformInfo
- type RawEvent
- type SubscribeEvent
- type SubscriptionRequest
- type SubscriptionSet
- type TickerFactory
- func (f *TickerFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
- func (f *TickerFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
- func (s TickerFactory) Close()
- func (s TickerFactory) ListenDisconnect() <-chan error
- func (s TickerFactory) Reset() []*subscription
- type TradeFactory
- func (f *TradeFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
- func (f *TradeFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
- func (s TradeFactory) Close()
- func (s TradeFactory) ListenDisconnect() <-chan error
- func (s TradeFactory) Reset() []*subscription
- type UnsubscribeEvent
- type UnsubscribeRequest
- type WebsocketAsynchronousFactory
Constants ¶
const ( ChanBook = "book" ChanTrades = "trades" ChanTicker = "ticker" ChanCandles = "candles" )
Available channels
const ( EventSubscribe = "subscribe" EventUnsubscribe = "unsubscribe" EventPing = "ping" )
Events
const ( ErrorCodeUnknownEvent int = 10000 ErrorCodeUnknownPair int = 10001 ErrorCodeUnknownBookPrecision int = 10011 ErrorCodeUnknownBookLength int = 10012 ErrorCodeSubscriptionFailed int = 10300 ErrorCodeAlreadySubscribed int = 10301 ErrorCodeUnknownChannel int = 10302 ErrorCodeUnsubscribeFailed int = 10400 ErrorCodeNotSubscribed int = 10401 )
error codes pulled from v2 docs & API usage
const DMSCancelOnDisconnect int = 4
DMSCancelOnDisconnect cancels session orders on disconnect.
Variables ¶
var ( ErrWSNotConnected = fmt.Errorf("websocket connection not established") ErrWSAlreadyConnected = fmt.Errorf("websocket connection already established") )
ws-specific errors
Functions ¶
Types ¶
type Asynchronous ¶
type Asynchronous interface { Connect() error Send(ctx context.Context, msg interface{}) error Listen() <-chan []byte Close() Done() <-chan error }
Asynchronous interface decouples the underlying transport from API logic.
type AsynchronousFactory ¶
type AsynchronousFactory interface {
Create() Asynchronous
}
AsynchronousFactory provides an interface to re-create asynchronous transports during reconnect events.
func NewWebsocketAsynchronousFactory ¶
func NewWebsocketAsynchronousFactory(parameters *Parameters) AsynchronousFactory
NewWebsocketAsynchronousFactory creates a new websocket factory with a given URL.
type AuthEvent ¶
type AuthEvent struct { Event string `json:"event"` Status string `json:"status"` ChanID int64 `json:"chanId,omitempty"` UserID int64 `json:"userId,omitempty"` SubID string `json:"subId"` AuthID string `json:"auth_id,omitempty"` Message string `json:"msg,omitempty"` Caps Capabilities `json:"caps"` }
type AuthState ¶
type AuthState authState // prevent user construction of authStates
AuthState provides a typed authentication state.
type BookFactory ¶
type BookFactory struct {
// contains filtered or unexported fields
}
func (*BookFactory) Build ¶
func (f *BookFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
func (*BookFactory) BuildSnapshot ¶
func (f *BookFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
func (BookFactory) Close ¶
func (s BookFactory) Close()
Close is terminal. Do not call heartbeat after close.
func (BookFactory) ListenDisconnect ¶
func (s BookFactory) ListenDisconnect() <-chan error
ListenDisconnect returns an error channel which receives a message when a heartbeat has expired a channel.
type CandlesFactory ¶
type CandlesFactory struct {
// contains filtered or unexported fields
}
func (*CandlesFactory) Build ¶
func (f *CandlesFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
func (*CandlesFactory) BuildSnapshot ¶
func (f *CandlesFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
func (CandlesFactory) Close ¶
func (s CandlesFactory) Close()
Close is terminal. Do not call heartbeat after close.
func (CandlesFactory) ListenDisconnect ¶
func (s CandlesFactory) ListenDisconnect() <-chan error
ListenDisconnect returns an error channel which receives a message when a heartbeat has expired a channel.
type Capabilities ¶
type Capabilities struct { Orders Capability `json:"orders"` Account Capability `json:"account"` Funding Capability `json:"funding"` History Capability `json:"history"` Wallets Capability `json:"wallets"` Withdraw Capability `json:"withdraw"` Positions Capability `json:"positions"` }
type Capability ¶
type Client ¶
type Client struct { Authentication AuthState // contains filtered or unexported fields }
Client provides a unified interface for users to interact with the Bitfinex V2 Websocket API. nolint:megacheck,structcheck
func NewWithAsyncFactory ¶
func NewWithAsyncFactory(async AsynchronousFactory) *Client
NewWithAsyncFactory creates a new default client with a given asynchronous transport factory interface.
func NewWithAsyncFactoryNonce ¶
func NewWithAsyncFactoryNonce(async AsynchronousFactory, nonce utils.NonceGenerator) *Client
NewWithAsyncFactoryNonce creates a new default client with a given asynchronous transport factory and nonce generator.
func NewWithParams ¶
func NewWithParams(params *Parameters) *Client
NewWithParams creates a new default client with a given set of parameters.
func NewWithParamsAsyncFactory ¶
func NewWithParamsAsyncFactory(params *Parameters, async AsynchronousFactory) *Client
NewWithParamsAsyncFactory creates a new default client with a given set of parameters and asynchronous transport factory interface.
func NewWithParamsAsyncFactoryNonce ¶
func NewWithParamsAsyncFactoryNonce(params *Parameters, async AsynchronousFactory, nonce utils.NonceGenerator) *Client
NewWithParamsAsyncFactoryNonce creates a new client with a given set of parameters, asynchronous transport factory, and nonce generator interfaces.
func NewWithParamsNonce ¶
func NewWithParamsNonce(params *Parameters, nonce utils.NonceGenerator) *Client
NewWithParamsNonce creates a new default client with a given set of parameters and nonce generator.
func (*Client) CancelOnDisconnect ¶
CancelOnDisconnect ensures all orders will be canceled if this API session is disconnected.
func (*Client) Close ¶
func (c *Client) Close()
Close provides an interface for a user initiated shutdown. Close will close the Done() channel.
func (*Client) Credentials ¶
Credentials assigns authentication credentials to a connection request.
func (*Client) EnableFlag ¶
func (*Client) IsConnected ¶
IsConnected returns true if the underlying asynchronous transport is connected to an endpoint.
func (*Client) Listen ¶
func (c *Client) Listen() <-chan interface{}
Listen provides an atomic interface for receiving API messages. When a websocket connection is terminated, the publisher channel will close.
func (*Client) LookupSubsIDByChannel ¶
LookupSubsIDByChannel looks up a subscription request by name and channel.
func (*Client) LookupSubsIDsBySymbol ¶
LookupSubsIDsBySymbol looks up a subscription IDs request by symbol.
func (*Client) LookupSubscription ¶
func (c *Client) LookupSubscription(subID string) (*SubscriptionRequest, error)
LookupSubscription looks up a subscription request by ID
func (*Client) SubmitCancel ¶
SubmitCancel sends a cancel request.
func (*Client) SubmitCancelMulti ¶
func (c *Client) SubmitCancelMulti(ctx context.Context, cancelMulti *bitfinex.MultiOrderCancelRequest) error
SubmitCancelMulti sends a multi cancel request.
func (*Client) SubmitOrder ¶
SubmitOrder sends an order request.
func (*Client) SubmitUpdateOrder ¶
func (*Client) Subscribe ¶
Subscribe sends a subscription request to the Bitfinex API and tracks the subscription status by ID.
func (*Client) SubscribeBook ¶
func (c *Client) SubscribeBook(ctx context.Context, symbol string, precision bitfinex.BookPrecision, frequency bitfinex.BookFrequency, priceLevel int) (string, error)
SubscribeBook sends a subscription request for market data for a given symbol, at a given frequency, with a given precision, returning no more than priceLevels price entries. Default values are Precision0, Frequency0, and priceLevels=25.
func (*Client) SubscribeCandles ¶
func (c *Client) SubscribeCandles(ctx context.Context, symbol string, resolution bitfinex.CandleResolution) (string, error)
SubscribeCandles sends a subscription request for OHLC candles.
func (*Client) SubscribeTicker ¶
SubscribeTicker sends a subscription request for the ticker.
func (*Client) SubscribeTrades ¶
SubscribeTrades sends a subscription request for the trade feed.
type ErrorEvent ¶
type ErrorEvent struct { Code int `json:"code"` Message string `json:"msg"` // also contain members related to subscription reject SubID string `json:"subId"` Channel string `json:"channel"` ChanID int64 `json:"chanId"` Symbol string `json:"symbol"` Precision string `json:"prec,omitempty"` Frequency string `json:"freq,omitempty"` Key string `json:"key,omitempty"` Len string `json:"len,omitempty"` Pair string `json:"pair"` }
type FlagRequest ¶
type InfoEvent ¶
type InfoEvent struct { Version float64 `json:"version"` ServerId string `json:"serverId"` Platform PlatformInfo `json:"platform"` Code int `json:"code"` Msg string `json:"msg"` }
type Orderbook ¶
type Orderbook struct {
// contains filtered or unexported fields
}
func (*Orderbook) SetWithSnapshot ¶
func (ob *Orderbook) SetWithSnapshot(bs *bitfinex.BookUpdateSnapshot)
func (*Orderbook) UpdateWith ¶
func (ob *Orderbook) UpdateWith(bu *bitfinex.BookUpdate)
type Parameters ¶
type Parameters struct { AutoReconnect bool ReconnectInterval time.Duration ReconnectAttempts int ShutdownTimeout time.Duration Logger *logger.LoggerType ResubscribeOnReconnect bool HeartbeatTimeout time.Duration LogTransport bool URL string ManageOrderbook bool // contains filtered or unexported fields }
Parameters defines adapter behavior.
func NewDefaultParameters ¶
func NewDefaultParameters(name, logLevel string) *Parameters
type PlatformInfo ¶
type PlatformInfo struct {
Status int `json:"status"`
}
type SubscribeEvent ¶
type SubscribeEvent struct { SubID string `json:"subId"` Channel string `json:"channel"` ChanID int64 `json:"chanId"` Symbol string `json:"symbol"` Precision string `json:"prec,omitempty"` Frequency string `json:"freq,omitempty"` Key string `json:"key,omitempty"` Len string `json:"len,omitempty"` Pair string `json:"pair"` }
type SubscriptionRequest ¶
type SubscriptionRequest struct { SubID string `json:"subId"` Event string `json:"event"` // authenticated APIKey string `json:"apiKey,omitempty"` AuthSig string `json:"authSig,omitempty"` AuthPayload string `json:"authPayload,omitempty"` AuthNonce string `json:"authNonce,omitempty"` Filter []string `json:"filter,omitempty"` DMS int `json:"dms,omitempty"` // dead man switch // unauthenticated Channel string `json:"channel,omitempty"` Symbol string `json:"symbol,omitempty"` Precision string `json:"prec,omitempty"` Frequency string `json:"freq,omitempty"` Key string `json:"key,omitempty"` Len string `json:"len,omitempty"` Pair string `json:"pair,omitempty"` }
func (*SubscriptionRequest) String ¶
func (s *SubscriptionRequest) String() string
type SubscriptionSet ¶
type SubscriptionSet []*subscription
SubscriptionSet is a typed version of an array of subscription pointers, intended to meet the sortable interface. We need to sort Reset()'s return values for tests with more than 1 subscription (range map order is undefined)
func (SubscriptionSet) Len ¶
func (s SubscriptionSet) Len() int
func (SubscriptionSet) Less ¶
func (s SubscriptionSet) Less(i, j int) bool
func (SubscriptionSet) Swap ¶
func (s SubscriptionSet) Swap(i, j int)
type TickerFactory ¶
type TickerFactory struct {
// contains filtered or unexported fields
}
func (*TickerFactory) Build ¶
func (f *TickerFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
func (*TickerFactory) BuildSnapshot ¶
func (f *TickerFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
func (TickerFactory) Close ¶
func (s TickerFactory) Close()
Close is terminal. Do not call heartbeat after close.
func (TickerFactory) ListenDisconnect ¶
func (s TickerFactory) ListenDisconnect() <-chan error
ListenDisconnect returns an error channel which receives a message when a heartbeat has expired a channel.
type TradeFactory ¶
type TradeFactory struct {
// contains filtered or unexported fields
}
func (*TradeFactory) Build ¶
func (f *TradeFactory) Build(chanID int64, objType string, raw []interface{}, raw_bytes []byte) (interface{}, error)
func (*TradeFactory) BuildSnapshot ¶
func (f *TradeFactory) BuildSnapshot(chanID int64, raw [][]float64, raw_bytes []byte) (interface{}, error)
func (TradeFactory) Close ¶
func (s TradeFactory) Close()
Close is terminal. Do not call heartbeat after close.
func (TradeFactory) ListenDisconnect ¶
func (s TradeFactory) ListenDisconnect() <-chan error
ListenDisconnect returns an error channel which receives a message when a heartbeat has expired a channel.
type UnsubscribeEvent ¶
type UnsubscribeRequest ¶
type WebsocketAsynchronousFactory ¶
type WebsocketAsynchronousFactory struct {
// contains filtered or unexported fields
}
WebsocketAsynchronousFactory creates a websocket-based asynchronous transport.
func (*WebsocketAsynchronousFactory) Create ¶
func (w *WebsocketAsynchronousFactory) Create() Asynchronous
Create returns a new websocket transport.