krakenapi

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 16 Imported by: 1

README

krakenapi-go

A Kraken WebSocket API for Go by crankykernel

WebSocket Support

Currently supports the following websocket API features:

  • Application ping
  • Tickers
  • OHLC
  • Spread

WebSocket Example

https://github.com/crankykernel/krakenapi-go/blob/master/example_socket_test.go

Documentation

Overview

Package krakenapi provides access to the Kraken cryptocurrency exchange.

Index

Constants

This section is empty.

Variables

View Source
var API_ROOT string = "https://api.kraken.com"
View Source
var WS_URL = "wss://ws.kraken.com"

Functions

func RestPair

func RestPair(input string) string

Given a common pair naming, return the Kraken format for the REST API.

func WebSocketPair

func WebSocketPair(input string) string

Given a common pair naming, return the Kraken format for websockets.

Types

type AddOrderOrderType

type AddOrderOrderType string
const OrderTypeLimit AddOrderOrderType = "limit"
const OrderTypeMarket AddOrderOrderType = "market"

type AddOrderRequest

type AddOrderRequest struct {
	Pair         string
	Side         OrderSide
	Type         AddOrderOrderType
	Price        float64
	Volume       float64
	UserRef      int32
	ValidateOnly bool
}

type AddOrderResponse

type AddOrderResponse struct {
	Error  []interface{} `json:"error"`
	Result struct {
		Descr struct {
			Order string `json:"order"`
		}
		Txid []string `json:"txid"`
	} `json:"result"`
}

func (*AddOrderResponse) HasError

func (r *AddOrderResponse) HasError() bool

type AssetPairInfo

type AssetPairInfo struct {
	Pair    string // Not in JSON response.
	AltName string `json:"altname"`
	WsName  string `json:"wsname"`
}

type AssetPairResponse

type AssetPairResponse struct {
	Error  []interface{}             `json:"error"`
	Result map[string]*AssetPairInfo `json:"result"`
}

type AssetPairService

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

func NewAssetPairService

func NewAssetPairService() *AssetPairService

func (*AssetPairService) GetRestPair

func (s *AssetPairService) GetRestPair(pair string) string

func (*AssetPairService) GetWsPair

func (s *AssetPairService) GetWsPair(pair string) string

func (*AssetPairService) LoadResponse

func (s *AssetPairService) LoadResponse(response AssetPairResponse)

func (*AssetPairService) Refresh

func (s *AssetPairService) Refresh() error

func (*AssetPairService) SetCacheFilename

func (s *AssetPairService) SetCacheFilename(filename string)

type Book

type Book struct {
	Orders map[Side][]Order
	Pair   string
}

func DecodeBook

func DecodeBook(data map[string]interface{}) (*Book, error)

type CancelOrderResponse

type CancelOrderResponse struct {
	Error  []interface{} `json:"error"`
	Result struct {
		Count int64 `json:"count"`
	} `json:"result"`
}

func (*CancelOrderResponse) HasError

func (r *CancelOrderResponse) HasError() bool

type EventMessage

type EventMessage struct {
	Event        string `json:"event"`
	ChannelID    int64  `json:"channelID"`
	Status       string `json:"status"`
	Pair         string `json:"pair"`
	ErrorMessage string `json:"errorMessage"`
	RequestID    int64  `json:"reqid"`
	Subscription struct {
		Name string `json:"name"`
	}
}

type Interval

type Interval int

Interval is a set of constants for OHLC intervals.

const (
	Interval_1m  Interval = 1
	Interval_5m  Interval = 5
	Interval_15m Interval = 15
	Interval_30m Interval = 30
	Interval_1h  Interval = 60
	Interval_4h  Interval = 240
	Interval_24h Interval = 1440
	Interval_7d  Interval = 10080
	Interval_15d Interval = 21600
)

type OHLC

type OHLC struct {
	Pair    string
	Time    float64
	EndTime float64
	Open    float64
	High    float64
	Low     float64
	Close   float64
	VWAP    float64
	Volume  float64
	Count   int64
}

OHLC is the decoded OHLC event for a pair.

func DecodeOHLC

func DecodeOHLC(data []interface{}) (*OHLC, error)

DecodeOHLC decodes an array into an OHLC.

type Order

type Order struct {
	Price     float64
	Volume    float64
	Timestamp float64
}

type OrderSide

type OrderSide string
const OrderSideBuy OrderSide = "buy"
const OrderSideSell OrderSide = "sell"

type RequestError

type RequestError struct {
	NetworkError error
	HttpError    error
	DecodeError  error
}

func (RequestError) Error

func (e RequestError) Error() string

type RestClient

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

func NewRestClient

func NewRestClient(apiKey string, apiSecret string) (*RestClient, error)

func (*RestClient) AddOrder

func (c *RestClient) AddOrder(order AddOrderRequest) (*AddOrderResponse, error)

func (*RestClient) CancelOrder

func (c *RestClient) CancelOrder(txId string) (*CancelOrderResponse, error)

func (*RestClient) Get

func (c *RestClient) Get(path string) (*http.Response, error)

func (*RestClient) Post

func (c *RestClient) Post(path string, params map[string]interface{}) (*http.Response, error)

func (*RestClient) Time

func (c *RestClient) Time() (*TimeResponse, error)

type Side

type Side string
const (
	Ask Side = "Ask"
	Bid Side = "Bid"
)

type Spread

type Spread struct {
	Pair      string
	Bid       float64
	Ask       float64
	Timestamp float64
}

Spread represents a decoded spread event for a pair.

func DecodeSpread

func DecodeSpread(input []interface{}) (*Spread, error)

DecodeSpread decodes the input instead a Spread struct.

type SubscribeMessage

type SubscribeMessage struct {
	Event        string                 `json:"event"`
	Pair         []string               `json:"pair"`
	Subscription map[string]interface{} `json:"subscription"`
}

type Ticker

type Ticker struct {
	Pair string

	// Ask.
	Ask struct {
		Price          float64
		WholeLotVolume int64
		LotVolume      float64
	}

	// Bid.
	Bid struct {
		Price          float64
		WholeLotVolume int64
		LotVolume      float64
	}

	// Close.
	Close struct {
		Price     float64
		LotVolume float64
	}

	// Volume.
	Volume struct {
		Today       float64
		Last24Hours float64
	}

	// VWAP.
	Vwap struct {
		Today       float64
		Last24Hours float64
	}

	// Number of trades.
	Trades struct {
		Today       int64
		Last24Hours int64
	}

	// Low price.
	Low struct {
		Today       float64
		Last24Hours float64
	}

	// High price.
	High struct {
		Today       float64
		Last24Hours float64
	}

	// Open price.
	Open struct {
		Today       float64
		Last24Hours float64
	}
}

Ticker is the decoded representation of a ticker.

func DecodeTicker

func DecodeTicker(data map[string]interface{}) (*Ticker, error)

DecodeTicker decodes an array into a Ticker.

type TimeResponse

type TimeResponse struct {
	Error  []interface{} `json:"error"`
	Result struct {
		UnixTime int64  `json:"unixtime"`
		Rfc1123  string `json:"rfc1123"`
	} `json:"result"`
}

type WebSocket

type WebSocket struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

func OpenWebSocket

func OpenWebSocket() (*WebSocket, error)

func (*WebSocket) Close

func (s *WebSocket) Close()

func (*WebSocket) Decode

func (s *WebSocket) Decode(input []byte) (interface{}, error)

func (*WebSocket) Next

func (s *WebSocket) Next() ([]byte, error)

func (*WebSocket) Ping

func (s *WebSocket) Ping(reqId int) error

Ping sends an application ping to the server. The reqId will only be included if non-zero.

func (*WebSocket) SubscribeBook

func (s *WebSocket) SubscribeBook(tickers []string, depth int) error

func (*WebSocket) SubscribeOHLC

func (s *WebSocket) SubscribeOHLC(interval Interval, tickers ...string) error

func (*WebSocket) SubscribeSpread

func (s *WebSocket) SubscribeSpread(tickers ...string) error

func (*WebSocket) SubscribeTicker

func (s *WebSocket) SubscribeTicker(tickers ...string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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