Back to godoc.org
github.com/adampointer/go-bitmex

Package bitmex

v0.0.0 (b9687ac)
Latest Go to latest
Published: Feb 28, 2020 | License: MIT | Module: github.com/adampointer/go-bitmex

Overview

Package bitmex is an event driven BitMEX client library for which provides a full access to both the REST and websocket APIs.

Index

Package Files

func NewBitmexClient

func NewBitmexClient(config *ClientConfig) *client.BitMEX

NewBitmexClient creates a new REST client

type APITopicHandler

type APITopicHandler func(response *types.SubscriptionResponse)

APITopicHandler is a function called in response to a API subscription event being received

type ClientConfig

type ClientConfig struct {
	HostUrl *url.URL

	ApiKey, ApiSecret     string
	VerboseRequestLogging bool
	RetryOpts             []retry.Option
	// contains filtered or unexported fields
}

ClientConfig holds configuration data for the REST client Rather than using this directly you should generally use the NewClientConfig function and the builder functions

func NewClientConfig

func NewClientConfig() *ClientConfig

NewClientConfig returns a *ClientConfig with the default transport set and the default retry options Default retry is exponential backoff, 10 attempts with an initial delay of 500 milliseconds

func (*ClientConfig) WithAuth

func (c *ClientConfig) WithAuth(apiKey, apiSecret string) *ClientConfig

WithAuth sets the credentials and is optional if you are exclusively using public endpoints

func (*ClientConfig) WithRetryOption

func (c *ClientConfig) WithRetryOption(opt retry.Option) *ClientConfig

WithRetryOption appends a retry option to the defaults

func (*ClientConfig) WithRetryOptions

func (c *ClientConfig) WithRetryOptions(opts ...retry.Option) *ClientConfig

WithRetryOptions sets the request retry options, replacing the defaults

func (*ClientConfig) WithTransport

func (c *ClientConfig) WithTransport(t http.RoundTripper) *ClientConfig

WithTransport allows you to override the underlying transport used by the custom RoundTripper

func (*ClientConfig) WithURL

func (c *ClientConfig) WithURL(u string) *ClientConfig

WithURL sets the url to use e.g. https://testnet.bitmex.com

type EventHandler

type EventHandler func(obj interface{})

EventHandler is a function called in response to websocket events

type WebsocketClient

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

WebsocketClient is a BitMEX websocket client

func NewWebsocketClient

func NewWebsocketClient(cfg *WebsocketClientConfig) *WebsocketClient

NewWebsocketClient returns a new BitMEX websocket client with the logrus standard logger

func (*WebsocketClient) L2OrderBook

func (w *WebsocketClient) L2OrderBook(instrument string, tickSize float64) (*book.Book, error)

L2OrderBook returns a l2 orderbook instance for the specified instrument tickSize must be specified and is the minimum price increment for the contract

func (*WebsocketClient) Restart

func (w *WebsocketClient) Restart()

Restart the websocket connection

func (*WebsocketClient) SendCommand

func (w *WebsocketClient) SendCommand(command *types.Command) error

SendCommand sends command json to the remote

func (*WebsocketClient) SetConfig

func (w *WebsocketClient) SetConfig(cfg *WebsocketClientConfig) *WebsocketClient

SetConfig allows you to set the configuration after struct initialisation

func (*WebsocketClient) Shutdown

func (w *WebsocketClient) Shutdown()

Shutdown closes the websocket and unsubscribes listeners

func (*WebsocketClient) Start

func (w *WebsocketClient) Start()

Start initialises the event bus and connects the websocket

func (*WebsocketClient) SubscribeToApiTopic

func (w *WebsocketClient) SubscribeToApiTopic(topic types.SubscriptionTopic, handler APITopicHandler) error

SubscribeToApiTopic allows you to subscribe to a BitMEX API topic without message ordering guarantees

func (*WebsocketClient) SubscribeToEvents

func (w *WebsocketClient) SubscribeToEvents(evt types.Event, handler EventHandler) error

SubscribeToEvents allows you to register a handler to listen to websocket events

func (*WebsocketClient) SubscribeToOneEvent

func (w *WebsocketClient) SubscribeToOneEvent(evt types.Event, handler EventHandler) error

SubscribeToOneEvent allows you to register a handler to listen to a single websocket event it will be unsubscribed after the first instance automatically

func (*WebsocketClient) UnsubscribeFromApiTopic

func (w *WebsocketClient) UnsubscribeFromApiTopic(topic types.SubscriptionTopic, handler APITopicHandler) error

UnsubscribeFromApiTopic allows you to subscribe a handler from a previously subscribed BitMEX API topic

func (*WebsocketClient) UnsubscribeFromEvents

func (w *WebsocketClient) UnsubscribeFromEvents(evt types.Event, handler EventHandler) error

UnsubscribeFromEvents unsubscribes a previously subscribed handler

func (*WebsocketClient) WithLogWriter

func (w *WebsocketClient) WithLogWriter(o io.Writer) *WebsocketClient

WithLogWriter sets the output stream for the logger

func (*WebsocketClient) WithLogger

func (w *WebsocketClient) WithLogger(l *log.Logger) *WebsocketClient

WithLogger overrides the logrus standard logger with a Logger instance

type WebsocketClientConfig

type WebsocketClientConfig struct {
	ApiKey, ApiSecret, URL string
}

WebSocketClientConfig holds configuration data for the websocket client

func NewWebsocketClientConfig

func NewWebsocketClientConfig() *WebsocketClientConfig

NewWebsocketClientConfig returns a new config struct

func (*WebsocketClientConfig) WithAuth

func (c *WebsocketClientConfig) WithAuth(apiKey, apiSecret string) *WebsocketClientConfig

WithAuth sets the credentials and is optional if you are exclusively using public endpoints

func (*WebsocketClientConfig) WithURL

func (c *WebsocketClientConfig) WithURL(u string) *WebsocketClientConfig

WithURL sets the url to use e.g. wss://testnet.bitmex.com/realtime

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier