Documentation ¶
Index ¶
- Constants
- type AddOrderRequest
- type AddOrderResponse
- type AuthDataRequest
- type AuthRequest
- type AuthSubscriptionRequest
- type CancelAllOrdersAfterRequest
- type CancelAllOrdersAfterResponse
- type CancelAllResponse
- type CancelOrderRequest
- type CancelOrderResponse
- type Candle
- type DecimalValues
- type EditOrderRequest
- type EditOrderResponse
- type EventType
- type IntValues
- type Kraken
- func (k *Kraken) AddOrder(req AddOrderRequest) error
- func (k *Kraken) Authenticate(key, secret string) error
- func (k *Kraken) CancelAll() error
- func (k *Kraken) CancelAllOrdersAfter(timeout int64) error
- func (k *Kraken) CancelOrder(orderIDs []string) error
- func (k *Kraken) Close() error
- func (k *Kraken) Connect() error
- func (k *Kraken) EditOrder(req EditOrderRequest) error
- func (k *Kraken) Listen() <-chan Update
- func (k *Kraken) SubscribeBook(pairs []string, depth int64) error
- func (k *Kraken) SubscribeCandles(pairs []string, interval int64) error
- func (k *Kraken) SubscribeOpenOrders() error
- func (k *Kraken) SubscribeOwnTrades() error
- func (k *Kraken) SubscribeSpread(pairs []string) error
- func (k *Kraken) SubscribeTicker(pairs []string) error
- func (k *Kraken) SubscribeTrades(pairs []string) error
- func (k *Kraken) Unsubscribe(channelType string, pairs []string) error
- func (k *Kraken) UnsubscribeBook(pairs []string, depth int64) error
- func (k *Kraken) UnsubscribeCandles(pairs []string, interval int64) error
- type KrakenOption
- type Level
- type Message
- type OpenOrder
- type OpenOrderDescr
- type OpenOrdersUpdate
- type OrderBook
- type OrderBookItem
- type OrderBookSide
- type OrderBookUpdate
- type OwnTrade
- type OwnTradesUpdate
- type PingRequest
- type PongResponse
- type Seq
- type Spread
- type Subscription
- type SubscriptionRequest
- type SubscriptionStatus
- type SystemStatus
- type TickerUpdate
- type Trade
- type UnsubscribeRequest
- type Update
Constants ¶
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
const ( ChanBook = "book" ChanTrades = "trade" ChanTicker = "ticker" ChanCandles = "ohlc" ChanSpread = "spread" ChanOpenOrders = "openOrders" ChanOwnTrades = "ownTrades" ChanAll = "*" )
Available channels
const ( EventSubscribe = "subscribe" EventUnsubscribe = "unsubscribe" EventPing = "ping" EventPong = "pong" EventSystemStatus = "systemStatus" EventSubscriptionStatus = "subscriptionStatus" EventHeartbeat = "heartbeat" EventAddOrder = "addOrder" EventAddOrderStatus = "addOrderStatus" EventCancelOrder = "cancelOrder" EventCancelOrderStatus = "cancelOrderStatus" EventCancelAll = "cancelAll" EventCancelAllStatus = "cancelAllStatus" EventCancelAllOrdersAfter = "cancelAllOrdersAfter" EventCancelAllOrdersAfterStatus = "cancelAllOrdersAfterStatus" EventEditOrder = "editOrder" EventEditOrderStatus = "editOrderStatus" )
Events
const ( Interval1 = 1 Interval5 = 5 Interval15 = 15 Interval30 = 30 Interval60 = 60 Interval240 = 240 Interval1440 = 1440 Interval10080 = 10080 Interval21600 = 21600 )
Intervals
const ( Depth10 = 10 Depth25 = 25 Depth100 = 100 Depth500 = 500 Depth1000 = 1000 )
Depth
const ( SubscriptionStatusError = "error" SubscriptionStatusSubscribed = "subscribed" SubscriptionStatusUnsubscribed = "unsubscribed" )
Subscription Statuses
const ( Buy = "b" Sell = "s" )
Trade sides for parsing
const ( Market = "m" Limit = "l" )
Order types for parsing
const ( SideBuy = "buy" SideSell = "sell" )
Trade sides -
const ( OrderTypeMarket = "market" OrderTypeLimit = "limit" OrderTypeStopLoss = "stop-loss" OrderTypeTakeProfit = "take-profit" OrderTypeStopLossLimit = "stop-loss-limit" OrderTypeTakeProfitLimit = "take-profit-limit" OrderTypeSettlePosition = "settle-position" )
Order types -
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" BTCUSDT = "XBT/USDT" 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" ETHUSDT = "ETH/USDT" GNOETH = "GNO/ETH" GNOEUR = "GNO/EUR" GNOUSD = "GNO/USD" GNOBTC = "GNO/XBT" LTCEUR = "LTC/EUR" LTCUSD = "LTC/USD" LTCBTC = "LTC/XBT" LTCUSDT = "LTC/USDT" 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
const ( StatusOK = "ok" StatusError = "error" )
Statuses
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOrderRequest ¶
type AddOrderRequest struct { AuthRequest Ordertype string `json:"ordertype"` Pair string `json:"pair"` Price string `json:"price"` Type string `json:"type"` Volume string `json:"volume"` Starttm string `json:"starttm,omitempty"` Expiretm string `json:"expiretm,omitempty"` Deadline string `json:"deadline,omitempty"` Validate string `json:"validate,omitempty"` TimeInForce string `json:"timeinforce,omitempty"` UserRef string `json:"userref,omitempty"` OFlags string `json:"oflags,omitempty"` Leverage string `json:"leverage,omitempty"` ClosePrice string `json:"close[price],omitempty"` ClosePrice2 string `json:"close[price2],omitempty"` CloseOrderType string `json:"close[ordertype],omitempty"` }
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 ¶
AuthDataRequest - data structure for private subscription request
type AuthRequest ¶
AuthRequest -
type AuthSubscriptionRequest ¶
type AuthSubscriptionRequest struct { Event string `json:"event"` Subs AuthDataRequest `json:"subscription"` }
AuthSubscriptionRequest - data structure for private subscription request
type CancelAllOrdersAfterRequest ¶
type CancelAllOrdersAfterRequest struct { AuthRequest Timeout int64 `json:"timeout"` ReqID int64 `json:"reqid,omitempty"` }
CancelAllOrdersAfterRequest -
type CancelAllOrdersAfterResponse ¶
type CancelAllOrdersAfterResponse struct { AuthRequest ReqID int64 `json:"reqid,omitempty"` Status string `json:"status"` ErrorMessage string `json:"errorMessage,omitempty"` CurrentTime string `json:"currentTime"` TriggerTime string `json:"triggerTime"` }
CancelAllOrdersAfterResponse -
type CancelAllResponse ¶
type CancelAllResponse struct { ReqID int64 `json:"reqid,omitempty"` Count int `json:"count"` Event string `json:"event"` Status string `json:"status"` ErrorMessage string `json:"errorMessage,omitempty"` }
CancelAllResponse -
type CancelOrderRequest ¶
type CancelOrderRequest struct { AuthRequest ReqID int64 `json:"reqid,omitempty"` TxID []string `json:"txid"` }
CancelOrderRequest -
type CancelOrderResponse ¶
type CancelOrderResponse struct { ReqID int64 `json:"reqid,omitempty"` Event string `json:"event"` Status string `json:"status"` ErrorMessage string `json:"errorMessage,omitempty"` }
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 ¶
UnmarshalJSON - unmarshal candle update
type DecimalValues ¶
DecimalValues - data structure for decimal ticker data
func (*DecimalValues) UnmarshalJSON ¶
func (v *DecimalValues) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshal ticker update
type EditOrderRequest ¶
type EditOrderRequest struct { AuthRequest OrderID string `json:"orderid,omitempty"` ReqID int64 `json:"reqid,omitempty"` Pair string `json:"pair"` Price string `json:"price,omitempty"` Price2 string `json:"price2,omitempty"` Volume string `json:"volume,omitempty"` OFlags string `json:"oflags,omitempty"` NewUserRef string `json:"newuserref,omitempty"` Validate string `json:"validate,omitempty"` }
EditOrderRequest -
type EditOrderResponse ¶
type EditOrderResponse struct { Event string `json:"event"` TxID string `json:"txid,omitempty"` OriginalTxID string `json:"originaltxid,omitempty"` ReqID int64 `json:"reqid,omitempty"` Status string `json:"status"` Description string `json:"descr,omitempty"` ErrorMessage string `json:"errorMessage,omitempty"` }
EditOrderResponse -
type EventType ¶
type EventType struct {
Event string `json:"event"`
}
EventType - data structure for parsing events
type IntValues ¶
IntValues - data structure for int ticker data
func (*IntValues) UnmarshalJSON ¶
UnmarshalJSON - unmarshal ticker update
type Kraken ¶
type Kraken struct {
// contains filtered or unexported fields
}
Kraken -
func (*Kraken) AddOrder ¶
func (k *Kraken) AddOrder(req AddOrderRequest) error
AddOrder - method adds new order.
func (*Kraken) Authenticate ¶
Authenticate - authenticate in private Websocket API
func (*Kraken) CancelAllOrdersAfter ¶
CancelAllOrdersAfter - provides a `Dead Man's Switch` mechanism to protect the client from network malfunction, extreme latency or unexpected matching engine downtime. The client can send a request with a timeout (in seconds), that will start a countdown timer which will cancel *all* client orders when the timer expires.
func (*Kraken) CancelOrder ¶
CancelOrder - method cancels order or list of orders.
func (*Kraken) EditOrder ¶
func (k *Kraken) EditOrder(req EditOrderRequest) error
EditOrder - method adds new order.
func (*Kraken) Listen ¶
Listen provides an atomic interface for receiving API messages. When a websocket connection is terminated, the publisher channel will close.
func (*Kraken) SubscribeBook ¶
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 ¶
SubscribeCandles - Open High Low Close (Candle) feed for a currency pair and interval period.
func (*Kraken) SubscribeOpenOrders ¶
SubscribeOpenOrders - method tries to subscribe on OpenOrders channel events
func (*Kraken) SubscribeOwnTrades ¶
SubscribeOwnTrades - method tries to subscribe on OwnTrades channel events
func (*Kraken) SubscribeSpread ¶
SubscribeSpread - Spread feed to show best bid and ask price for a currency pair
func (*Kraken) SubscribeTicker ¶
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 ¶
SubscribeTrades - Trade feed for a currency pair.
func (*Kraken) Unsubscribe ¶
Unsubscribe - Unsubscribe from single subscription, can specify multiple currency pairs.
func (*Kraken) UnsubscribeBook ¶
UnsubscribeBook - Unsubscribe from order book 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 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 ¶
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 OrderBook ¶
type OrderBook struct { Asks *OrderBookSide Bids *OrderBookSide }
OrderBook -
func NewOrderBook ¶
NewOrderBook - creates order book.
depth - is a requested depth from Kraken pricePrecision - count of valuable signs after dot in price, which is required for checksum verification volumePrecision - count of valuable signs after dot in volume, which is required for checksum verification
func (*OrderBook) ApplyUpdate ¶
func (o *OrderBook) ApplyUpdate(upd OrderBookUpdate, verify bool) error
ApplyUpdate - applies updates from kraken websocket. If you need to verify checksum, set verify to true.
func (*OrderBook) Checksum ¶
Checksum - computes order book checksum. Details https://docs.kraken.com/websockets/#book-checksum
type OrderBookItem ¶
OrderBookItem - data structure for order book item
func (*OrderBookItem) UnmarshalJSON ¶
func (obi *OrderBookItem) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshal candle update
type OrderBookSide ¶
type OrderBookSide struct {
// contains filtered or unexported fields
}
OrderBookSide -
func (*OrderBookSide) Best ¶
func (o *OrderBookSide) Best() (*decimal.Big, *decimal.Big)
Best - returns best price and volume at this price. If order book is not initialized it returns Zero
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"` UserRef json.Number `json:"userref"` }
OwnTrade - Own trades.
type PingRequest ¶
PingRequest - data structure for ping request
type PongResponse ¶
PongResponse - data structure for ping response
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 ¶
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 ¶
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