deribit

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 22 Imported by: 2

README

forked from github.com/adampointer/go-deribit

go-deribit

import "github.com/cicdteam/go-deribit"

GoDoc API Documentation

Overview

Go library for using the Deribit's v2 Websocket API.

Deribit is a modern, fast BitCoin derivatives exchange.

This library is a port of the official wrapper libraries to Go.

V2 API Documentation

Example Usage

Look at cmd/example/main.go

make build
example --access-key XXX --secret-key YYYYYY

Reconnect Behaviour

There is a heartbeat which triggers every 10 seconds to keep the websocket connection alive. In the event of a connection error, the library will automatically attempt to reconnect, re-authenticate and reestablish subscriptions.

This behaviour is overrideable with the SetDisconnectHandler method.

// Example reconnect code
exchange.SetDisconnectHandler(func (core *deribit.RPCCore) {
    exg := &deribit.NewExchangeFromCore(true, core)
	log.Warn("Disconnected from exchange. Attempting reconnection...")
	if err := exg.Connect(); err != nil {
		log.Fatalf("Error re-connecting to exchange: %s", err)
	}
	log.Info("Reconnected")
})

Logging

The standard logger has been used within the library. You can plug this into your own application's logger by overriding the output io.Writer.

logger := logrus.New()
exchange.SetLogOutput(logger.Writer())

Development

The models and client directories are where all the requests and responses are stored. The contents is automatically generated from the schema directory by go-swagger.

If you need to rebuild these use make generate-models.

The RPC subscriptions are also auto-generated. Use make generate-methods to rebuild these. They are in rpc_subscriptions.go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timed out waiting for a response")

ErrTimeout - request timed out

Functions

This section is empty.

Types

type Exchange

type Exchange struct {
	RPCCore
	// contains filtered or unexported fields
}

Exchange is an API wrapper with the exchange

func NewExchange

func NewExchange(test bool, errs chan error, stop chan bool) (*Exchange, error)

NewExchange creates a new API wrapper key and secret can be ignored if you are only calling public endpoints

func NewExchangeFromCore

func NewExchangeFromCore(test bool, core RPCCore) *Exchange

NewExchangeFromCore creates a new exchange from an existing RPCCore

func (*Exchange) Authenticate

func (e *Exchange) Authenticate(keys ...string) error

Authenticate : 1st param: API Key, 2nd param: API Secret

func (*Exchange) Client

func (e *Exchange) Client() *client.DeribitAPI

Client returns an initialised API client

func (*Exchange) Close

func (e *Exchange) Close() error

Close the websocket connection

func (*Exchange) Connect

func (e *Exchange) Connect() error

Connect to the websocket API

func (*Exchange) Reconnect

func (e *Exchange) Reconnect(core *RPCCore)

Reconnect reconnect is already built-in on OnDisconnect. Use this method only within OnDisconnect to override it

func (*Exchange) SetDisconnectHandler

func (e *Exchange) SetDisconnectHandler(f func(*RPCCore))

SetDisconnectHandler overrides the default disconnect handler

func (*Exchange) SetLogOutput

func (e *Exchange) SetLogOutput(w io.Writer)

SetLogOutput set log output

func (*Exchange) SubscribeAnnouncements

func (e *Exchange) SubscribeAnnouncements() (chan *models.AnnouncementNotification, error)

SubscribeAnnouncements subscribes to the announcements channel

func (*Exchange) SubscribeBookGroup

func (e *Exchange) SubscribeBookGroup(instrument_name, group, depth, interval string) (chan *models.BookNotification, error)

SubscribeBookGroup subscribes to the book.{instrument_name}.{group}.{depth}.{interval} channel

func (*Exchange) SubscribeBookInterval

func (e *Exchange) SubscribeBookInterval(instrument_name, interval string) (chan *models.BookNotificationRaw, error)

SubscribeBookInterval subscribes to the book.{instrument_name}.{interval} channel

func (*Exchange) SubscribeDeribitPriceIndex

func (e *Exchange) SubscribeDeribitPriceIndex(index_name string) (chan *models.DeribitPriceIndexNotification, error)

SubscribeDeribitPriceIndex subscribes to the deribit_price_index.{index_name} channel

func (*Exchange) SubscribeDeribitPriceRanking

func (e *Exchange) SubscribeDeribitPriceRanking(index_name string) (chan *models.DeribitPriceRankingNotification, error)

SubscribeDeribitPriceRanking subscribes to the deribit_price_ranking.{index_name} channel

func (*Exchange) SubscribeEstimatedExpirationPrice

func (e *Exchange) SubscribeEstimatedExpirationPrice(index_name string) (chan *models.EstimatedExpirationPriceNotification, error)

SubscribeEstimatedExpirationPrice subscribes to the estimated_expiration_price.{index_name} channel

func (*Exchange) SubscribeMarkPriceOptions

func (e *Exchange) SubscribeMarkPriceOptions(index_name string) (chan *models.MarkpriceOptionsNotification, error)

SubscribeMarkPriceOptions subscribes to the markprice.options.{index_name} channel

func (*Exchange) SubscribePerpetual

func (e *Exchange) SubscribePerpetual(instrument_name, interval string) (chan *models.PerpetualNotification, error)

SubscribePerpetual subscribes to the perpetual.{instrument_name}.{interval} channel

func (*Exchange) SubscribeQuote

func (e *Exchange) SubscribeQuote(instrument_name string) (chan *models.QuoteNotification, error)

SubscribeQuote subscribes to the quote.{instrument_name} channel

func (*Exchange) SubscribeTicker

func (e *Exchange) SubscribeTicker(instrument_name, interval string) (chan *models.TickerNotification, error)

SubscribeTicker subscribes to the ticker.{instrument_name}.{interval} channel

func (*Exchange) SubscribeTrades

func (e *Exchange) SubscribeTrades(instrument_name, interval string) (chan *models.PublicTrade, error)

SubscribeTrades subscribes to the trades.{instrument_name}.{interval} channel

func (*Exchange) SubscribeUserOrdersInstrumentName

func (e *Exchange) SubscribeUserOrdersInstrumentName(instrument_name, interval string) (chan *models.Order, error)

SubscribeUserOrdersInstrumentName subscribes to the user.orders.{instrument_name}.{interval} channel

func (*Exchange) SubscribeUserOrdersKind

func (e *Exchange) SubscribeUserOrdersKind(kind, currency, interval string) (chan *models.Order, error)

SubscribeUserOrdersKind subscribes to the user.orders.{kind}.{currency}.{interval} channel

func (*Exchange) SubscribeUserPortfolio

func (e *Exchange) SubscribeUserPortfolio(currency string) (chan *models.UserPortfolioNotification, error)

SubscribeUserPortfolio subscribes to the user.portfolio.{currency} channel

func (*Exchange) SubscribeUserTradesInstrument

func (e *Exchange) SubscribeUserTradesInstrument(instrument_name, interval string) (chan *models.UserTrade, error)

SubscribeUserTradesInstrument subscribes to the user.trades.{instrument_name}.{interval} channel

func (*Exchange) SubscribeUserTradesKind

func (e *Exchange) SubscribeUserTradesKind(kind, currency, interval string) (chan *models.UserTrade, error)

SubscribeUserTradesKind subscribes to the user.trades.{kind}.{currency}.{interval} channel

type RPCCall

type RPCCall struct {
	Req   *RPCRequest
	Res   *RPCResponse
	Error error
	Done  chan bool
}

RPCCall represents the entire call from request to response

func NewRPCCall

func NewRPCCall(req *RPCRequest) *RPCCall

NewRPCCall returns a new RPCCall initialised with a done channel and request

func (*RPCCall) CloseError

func (r *RPCCall) CloseError(err error)

func (*RPCCall) CloseOK

func (r *RPCCall) CloseOK()

type RPCCore

type RPCCore struct {
	OnConnect func()
	// contains filtered or unexported fields
}

RPCCore actually sends and receives messages

func (*RPCCore) Submit

func (r *RPCCore) Submit(operation *runtime.ClientOperation) (interface{}, error)

Submit satisfies the runtime.ClientTransport interface

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError error object

type RPCNotification

type RPCNotification struct {
	JsonRpc string
	Method  string `json:"method"`
	Params  struct {
		Data    json.RawMessage `json:"data"`
		Channel string          `json:"channel"`
	} `json:"params,omitempty"`
}

RPCNotification is a notification which we have subscribed to

type RPCRequest

type RPCRequest struct {
	JsonRpc string                 `json:"jsonrpc"`
	Method  string                 `json:"method"`
	ID      uint64                 `json:"id"`
	Params  map[string]interface{} `json:"params,omitempty"`
}

RPCRequest is what we send to the remote Implements runtime.ClientRequest

func NewRPCRequest

func NewRPCRequest(method string) *RPCRequest

func (*RPCRequest) AddAuth

func (r *RPCRequest) AddAuth(auth *models.PublicAuthResponse)

func (RPCRequest) GetBody

func (RPCRequest) GetBody() []byte

func (RPCRequest) GetBodyParam

func (RPCRequest) GetBodyParam() interface{}

func (RPCRequest) GetFileParam

func (RPCRequest) GetFileParam() map[string][]runtime.NamedReadCloser

func (RPCRequest) GetHeaderParams

func (RPCRequest) GetHeaderParams() http.Header

func (RPCRequest) GetMethod

func (RPCRequest) GetMethod() string

func (*RPCRequest) GetPath

func (r *RPCRequest) GetPath() string

func (RPCRequest) GetQueryParams

func (RPCRequest) GetQueryParams() url.Values

func (RPCRequest) SetBodyParam

func (RPCRequest) SetBodyParam(interface{}) error

func (RPCRequest) SetFileParam

func (RPCRequest) SetFileParam(string, ...runtime.NamedReadCloser) error

func (RPCRequest) SetFormParam

func (RPCRequest) SetFormParam(string, ...string) error

func (RPCRequest) SetHeaderParam

func (RPCRequest) SetHeaderParam(string, ...string) error

func (RPCRequest) SetPathParam

func (RPCRequest) SetPathParam(string, string) error

func (*RPCRequest) SetQueryParam

func (r *RPCRequest) SetQueryParam(key string, vals ...string) error

func (RPCRequest) SetTimeout

func (RPCRequest) SetTimeout(time.Duration) error

type RPCResponse

type RPCResponse struct {
	JsonRpc string          `json:"jsonrpc"`
	ID      uint64          `json:"id,omitempty"`
	Result  json.RawMessage `json:"result"`
	Error   *RPCError       `json:"error,omitempty"`
}

RPCResponse is what we receive from the remote Implements runtime.ClientResponse

func (*RPCResponse) Body

func (r *RPCResponse) Body() io.ReadCloser

func (*RPCResponse) Code

func (r *RPCResponse) Code() int

func (RPCResponse) GetHeader

func (RPCResponse) GetHeader(string) string

func (*RPCResponse) Message

func (r *RPCResponse) Message() string

type RPCSubscription

type RPCSubscription struct {
	Data    chan *RPCNotification
	Channel string
}

RPCSubscription is a subscription to an event type to receive notifications about

Jump to

Keyboard shortcuts

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