websocket

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProdBaseURL        = "wss://ws.kraken.com"
	AuthBaseURL        = "wss://ws-auth.kraken.com"
	SandboxBaseURL     = "wss://beta-ws.kraken.com"
	AuthSandboxBaseURL = "wss://beta-ws-auth.kraken.com"
)

URLs

View Source
const (
	ChanBook       = "book"
	ChanTrades     = "trade"
	ChanTicker     = "ticker"
	ChanCandles    = "ohlc"
	ChanSpread     = "spread"
	ChanOpenOrders = "openOrders"
	ChanOwnTrades  = "ownTrades"
	ChanAll        = "*"
)

Available channels

View Source
const (
	EventSubscribe             = "subscribe"
	EventUnsubscribe           = "unsubscribe"
	EventPing                  = "ping"
	EventPong                  = "pong"
	EventSystemStatus          = "systemStatus"
	EventSubscriptionStatus    = "subscriptionStatus"
	EventHeartbeat             = "heartbeat"
	EventAddOrder              = "addOrder"
	EventAddOrderStatus        = "addOrderStatus"
	EventCancelOrder           = "cancelOrder"
	EventCancelOrderStatus     = "cancelOrderStatus"
	EventCancellAll            = "cancelAll"
	EventCancellAllStatus      = "cancelAllStatus"
	EventCancellAllOrdersAfter = "cancelAllOrdersAfter"
)

Events

View Source
const (
	Interval1     = 1
	Interval5     = 5
	Interval15    = 15
	Interval30    = 30
	Interval60    = 60
	Interval240   = 240
	Interval1440  = 1440
	Interval10080 = 10080
	Interval21600 = 21600
)

Intervals

View Source
const (
	Depth10   = 10
	Depth25   = 25
	Depth100  = 100
	Depth500  = 500
	Depth1000 = 1000
)

Depth

View Source
const (
	SubscriptionStatusError        = "error"
	SubscriptionStatusSubscribed   = "subscribed"
	SubscriptionStatusUnsubscribed = "unsubscribed"
)

Subscription Statuses

View Source
const (
	Buy  = "b"
	Sell = "s"
)

Trade sides

View Source
const (
	Market = "m"
	Limit  = "l"
)

Order types

View Source
const (
	ADACAD  = "ADA/CAD"
	ADAETH  = "ADA/ETH"
	ADAEUR  = "ADA/EUR"
	ADAUSD  = "ADA/USD"
	ADABTC  = "ADA/XBT"
	BCHEUR  = "BCH/EUR"
	BCHUSD  = "BCH/USD"
	BCHBTC  = "BCH/XBT"
	BSVEUR  = "BSV/EUR"
	BSVUSD  = "BSV/USD"
	BSVBTC  = "BSV/XBT"
	BTCEUR  = "XBT/EUR"
	BTCUSD  = "XBT/USD"
	BTCCAD  = "XBT/CAD"
	BTCJPY  = "XBT/JPY"
	BTCGBP  = "XBT/GBP"
	DASHEUR = "DASH/EUR"
	DASHUSD = "DASH/USD"
	DASHBTC = "DASH/XBT"
	DOGEBTC = "XDG/XBT"
	DOTEUR  = "DOT/EUR"
	DOTUSD  = "DOT/USD"
	EOSETH  = "EOS/ETH"
	EOSEUR  = "EOS/EUR"
	EOSUSD  = "EOS/USD"
	EOSBTC  = "EOS/XBT"
	ETCETH  = "ETC/ETH"
	ETCEUR  = "ETC/EUR"
	ETCUSD  = "ETC/USD"
	ETCBTC  = "ETC/XBT"
	ETHCAD  = "ETH/CAD"
	ETHEUR  = "ETH/EUR"
	ETHUSD  = "ETH/USD"
	ETHBTC  = "ETH/XBT"
	ETHJPY  = "ETH/JPY"
	ETHGBP  = "ETH/GBP"
	GNOETH  = "GNO/ETH"
	GNOEUR  = "GNO/EUR"
	GNOUSD  = "GNO/USD"
	GNOBTC  = "GNO/XBT"
	LTCEUR  = "LTC/EUR"
	LTCUSD  = "LTC/USD"
	LTCBTC  = "LTC/XBT"
	MLNETH  = "MLN/ETH"
	MLNBTC  = "MLN/XBT"
	QTUMCAD = "QTUM/CAD"
	QTUMETH = "QTUM/ETH"
	QTUMEUR = "QTUM/EUR"
	QTUMUSD = "QTUM/USD"
	QTUMBTC = "QTUM/XBT"
	REPETH  = "REP/ETH"
	REPEUR  = "REP/EUR"
	REPUSD  = "REP/USD"
	REPBTC  = "REP/XBT"
	USDTUSD = "USDT/USD"
	XLMEUR  = "XLM/EUR"
	XLMUSD  = "XLM/USD"
	XLMBTC  = "XLM/XBT"
	XMREUR  = "XMR/EUR"
	XMRUSD  = "XMR/USD"
	XMRBTC  = "XMR/XBT"
	XRPCAD  = "XRP/CAD"
	XRPEUR  = "XRP/EUR"
	XRPJPY  = "XRP/JPY"
	XRPUSD  = "XRP/USD"
	XRPBTC  = "XRP/XBT"
	XTZCAD  = "XTZ/CAD"
	XTZETH  = "XTZ/ETH"
	XTZEUR  = "XTZ/EUR"
	XTZUSD  = "XTZ/USD"
	XTZBTC  = "XTZ/XBT"
	ZECEUR  = "ZEC/EUR"
	ZECJPY  = "ZEC/JPY"
	ZECUSD  = "ZEC/USD"
)

Pairs

View Source
const (
	StatusOK    = "ok"
	StatusError = "error"
)

Statuses

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOrderRequest

type AddOrderRequest struct {
	AuthRequest
	ClosePrice string `json:"close[price]"`
	Ordertype  string `json:"ordertype"`
	Pair       string `json:"pair"`
	Price      string `json:"price"`
	Type       string `json:"type"`
	Volume     string `json:"volume"`
}

AddOrderRequest -

type AddOrderResponse

type AddOrderResponse struct {
	Description  string `json:"descr"`
	Event        string `json:"event"`
	Status       string `json:"status"`
	TxID         string `json:"txid"`
	ErrorMessage string `json:"errorMessage,omitempty"`
}

AddOrderResponse -

type AuthDataRequest

type AuthDataRequest struct {
	Name  string `json:"name"`
	Token string `json:"token"`
}

AuthDataRequest - data structure for private subscription request

type AuthRequest

type AuthRequest struct {
	Token string `json:"token"`
	Event string `json:"event"`
}

AuthRequest -

type AuthSubscriptionRequest

type AuthSubscriptionRequest struct {
	Event string          `json:"event"`
	Subs  AuthDataRequest `json:"subscription"`
}

AuthSubscriptionRequest - data structure for private subscription request

type CancelAllResponse

type CancelAllResponse struct {
	Count        int    `json:"count"`
	Event        string `json:"event"`
	Status       string `json:"status"`
	ErrorMessage string `json:"errorMessage,omitempty"`
}

CancelAllResponse -

type CancelOrderRequest

type CancelOrderRequest struct {
	AuthRequest
	TxID []string `json:"txid"`
}

CancelOrderRequest -

type CancelOrderResponse

type CancelOrderResponse struct {
	ErrorMessage string `json:"errorMessage,omitempty"`
	Event        string `json:"event"`
	Status       string `json:"status"`
}

CancelOrderResponse -

type Candle

type Candle struct {
	Time      json.Number
	EndTime   json.Number
	Open      json.Number
	High      json.Number
	Low       json.Number
	Close     json.Number
	VolumeWAP json.Number
	Volume    json.Number
	Count     int64
}

Candle -

func (*Candle) UnmarshalJSON

func (c *Candle) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal candle update

type DecimalValues

type DecimalValues struct {
	Today  json.Number
	Last24 json.Number
}

DecimalValues - data structure for decimal ticker data

func (*DecimalValues) UnmarshalJSON

func (v *DecimalValues) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal ticker update

type EventType

type EventType struct {
	Event string `json:"event"`
}

EventType - data structure for parsing events

type IntValues

type IntValues struct {
	Today  int64
	Last24 int64
}

IntValues - data structure for int ticker data

func (*IntValues) UnmarshalJSON

func (v *IntValues) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal ticker update

type Kraken

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

Kraken -

func NewKraken

func NewKraken(url string, opts ...KrakenOption) *Kraken

New -

func (*Kraken) AddOrder

func (k *Kraken) AddOrder(req AddOrderRequest) error

AddOrder - method adds new order.

func (*Kraken) Authenticate

func (k *Kraken) Authenticate(key, secret string) error

Authenticate - authenticate in private Websocket API

func (*Kraken) CancelAll

func (k *Kraken) CancelAll() error

CancelAll - method cancels order or list of orders.

func (*Kraken) CancelOrder

func (k *Kraken) CancelOrder(orderIDs []string) error

CancelOrder - method cancels order or list of orders.

func (*Kraken) Close

func (k *Kraken) Close() error

Close - provides an interface for a user initiated shutdown.

func (*Kraken) Connect

func (k *Kraken) Connect() error

Connect to the Kraken API, this should only be called once.

func (*Kraken) Listen

func (k *Kraken) Listen() <-chan Update

Listen provides an atomic interface for receiving API messages. When a websocket connection is terminated, the publisher channel will close.

func (*Kraken) SubscribeBook

func (k *Kraken) SubscribeBook(pairs []string, depth int64) error

SubscribeBook - Order book levels. On subscription, a snapshot will be published at the specified depth, following the snapshot, level updates will be published.

func (*Kraken) SubscribeCandles

func (k *Kraken) SubscribeCandles(pairs []string, interval int64) error

SubscribeCandles - Open High Low Close (Candle) feed for a currency pair and interval period.

func (*Kraken) SubscribeOpenOrders

func (k *Kraken) SubscribeOpenOrders() error

SubscribeOpenOrders - method tries to subscribe on OpenOrders channel events

func (*Kraken) SubscribeOwnTrades

func (k *Kraken) SubscribeOwnTrades() error

SubscribeOwnTrades - method tries to subscribe on OwnTrades channel events

func (*Kraken) SubscribeSpread

func (k *Kraken) SubscribeSpread(pairs []string) error

SubscribeSpread - Spread feed to show best bid and ask price for a currency pair

func (*Kraken) SubscribeTicker

func (k *Kraken) SubscribeTicker(pairs []string) error

SubscribeTicker - Ticker information includes best ask and best bid prices, 24hr volume, last trade price, volume weighted average price, etc for a given currency pair. A ticker message is published every time a trade or a group of trade happens.

func (*Kraken) SubscribeTrades

func (k *Kraken) SubscribeTrades(pairs []string) error

SubscribeTrades - Trade feed for a currency pair.

func (*Kraken) Unsubscribe

func (k *Kraken) Unsubscribe(channelType string, pairs []string) error

Unsubscribe - Unsubscribe from single subscription, can specify multiple currency pairs.

func (*Kraken) UnsubscribeBook

func (k *Kraken) UnsubscribeBook(pairs []string, depth int64) error

UnsubscribeBook - Unsubscribe from order book subscription, can specify multiple currency pairs.

func (*Kraken) UnsubscribeCandles

func (k *Kraken) UnsubscribeCandles(pairs []string, interval int64) error

UnsubscribeCandles - Unsubscribe from candles subscription, can specify multiple currency pairs.

type KrakenOption

type KrakenOption func(*Kraken)

KrakenOption - option function for `AuthClient`

func WithHeartbeatTimeout

func WithHeartbeatTimeout(timeout time.Duration) KrakenOption

WithHeartbeatTimeout - add custom heartbeat timeout (time interval for sending ping message). Default: 10s.

func WithLogLevel

func WithLogLevel(level log.Level) KrakenOption

WithLogLevel - add custom log level. Default: info

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) KrakenOption

WithReadTimeout - add custom read timeout. Default: 15s.

func WithReconnectTimeout

func WithReconnectTimeout(timeout time.Duration) KrakenOption

WithReconnectTimeout - add custom reconnect timeout (time interval for next reconnecting try). Default: 5s.

type Level

type Level struct {
	Price          json.Number
	Volume         json.Number
	WholeLotVolume int
}

Level -

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal ticker update

type Message

type Message struct {
	ChannelID   int64
	Data        json.RawMessage
	ChannelName string
	Pair        string
	Sequence    Seq
}

Message - data structure of default Kraken WS update

func (*Message) UnmarshalJSON

func (msg *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal update

type OpenOrder

type OpenOrder struct {
	Cost       json.Number    `json:"cost"`
	Descr      OpenOrderDescr `json:"descr"`
	Fee        json.Number    `json:"fee"`
	LimitPrice json.Number    `json:"limitprice"`
	Misc       string         `json:"misc"`
	Oflags     string         `json:"oflags"`
	OpenTime   json.Number    `json:"opentm"`
	StartTime  json.Number    `json:"starttm"`
	ExpireTime json.Number    `json:"expiretm"`
	Price      json.Number    `json:"price"`
	Refid      string         `json:"refid"`
	Status     string         `json:"status"`
	StopPrice  json.Number    `json:"stopprice"`
	UserRef    int64          `json:"userref"`
	Vol        json.Number    `json:"vol,string"`
	VolExec    json.Number    `json:"vol_exec"`
}

OpenOrder -

type OpenOrderDescr

type OpenOrderDescr struct {
	Close     string      `json:"close"`
	Leverage  string      `json:"leverage"`
	Order     string      `json:"order"`
	Ordertype string      `json:"ordertype"`
	Pair      string      `json:"pair"`
	Price     json.Number `json:"price"`
	Price2    json.Number `json:"price2"`
	Type      string      `json:"type"`
}

OpenOrderDescr -

type OpenOrdersUpdate

type OpenOrdersUpdate []map[string]OpenOrder

OpenOrdersUpdate -

type OrderBookItem

type OrderBookItem struct {
	Price     json.Number
	Volume    json.Number
	Time      json.Number
	Republish bool
}

OrderBookItem - data structure for order book item

func (*OrderBookItem) UnmarshalJSON

func (obi *OrderBookItem) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal candle update

type OrderBookUpdate

type OrderBookUpdate struct {
	Asks       []OrderBookItem
	Bids       []OrderBookItem
	CheckSum   string
	IsSnapshot bool
}

OrderBookUpdate - data structure for order book update

func (*OrderBookUpdate) UnmarshalJSON

func (obu *OrderBookUpdate) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal candle update

type OwnTrade

type OwnTrade struct {
	Cost      json.Number `json:"cost"`
	Fee       json.Number `json:"fee"`
	Margin    json.Number `json:"margin"`
	OrderID   string      `json:"ordertxid"`
	OrderType string      `json:"ordertype"`
	Pair      string      `json:"pair"`
	PosTxID   string      `json:"postxid"`
	Price     json.Number `json:"price"`
	Time      json.Number `json:"time"`
	Type      string      `json:"type"`
	Vol       json.Number `json:"vol"`
}

OwnTrade - Own trades.

type OwnTradesUpdate

type OwnTradesUpdate []map[string]OwnTrade

OwnTradesUpdate -

type PingRequest

type PingRequest struct {
	Event string `json:"event"`
	ReqID int    `json:"reqid,omitempty"`
}

PingRequest - data structure for ping request

type PongResponse

type PongResponse struct {
	Event string `json:"event"`
	ReqID int    `json:"reqid,omitempty"`
}

PongResponse - data structure for ping response

type Seq

type Seq struct {
	Value int64 `json:"sequence"`
}

Seq -

type Spread

type Spread struct {
	Ask       json.Number
	Bid       json.Number
	AskVolume json.Number
	BidVolume json.Number
	Time      json.Number
}

Spread - data structure for spread update

func (*Spread) UnmarshalJSON

func (s *Spread) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal candle update

type Subscription

type Subscription struct {
	Name     string `json:"name"`
	Interval int64  `json:"interval,omitempty"`
	Depth    int64  `json:"depth,omitempty"`
}

Subscription - data structure of subscription entity

type SubscriptionRequest

type SubscriptionRequest struct {
	ReqID string `json:"reqid,omitempty"`
	Event string `json:"event"`

	Pairs        []string     `json:"pair"`
	Subscription Subscription `json:"subscription"`
}

SubscriptionRequest - data structure for subscription request

type SubscriptionStatus

type SubscriptionStatus struct {
	ChannelID    int64        `json:"channelID"`
	Event        string       `json:"event"`
	Status       string       `json:"status"`
	Pair         string       `json:"pair"`
	ReqID        string       `json:"reqid,omitempty"`
	Error        string       `json:"errorMessage,omitempty"`
	Subscription Subscription `json:"subscription"`
}

SubscriptionStatus - data structure for subscription status event

type SystemStatus

type SystemStatus struct {
	Event        string  `json:"event"`
	ConnectionID big.Int `json:"connectionID"`
	Status       string  `json:"status"`
	Version      string  `json:"version"`
}

SystemStatus - data structure for system status event

type TickerUpdate

type TickerUpdate struct {
	Ask                Level         `json:"a"`
	Bid                Level         `json:"b"`
	Close              DecimalValues `json:"c"`
	Volume             DecimalValues `json:"v"`
	VolumeAveragePrice DecimalValues `json:"p"`
	TradeVolume        IntValues     `json:"t"`
	Low                DecimalValues `json:"l"`
	High               DecimalValues `json:"h"`
	Open               DecimalValues `json:"o"`
}

TickerUpdate - data structure for ticker update

type Trade

type Trade struct {
	Price     json.Number
	Volume    json.Number
	Time      json.Number
	Side      string
	OrderType string
	Misc      string
}

Trade - data structure for trade update

func (*Trade) UnmarshalJSON

func (t *Trade) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshal candle update

type UnsubscribeRequest

type UnsubscribeRequest struct {
	Event        string       `json:"event"`
	Pairs        []string     `json:"pair"`
	Subscription Subscription `json:"subscription"`
}

UnsubscribeRequest - data structure for unsubscription request

type Update

type Update struct {
	ChannelID   int64
	Data        interface{}
	ChannelName string
	Pair        string
	Sequence    Seq
}

Update - notification from channel or events

Jump to

Keyboard shortcuts

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