krakenapi

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

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

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 16 Imported by: 0

README

Kraken GO API Client

build status

A simple API Client for the Kraken Trading platform.

Example usage:

package main

import (
	"fmt"
	"log"

	"github.com/beldur/kraken-go-api-client"
)

func main() {
	api := krakenapi.New("KEY", "SECRET")
	result, err := api.Query("Ticker", map[string]string{
		"pair": "XXBTZEUR",
	})

	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Result: %+v\n", result)

	// There are also some strongly typed methods available
	ticker, err := api.Ticker(krakenapi.XXBTZEUR)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ticker.XXBTZEUR.OpeningPrice)
}

Contributors

  • Piega
  • Glavic
  • MarinX
  • bjorand
  • khezen

Documentation

Index

Constants

View Source
const (
	// APIURL is the official Kraken API Endpoint
	APIURL = "https://api.kraken.com"
	// APIVersion is the official Kraken API Version Number
	APIVersion = "0"
	// APIUserAgent identifies this library with the Kraken API
	APIUserAgent = "Kraken GO API Agent (https://github.com/beldur/kraken-go-api-client)"
)
View Source
const (
	MinimumREP  = 0.3
	MinimumXBT  = 0.002
	MinimumBCH  = 0.002
	MinimumDASH = 0.03
	MinimumDOGE = 3000.0
	MinimumEOS  = 3.0
	MinimumETH  = 0.02
	MinimumETC  = 0.3
	MinimumGNO  = 0.03
	MinimumICN  = 2.0
	MinimumLTC  = 0.1
	MinimumMLN  = 0.1
	MinimumXMR  = 0.1
	MinimumXRP  = 30.0
	MinimumXLM  = 300.0
	MinimumZEC  = 0.02
	MinimumUSDT = 5.0
)

These represent the minimum order sizes for the respective coins Should be monitored through here: https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size-

View Source
const (
	BUY    = "b"
	SELL   = "s"
	MARKET = "m"
	LIMIT  = "l"
)
View Source
const (
	OTMarket              = "market"
	OTLimit               = "limit"                  // (price = limit price)
	OTStopLoss            = "stop-loss"              // (price = stop loss price)
	OTTakeProfi           = "take-profit"            // (price = take profit price)
	OTStopLossProfit      = "stop-loss-profit"       // (price = stop loss price, price2 = take profit price)
	OTStopLossProfitLimit = "stop-loss-profit-limit" // (price = stop loss price, price2 = take profit price)
	OTStopLossLimit       = "stop-loss-limit"        // (price = stop loss trigger price, price2 = triggered limit price)
	OTTakeProfitLimit     = "take-profit-limit"      // (price = take profit trigger price, price2 = triggered limit price)
	OTTrailingStop        = "trailing-stop"          // (price = trailing stop offset)
	OTTrailingStopLimit   = "trailing-stop-limit"    // (price = trailing stop offset, price2 = triggered limit offset)
	OTStopLossAndLimit    = "stop-loss-and-limit"    // (price = stop loss price, price2 = limit price)
	OTSettlePosition      = "settle-position"
)

OrderTypes for AddOrder

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOrderResponse

type AddOrderResponse struct {
	Description    OrderDescription `json:"descr"`
	TransactionIds []string         `json:"txid"`
}

type AssetInfo

type AssetInfo struct {
	// Alternate name
	Altname string
	// Asset class
	AssetClass string `json:"aclass"`
	// Scaling decimal places for record keeping
	Decimals int
	// Scaling decimal places for output display
	DisplayDecimals int `json:"display_decimals"`
}

AssetInfo represents an asset information

type AssetPairInfo

type AssetPairInfo struct {
	// Alternate pair name
	Altname string `json:"altname"`
	// Asset class of base component
	AssetClassBase string `json:"aclass_base"`
	// Asset id of base component
	Base string `json:"base"`
	// Asset class of quote component
	AssetClassQuote string `json:"aclass_quote"`
	// Asset id of quote component
	Quote string `json:"quote"`
	// Volume lot size
	Lot string `json:"lot"`
	// Scaling decimal places for pair
	PairDecimals int `json:"pair_decimals"`
	// Scaling decimal places for volume
	LotDecimals int `json:"lot_decimals"`
	// Amount to multiply lot volume by to get currency volume
	LotMultiplier int `json:"lot_multiplier"`
	// Array of leverage amounts available when buying
	LeverageBuy []float64 `json:"leverage_buy"`
	// Array of leverage amounts available when selling
	LeverageSell []float64 `json:"leverage_sell"`
	// Fee schedule array in [volume, percent fee] tuples
	Fees [][]float64 `json:"fees"`
	// // Maker fee schedule array in [volume, percent fee] tuples (if on maker/taker)
	FeesMaker [][]float64 `json:"fees_maker"`
	// // Volume discount currency
	FeeVolumeCurrency string `json:"fee_volume_currency"`
	// Margin call level
	MarginCall int `json:"margin_call"`
	// Stop-out/Liquidation margin level
	MarginStop int `json:"margin_stop"`
}

AssetPairInfo represents asset pair information

type AssetPairsResponse

type AssetPairsResponse struct {
	KrakenResponse
	Result map[string]AssetPairInfo `json:"result"`
}

AssetPairsResponse includes asset pair informations

type AssetsResponse

type AssetsResponse struct {
	Assets map[string]AssetInfo
}

AssetsResponse includes asset informations

type BalanceResponse

type BalanceResponse struct {
	Balances map[string]float64
}

type CancelOrderResponse

type CancelOrderResponse struct {
	Count   int  `json:"count"`
	Pending bool `json:"pending"`
}

type ClosedOrdersResponse

type ClosedOrdersResponse struct {
	Closed map[string]Order `json:"closed"`
	Count  int              `json:"count"`
}

ClosedOrdersResponse represents a list of closed orders, indexed by id

type DepositAddressesResponse

type DepositAddressesResponse []struct {
	Address  string `json:"address"`
	Expiretm string `json:"expiretm"`
	New      bool   `json:"new,omitempty"`
}

DepositAddressesResponse is the response type of a DepositAddresses query to the Kraken API.

type DepthResponse

type DepthResponse struct {
	KrakenResponse
	Result map[string]OrderBook `json:"result"`
}

DepthResponse is a response from kraken to Depth request.

type KrakenApi

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

KrakenApi represents a Kraken API Client connection

func New

func New(key, secret string) *KrakenApi

New creates a new Kraken API client

func NewWithClient

func NewWithClient(key, secret string, httpClient *http.Client) *KrakenApi

func (*KrakenApi) AddOrder

func (api *KrakenApi) AddOrder(pair string, direction string, orderType string, volume string, args map[string]string) (*AddOrderResponse, error)

AddOrder adds new order

func (*KrakenApi) AssetPairs

func (api *KrakenApi) AssetPairs() (*AssetPairsResponse, error)

AssetPairs returns the servers available asset pairs

func (*KrakenApi) Assets

func (api *KrakenApi) Assets() (*AssetsResponse, error)

Assets returns the servers available assets

func (*KrakenApi) Balance

func (api *KrakenApi) Balance() (*BalanceResponse, error)

Balance returns all account asset balances

func (*KrakenApi) CancelOrder

func (api *KrakenApi) CancelOrder(txid string) (*CancelOrderResponse, error)

CancelOrder cancels order

func (*KrakenApi) ClosedOrders

func (api *KrakenApi) ClosedOrders(args map[string]string) (*ClosedOrdersResponse, error)

ClosedOrders returns all closed orders

func (*KrakenApi) DepositAddresses

func (api *KrakenApi) DepositAddresses(asset string, method string) (*DepositAddressesResponse, error)

DepositAddresses returns deposit addresses

func (*KrakenApi) Depth

func (api *KrakenApi) Depth(pair string, count int) (*OrderBook, error)

Depth returns the order book for given pair and orders count.

func (*KrakenApi) Ledgers

func (api *KrakenApi) Ledgers(args map[string]string) (*LedgersResponse, error)

Ledgers returns ledgers informations

func (*KrakenApi) OpenOrders

func (api *KrakenApi) OpenOrders(args map[string]string) (*OpenOrdersResponse, error)

OpenOrders returns all open orders

func (*KrakenApi) Query

func (api *KrakenApi) Query(method string, data map[string]string) (interface{}, error)

Query sends a query to Kraken api for given method and parameters

func (*KrakenApi) QueryOrders

func (api *KrakenApi) QueryOrders(txids string, args map[string]string) (*QueryOrdersResponse, error)

QueryOrders shows order

func (*KrakenApi) Ticker

func (api *KrakenApi) Ticker(pairs ...string) (*TickerResponse, error)

Ticker returns the ticker for given comma separated pairs

func (*KrakenApi) Time

func (api *KrakenApi) Time() (*TimeResponse, error)

Time returns the server's time

func (*KrakenApi) TradeBalance

func (api *KrakenApi) TradeBalance(args map[string]string) (*TradeBalanceResponse, error)

TradeBalance returns trade balance info

func (*KrakenApi) Trades

func (api *KrakenApi) Trades(pair string, since int64) (*TradesResponse, error)

Trades returns the recent trades for given pair

func (*KrakenApi) TradesHistory

func (api *KrakenApi) TradesHistory(start int64, end int64, args map[string]string) (*TradesHistoryResponse, error)

func (*KrakenApi) Withdraw

func (api *KrakenApi) Withdraw(asset string, key string, amount *big.Float) (*WithdrawResponse, error)

Withdraw executes a withdrawal, returning a reference ID

func (*KrakenApi) WithdrawInfo

func (api *KrakenApi) WithdrawInfo(asset string, key string, amount *big.Float) (*WithdrawInfoResponse, error)

WithdrawInfo returns withdrawal information

type KrakenResponse

type KrakenResponse struct {
	Error []string `json:"error"`
}

KrakenResponse wraps the Kraken API JSON response

type LedgerInfo

type LedgerInfo struct {
	RefID   string    `json:"refid"`
	Time    float64   `json:"time"`
	Type    string    `json:"type"`
	Aclass  string    `json:"aclass"`
	Asset   string    `json:"asset"`
	Amount  big.Float `json:"amount"`
	Fee     big.Float `json:"fee"`
	Balance big.Float `json:"balance"`
}

type LedgersResponse

type LedgersResponse struct {
	Ledger map[string]LedgerInfo `json:"ledger"`
}

LedgersResponse represents an associative array of ledgers infos

type OpenOrdersResponse

type OpenOrdersResponse struct {
	Open  map[string]Order `json:"open"`
	Count int              `json:"count"`
}

type Order

type Order struct {
	TransactionID  string           `json:"-"`
	ReferenceID    string           `json:"refid"`
	UserRef        int              `json:"userref"`
	Status         string           `json:"status"`
	OpenTime       float64          `json:"opentm"`
	StartTime      float64          `json:"starttm"`
	ExpireTime     float64          `json:"expiretm"`
	Description    OrderDescription `json:"descr"`
	Volume         string           `json:"vol"`
	VolumeExecuted float64          `json:"vol_exec,string"`
	Cost           float64          `json:"cost,string"`
	Fee            float64          `json:"fee,string"`
	Price          float64          `json:"price,string"`
	StopPrice      float64          `json:"stopprice.string"`
	LimitPrice     float64          `json:"limitprice,string"`
	Misc           string           `json:"misc"`
	OrderFlags     string           `json:"oflags"`
	CloseTime      float64          `json:"closetm"`
	Reason         string           `json:"reason"`
}

Order represents a single order

type OrderBook

type OrderBook struct {
	Asks []OrderBookItem `json:"asks"`
	Bids []OrderBookItem `json:"bids"`
}

OrderBook contains top asks and bids.

type OrderBookItem

type OrderBookItem struct {
	Price  float64
	Amount float64
	Ts     int64
}

OrderBookItem is a piece of information about an order.

func (*OrderBookItem) UnmarshalJSON

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

UnmarshalJSON takes a json array from kraken and converts it into an OrderBookItem.

type OrderDescription

type OrderDescription struct {
	AssetPair      string `json:"pair"`
	Close          string `json:"close"`
	Leverage       string `json:"leverage"`
	Order          string `json:"order"`
	OrderType      string `json:"ordertype"`
	PrimaryPrice   string `json:"price"`
	SecondaryPrice string `json:"price2"`
	Type           string `json:"type"`
}

OrderDescription represents an orders description

type PairTickerInfo

type PairTickerInfo struct {
	// Ask array(<price>, <whole lot volume>, <lot volume>)
	Ask []string `json:"a"`
	// Bid array(<price>, <whole lot volume>, <lot volume>)
	Bid []string `json:"b"`
	// Last trade closed array(<price>, <lot volume>)
	Close []string `json:"c"`
	// Volume array(<today>, <last 24 hours>)
	Volume []string `json:"v"`
	// Volume weighted average price array(<today>, <last 24 hours>)
	VolumeAveragePrice []string `json:"p"`
	// Number of trades array(<today>, <last 24 hours>)
	Trades []int `json:"t"`
	// Low array(<today>, <last 24 hours>)
	Low []string `json:"l"`
	// High array(<today>, <last 24 hours>)
	High []string `json:"h"`
	// Today's opening price
	OpeningPrice float64 `json:"o,string"`
}

PairTickerInfo represents ticker information for a pair

type QueryOrdersResponse

type QueryOrdersResponse map[string]Order

type TickerResponse

type TickerResponse struct {
	KrakenResponse
	Result map[string]PairTickerInfo `json:"result"`
}

TickerResponse includes the requested ticker pairs

func (*TickerResponse) GetPairTickerInfo

func (v *TickerResponse) GetPairTickerInfo(pair string) PairTickerInfo

GetPairTickerInfo is a helper method that returns given `pair`'s `PairTickerInfo`

type TimeResponse

type TimeResponse struct {
	KrakenResponse
	Result struct {
		// Unix timestamp
		Unixtime int `json:"unixtime"`
		// RFC 1123 time format
		Rfc1123 string `json:"rfc1123"`
	} `json:"result"`
}

TimeResponse represents the server's time

type TradeBalanceResponse

type TradeBalanceResponse struct {
	EquivalentBalance         float64 `json:"eb,string"`
	TradeBalance              float64 `json:"tb,string"`
	MarginOP                  float64 `json:"m,string"`
	UnrealizedNetProfitLossOP float64 `json:"n,string"`
	CostBasisOP               float64 `json:"c,string"`
	CurrentValuationOP        float64 `json:"v,string"`
	Equity                    float64 `json:"e,string"`
	FreeMargin                float64 `json:"mf,string"`
	MarginLevel               float64 `json:"ml,string"`
}

type TradeHistoryInfo

type TradeHistoryInfo struct {
	TransactionId string  `json:"ordertxid"`
	PostxId       string  `json:"postxid"`
	AssetPair     string  `json:"pair"`
	Time          float64 `json:"time"`
	Type          string  `json:"type"`
	OrderType     string  `json:"ordertype"`
	Price         float64 `json:"price,string"`
	Cost          float64 `json:"cost,string"`
	Fee           float64 `json:"fee,string"`
	Volume        float64 `json:"vol,string"`
	Margin        float64 `json:"margin,string"`
	Misc          string  `json:"misc"`
}

type TradeInfo

type TradeInfo struct {
	Price         float64 `json:"0",string`
	Volume        float64 `json:"1",string`
	Time          float64 `json:"2"`
	BuySell       string  `json:"3"`
	MarketLimit   string  `json:"4"`
	Buy           bool
	Sell          bool
	Market        bool
	Limit         bool
	Miscellaneous string `json:"5"`
}

TradeInfo represents a trades information

type TradesHistoryResponse

type TradesHistoryResponse struct {
	Trades map[string]TradeHistoryInfo `json:"trades"`
	Count  int                         `json:"count"`
}

TradesHistoryResponse represents a list executed trade

type TradesResponse

type TradesResponse struct {
	KrakenResponse
	Result struct {
		Last   int `json:"last,string"`
		Trades map[string]TradeInfo
	} `json:"result"`
}

TradesResponse represents a list of the last trades

type WithdrawInfoResponse

type WithdrawInfoResponse struct {
	Method string    `json:"method"`
	Limit  big.Float `json:"limit"`
	Amount big.Float `json:"amount"`
	Fee    big.Float `json:"fee"`
}

WithdrawInfoResponse is the response type showing withdrawal information for a selected withdrawal method.

type WithdrawResponse

type WithdrawResponse struct {
	RefID int `json:"refid"`
}

WithdrawResponse is the response type of a Withdraw query to the Kraken API.

Jump to

Keyboard shortcuts

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