deribit

package module
v0.0.0-...-cf154a7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: MIT Imports: 16 Imported by: 0

README

deribit-api

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

V2 API Documentation: https://docs.deribit.com/v2/

Example
package main

import (
	"github.com/annakallo/go-deribit-api"
	"github.com/annakallo/go-deribit-api/models"
	"log"
)

func main() {
	cfg := &deribit.Configuration{
		Addr:          deribit.TestBaseURL,
		ApiKey:        "AsJTU16U",
		SecretKey:     "mM5_K8LVxztN6TjjYpv_cJVGQBvk4jglrEpqkw1b87U",
		AutoReconnect: true,
		DebugMode:     true,
	}
	client := deribit.New(cfg)

	client.GetTime()
	client.Test()

	var err error

	// GetBookSummaryByCurrency
	getBookSummaryByCurrencyParams := &models.GetBookSummaryByCurrencyParams{
		Currency: "BTC",
		Kind:     "future",
	}
	var getBookSummaryByCurrencyResult []models.BookSummary
	getBookSummaryByCurrencyResult, err = client.GetBookSummaryByCurrency(getBookSummaryByCurrencyParams)
	if err != nil {
		log.Printf("%v", err)
		return
	}
	log.Printf("%v", getBookSummaryByCurrencyResult)

	// GetOrderBook
	getOrderBookParams := &models.GetOrderBookParams{
		InstrumentName: "BTC-PERPETUAL",
		Depth:          5,
	}
	var getOrderBookResult models.GetOrderBookResponse
	getOrderBookResult, err = client.GetOrderBook(getOrderBookParams)
	if err != nil {
		log.Printf("%v", err)
		return
	}
	log.Printf("%v", getOrderBookResult)

	// GetPosition
	getPositionParams := &models.GetPositionParams{
		InstrumentName: "BTC-PERPETUAL",
	}
	var getPositionResult models.Position
	getPositionResult, err = client.GetPosition(getPositionParams)
	if err != nil {
		log.Printf("%v", err)
		return
	}
	log.Printf("%v", getPositionResult)

	// Buy
	guyParams := &models.BuyParams{
		InstrumentName: "BTC-PERPETUAL",
		Amount:         40,
		Price:          6000.0,
		Type:           "limit",
	}
	var buyResult models.BuyResponse
	buyResult, err = client.Buy(guyParams)
	if err != nil {
		log.Printf("%v", err)
		return
	}
	log.Printf("%v", buyResult)

	// Subscribe
	client.On("announcements", func(e *models.AnnouncementsNotification) {
    
    })
    client.On("book.ETH-PERPETUAL.100.1.100ms", func(e *models.OrderBookGroupNotification) {

    })
    client.On("book.BTC-PERPETUAL.100ms", func(e *models.OrderBookNotification) {

    })
    client.On("book.BTC-PERPETUAL.raw", func(e *models.OrderBookRawNotification) {

    })
    client.On("deribit_price_index.btc_usd", func(e *models.DeribitPriceIndexNotification) {

    })
    client.On("deribit_price_ranking.btc_usd", func(e *models.DeribitPriceRankingNotification) {

    })
    client.On("estimated_expiration_price.btc_usd", func(e *models.EstimatedExpirationPriceNotification) {

    })
    client.On("markprice.options.btc_usd", func(e *models.MarkpriceOptionsNotification) {

    })
    client.On("perpetual.BTC-PERPETUAL.raw", func(e *models.PerpetualNotification) {

    })
    client.On("quote.BTC-PERPETUAL", func(e *models.QuoteNotification) {

    })
    client.On("ticker.BTC-PERPETUAL.raw", func(e *models.TickerNotification) {

    })
    client.On("trades.BTC-PERPETUAL.raw", func(e *models.TradesNotification) {

    })

    client.On("user.changes.BTC-PERPETUAL.raw", func(e *models.UserChangesNotification) {

    })
    client.On("user.changes.future.BTC.raw", func(e *models.UserChangesNotification) {

    })
    client.On("user.orders.BTC-PERPETUAL.raw", func(e *models.UserOrderNotification) {

    })
    client.On("user.orders.future.BTC.100ms", func(e *models.UserOrderNotification) {

    })
    client.On("user.portfolio.btc", func(e *models.PortfolioNotification) {

    })
    client.On("user.trades.BTC-PERPETUAL.raw", func(e *models.UserTradesNotification) {

    })
    client.On("user.trades.future.BTC.100ms", func(e *models.UserTradesNotification) {

    })
    
    client.Subscribe([]string{
        //"announcements",
        //"book.BTC-PERPETUAL.none.10.100ms",	// none/1,2,5,10,25,100,250
        //"book.BTC-PERPETUAL.100ms",	// type: snapshot/change
        "book.BTC-PERPETUAL.raw",
        //"deribit_price_index.btc_usd",
        //"deribit_price_ranking.btc_usd",
        //"estimated_expiration_price.btc_usd",
        //"markprice.options.btc_usd",
        //"perpetual.BTC-PERPETUAL.raw",
        //"quote.BTC-PERPETUAL",
        //"ticker.BTC-PERPETUAL.raw",
        "trades.BTC-PERPETUAL.raw",
        //"user.changes.BTC-PERPETUAL.raw",
        //"user.changes.future.BTC.raw",
        "user.orders.BTC-PERPETUAL.raw",
        //"user.orders.future.BTC.100ms",
        //"user.portfolio.btc",
        //"user.trades.BTC-PERPETUAL.raw",
        //"user.trades.future.BTC.100ms",
    })

	forever := make(chan bool)
	<- forever
}

Documentation

Index

Constants

View Source
const (
	RealBaseURL = "wss://www.deribit.com/ws/api/v2/"
	TestBaseURL = "wss://test.deribit.com/ws/api/v2/"
)
View Source
const (
	MaxTryTimes = 10000
)

Variables

View Source
var (
	ErrAuthenticationIsRequired = errors.New("authentication is required")
)

Functions

func Float32Pointer

func Float32Pointer(value float32) *float32

func Float64Pointer

func Float64Pointer(value float64) *float64

func Int32Pointer

func Int32Pointer(value int32) *int32

func Int64Pointer

func Int64Pointer(value int64) *int64

func IntPointer

func IntPointer(value int) *int

func StringPointer

func StringPointer(value string) *string

Types

type Client

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

func New

func New(cfg *Configuration) *Client

func (*Client) Auth

func (c *Client) Auth(apiKey string, secretKey string) (err error)

func (*Client) Buy

func (c *Client) Buy(params *models.BuyParams) (result models.BuyResponse, err error)

func (*Client) Call

func (c *Client) Call(method string, params interface{}, result interface{}) (err error)

Call issues JSONRPC v2 calls

func (*Client) Cancel

func (c *Client) Cancel(params *models.CancelParams) (result models.Order, err error)

func (*Client) CancelAll

func (c *Client) CancelAll() (result string, err error)

func (*Client) CancelAllByCurrency

func (c *Client) CancelAllByCurrency(params *models.CancelAllByCurrencyParams) (result string, err error)

func (*Client) CancelAllByInstrument

func (c *Client) CancelAllByInstrument(params *models.CancelAllByInstrumentParams) (result string, err error)

func (*Client) CancelTransferByID

func (c *Client) CancelTransferByID(params *models.CancelTransferByIDParams) (result models.Transfer, err error)

func (*Client) CancelWithdrawal

func (c *Client) CancelWithdrawal(params *models.CancelWithdrawalParams) (result models.Withdrawal, err error)

func (*Client) ChangeSubaccountName

func (c *Client) ChangeSubaccountName(params *models.ChangeSubaccountNameParams) (result string, err error)

func (*Client) ClosePosition

func (c *Client) ClosePosition(params *models.ClosePositionParams) (result models.ClosePositionResponse, err error)

func (*Client) CreateDepositAddress

func (c *Client) CreateDepositAddress(params *models.CreateDepositAddressParams) (result models.DepositAddress, err error)

func (*Client) CreateSubaccount

func (c *Client) CreateSubaccount() (result models.Subaccount, err error)

func (*Client) DisableCancelOnDisconnect

func (c *Client) DisableCancelOnDisconnect() (result string, err error)

func (*Client) DisableHeartbeat

func (c *Client) DisableHeartbeat() (result string, err error)

func (*Client) DisableTfaForSubaccount

func (c *Client) DisableTfaForSubaccount(params *models.DisableTfaForSubaccountParams) (result string, err error)

func (*Client) Edit

func (c *Client) Edit(params *models.EditParams) (result models.EditResponse, err error)

func (*Client) Emit

func (c *Client) Emit(event interface{}, arguments ...interface{}) *emission.Emitter

Emit emits an event

func (*Client) EnableCancelOnDisconnect

func (c *Client) EnableCancelOnDisconnect() (result string, err error)

func (*Client) GetAccountSummary

func (c *Client) GetAccountSummary(params *models.GetAccountSummaryParams) (result models.AccountSummary, err error)

func (*Client) GetAnnouncements

func (c *Client) GetAnnouncements() (result []models.Announcement, err error)

func (*Client) GetBookSummaryByCurrency

func (c *Client) GetBookSummaryByCurrency(params *models.GetBookSummaryByCurrencyParams) (result []models.BookSummary, err error)

func (*Client) GetBookSummaryByInstrument

func (c *Client) GetBookSummaryByInstrument(params *models.GetBookSummaryByInstrumentParams) (result []models.BookSummary, err error)

func (*Client) GetContractSize

func (c *Client) GetContractSize(params *models.GetContractSizeParams) (result models.GetContractSizeResponse, err error)

func (*Client) GetCurrencies

func (c *Client) GetCurrencies() (result []models.Currency, err error)

func (*Client) GetCurrentDepositAddress

func (c *Client) GetCurrentDepositAddress(params *models.GetCurrentDepositAddressParams) (result models.DepositAddress, err error)

func (*Client) GetDeposits

func (c *Client) GetDeposits(params *models.GetDepositsParams) (result models.GetDepositsResponse, err error)

func (*Client) GetEmailLanguage

func (c *Client) GetEmailLanguage() (result string, err error)

func (*Client) GetFundingChartData

func (c *Client) GetFundingChartData(params *models.GetFundingChartDataParams) (result models.GetFundingChartDataResponse, err error)

func (*Client) GetFundingRateHistory

func (c *Client) GetFundingRateHistory(params *models.GetFundingRateHistoryParams) (result models.GetFundingRateHistoryResponse, err error)

This is a new function added

func (*Client) GetFundingRateValue

func (c *Client) GetFundingRateValue(params *models.GetFundingRateValueParams) (result models.GetFundingRateValueResponse, err error)

This is a new function added

func (*Client) GetHistoricalVolatility

func (c *Client) GetHistoricalVolatility(params *models.GetHistoricalVolatilityParams) (result models.GetHistoricalVolatilityResponse, err error)

func (*Client) GetIndex

func (c *Client) GetIndex(params *models.GetIndexParams) (result models.GetIndexResponse, err error)

func (*Client) GetInstruments

func (c *Client) GetInstruments(params *models.GetInstrumentsParams) (result []models.Instrument, err error)

func (*Client) GetLastSettlementsByCurrency

func (c *Client) GetLastSettlementsByCurrency(params *models.GetLastSettlementsByCurrencyParams) (result models.GetLastSettlementsResponse, err error)

func (*Client) GetLastSettlementsByInstrument

func (c *Client) GetLastSettlementsByInstrument(params *models.GetLastSettlementsByInstrumentParams) (result models.GetLastSettlementsResponse, err error)

func (*Client) GetLastTradesByCurrency

func (c *Client) GetLastTradesByCurrency(params *models.GetLastTradesByCurrencyParams) (result models.GetLastTradesResponse, err error)

func (*Client) GetLastTradesByCurrencyAndTime

func (c *Client) GetLastTradesByCurrencyAndTime(params *models.GetLastTradesByCurrencyAndTimeParams) (result models.GetLastTradesResponse, err error)

func (*Client) GetLastTradesByInstrument

func (c *Client) GetLastTradesByInstrument(params *models.GetLastTradesByInstrumentParams) (result models.GetLastTradesResponse, err error)

func (*Client) GetLastTradesByInstrumentAndTime

func (c *Client) GetLastTradesByInstrumentAndTime(params *models.GetLastTradesByInstrumentAndTimeParams) (result models.GetLastTradesResponse, err error)

func (*Client) GetMargins

func (c *Client) GetMargins(params *models.GetMarginsParams) (result models.GetMarginsResponse, err error)

func (*Client) GetNewAnnouncements

func (c *Client) GetNewAnnouncements() (result []models.Announcement, err error)

func (*Client) GetOpenOrdersByCurrency

func (c *Client) GetOpenOrdersByCurrency(params *models.GetOpenOrdersByCurrencyParams) (result []models.Order, err error)

func (*Client) GetOpenOrdersByInstrument

func (c *Client) GetOpenOrdersByInstrument(params *models.GetOpenOrdersByInstrumentParams) (result []models.Order, err error)

func (*Client) GetOrderBook

func (c *Client) GetOrderBook(params *models.GetOrderBookParams) (result models.GetOrderBookResponse, err error)

func (*Client) GetOrderHistoryByCurrency

func (c *Client) GetOrderHistoryByCurrency(params *models.GetOrderHistoryByCurrencyParams) (result []models.Order, err error)

func (*Client) GetOrderHistoryByInstrument

func (c *Client) GetOrderHistoryByInstrument(params *models.GetOrderHistoryByInstrumentParams) (result []models.Order, err error)

func (*Client) GetOrderMarginByIDs

func (c *Client) GetOrderMarginByIDs(params *models.GetOrderMarginByIDsParams) (result models.GetOrderMarginByIDsResponse, err error)

func (*Client) GetOrderState

func (c *Client) GetOrderState(params *models.GetOrderStateParams) (result models.Order, err error)

func (*Client) GetPosition

func (c *Client) GetPosition(params *models.GetPositionParams) (result models.Position, err error)

func (*Client) GetPositions

func (c *Client) GetPositions(params *models.GetPositionsParams) (result []models.Position, err error)

func (*Client) GetSettlementHistoryByCurrency

func (c *Client) GetSettlementHistoryByCurrency(params *models.GetSettlementHistoryByCurrencyParams) (result models.GetSettlementHistoryResponse, err error)

func (*Client) GetSettlementHistoryByInstrument

func (c *Client) GetSettlementHistoryByInstrument(params *models.GetSettlementHistoryByInstrumentParams) (result models.GetSettlementHistoryResponse, err error)

func (*Client) GetStopOrderHistory

func (c *Client) GetStopOrderHistory(params *models.GetStopOrderHistoryParams) (result models.GetStopOrderHistoryResponse, err error)

func (*Client) GetSubaccounts

func (c *Client) GetSubaccounts(params *models.GetSubaccountsParams) (result []models.Subaccount, err error)

func (*Client) GetTime

func (c *Client) GetTime() (result int64, err error)

func (*Client) GetTradeVolumes

func (c *Client) GetTradeVolumes() (result models.GetTradeVolumesResponse, err error)

func (*Client) GetTradingviewChartData

func (c *Client) GetTradingviewChartData(params *models.GetTradingviewChartDataParams) (result models.GetTradingviewChartDataResponse, err error)

func (*Client) GetTransfers

func (c *Client) GetTransfers(params *models.GetTransfersParams) (result models.GetTransfersResponse, err error)

func (*Client) GetUserTradesByCurrency

func (c *Client) GetUserTradesByCurrency(params *models.GetUserTradesByCurrencyParams) (result models.GetUserTradesResponse, err error)

func (*Client) GetUserTradesByCurrencyAndTime

func (c *Client) GetUserTradesByCurrencyAndTime(params *models.GetUserTradesByCurrencyAndTimeParams) (result models.GetUserTradesResponse, err error)

func (*Client) GetUserTradesByInstrument

func (c *Client) GetUserTradesByInstrument(params *models.GetUserTradesByInstrumentParams) (result models.GetUserTradesResponse, err error)

func (*Client) GetUserTradesByInstrumentAndTime

func (c *Client) GetUserTradesByInstrumentAndTime(params *models.GetUserTradesByInstrumentAndTimeParams) (result models.GetUserTradesResponse, err error)

func (*Client) GetUserTradesByOrder

func (c *Client) GetUserTradesByOrder(params *models.GetUserTradesByOrderParams) (result models.GetUserTradesResponse, err error)

func (*Client) GetVolatilityIndexData

func (c *Client) GetVolatilityIndexData(params *models.GetVolatilityIndexDataParams) (result models.GetVolatilityIndexDataResponse, err error)

func (*Client) GetWithdrawals

func (c *Client) GetWithdrawals(params *models.GetWithdrawalsParams) (result []models.Withdrawal, err error)

func (*Client) Handle

func (c *Client) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)

Handle implements jsonrpc2.Handler

func (*Client) Hello

func (c *Client) Hello(params *models.HelloParams) (result models.HelloResponse, err error)

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*Client) Logout

func (c *Client) Logout() (err error)

func (*Client) Off

func (c *Client) Off(event interface{}, listener interface{}) *emission.Emitter

Off removes a listener for an event

func (*Client) On

func (c *Client) On(event interface{}, listener interface{}) *emission.Emitter

On adds a listener to a specific event

func (*Client) PrivateSubscribe

func (c *Client) PrivateSubscribe(params *models.SubscribeParams) (result models.SubscribeResponse, err error)

func (*Client) PrivateUnsubscribe

func (c *Client) PrivateUnsubscribe(params *models.UnsubscribeParams) (result models.UnsubscribeResponse, err error)

func (*Client) PublicSubscribe

func (c *Client) PublicSubscribe(params *models.SubscribeParams) (result models.SubscribeResponse, err error)

func (*Client) PublicUnsubscribe

func (c *Client) PublicUnsubscribe(params *models.UnsubscribeParams) (result models.UnsubscribeResponse, err error)

func (*Client) Sell

func (c *Client) Sell(params *models.SellParams) (result models.SellResponse, err error)

func (*Client) SetAnnouncementAsRead

func (c *Client) SetAnnouncementAsRead(params *models.SetAnnouncementAsReadParams) (result string, err error)

func (*Client) SetEmailForSubaccount

func (c *Client) SetEmailForSubaccount(params *models.SetEmailForSubaccountParams) (result string, err error)

func (*Client) SetEmailLanguage

func (c *Client) SetEmailLanguage(params *models.SetEmailLanguageParams) (result string, err error)

func (*Client) SetHeartbeat

func (c *Client) SetHeartbeat(params *models.SetHeartbeatParams) (result string, err error)

func (*Client) SetPasswordForSubaccount

func (c *Client) SetPasswordForSubaccount(params *models.SetPasswordForSubaccountParams) (result string, err error)

func (*Client) Subscribe

func (c *Client) Subscribe(channels []string)

func (*Client) Test

func (c *Client) Test() (result models.TestResponse, err error)

func (*Client) Ticker

func (c *Client) Ticker(params *models.TickerParams) (result models.TickerResponse, err error)

func (*Client) ToggleNotificationsFromSubaccount

func (c *Client) ToggleNotificationsFromSubaccount(params *models.ToggleNotificationsFromSubaccountParams) (result string, err error)

func (*Client) ToggleSubaccountLogin

func (c *Client) ToggleSubaccountLogin(params *models.ToggleSubaccountLoginParams) (result string, err error)

func (*Client) Withdraw

func (c *Client) Withdraw(params *models.WithdrawParams) (result models.Withdrawal, err error)

type Configuration

type Configuration struct {
	Ctx           context.Context
	Addr          string `json:"addr"`
	ApiKey        string `json:"api_key"`
	SecretKey     string `json:"secret_key"`
	AutoReconnect bool   `json:"auto_reconnect"`
	DebugMode     bool   `json:"debug_mode"`
}

type Event

type Event struct {
	Channel string          `json:"channel"`
	Data    json.RawMessage `json:"data"`
}

Event is wrapper of received event

type ObjectStream

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

A ObjectStream is a jsonrpc2.ObjectStream that uses a WebSocket to send and receive JSON-RPC 2.0 objects.

func NewObjectStream

func NewObjectStream(conn *websocket.Conn) ObjectStream

NewObjectStream creates a new jsonrpc2.ObjectStream for sending and receiving JSON-RPC 2.0 objects over a WebSocket.

func (ObjectStream) Close

func (t ObjectStream) Close() error

Close implements jsonrpc2.ObjectStream.

func (ObjectStream) ReadObject

func (t ObjectStream) ReadObject(v interface{}) error

ReadObject implements jsonrpc2.ObjectStream.

func (ObjectStream) WriteObject

func (t ObjectStream) WriteObject(obj interface{}) error

WriteObject implements jsonrpc2.ObjectStream.

type Token

type Token struct {
	AccessToken string `json:"access_token"`
}

Token is used to embedded in params for private methods

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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