krakex v0.1.1 Krakex View Source

Kraken API Client.

The Kraken API is divided into several sections:

Public market data

Private user data

Private user trading

  • add_order/5 (not implemented) - Add standard order.
  • cancel_order/2 (not implemented) - Cancel open order.

Private user funding

  • deposit_methods/3 (not implemented) - Get deposit methods.
  • deposit_addresses/4 (not implemented) - Get deposit addresses.
  • deposit_status/4 (not implemented) - Get status of recent deposits.
  • withdraw_info/5 (not implemented) - Get withdrawal information.
  • withdraw/5 (not implemented) - Withdraw funds.
  • withdraw_status/3 (not implemented) - Get status of recent withdrawals.
  • withdraw_cancel/4 (not implemented) - Request withdrawal cancelation.

Link to this section Summary

Link to this section Functions

Link to this function asset_pairs(client \\ Krakex.API.public_client(), opts \\ []) View Source
asset_pairs(Krakex.Client.t(), keyword()) :: Krakex.API.response()

Get tradable asset pairs.

Takes the following keyword options:

  • :info - info to retrieve.

    • "info" - all info (default).
    • "leverage" - leverage info.
    • "fees" - fees schedule.
    • "margin" - margin info.
  • :pair - list of asset pairs to get info on. Returns all (default)

Returns a map of asset pairs and a map of their info with the fields:

  • "altname" - alternate pair name.
  • "aclass_base" - asset class of base component.
  • "base" - asset id of base component.
  • "aclass_quote" - asset class of quote component.
  • "quote" - asset id of quote component.
  • "lot" - volume lot size.
  • "pair_decimals" - scaling decimal places for pair.
  • "lot_decimals" - scaling decimal places for volume.
  • "lot_multiplier" - amount to multiply lot volume by to get currency volume.
  • "leverage_buy" - array of leverage amounts available when buying.
  • "leverage_sell" - array of leverage amounts available when selling.
  • "fees" - fee schedule array in [volume, percent fee] tuples.
  • "fees_maker" - maker fee schedule array in [volume, percent fee] tuples (if on maker/taker).
  • "fee_volume_currency" - volume discount currency.
  • "margin_call" - margin call level.
  • "margin_stop" - stop-out/liquidation margin level.

Example response:

{:ok, %{"BCHEUR" => %{"aclass_base" => "currency", "aclass_quote" => "currency",
                      "altname" => "BCHEUR", "base" => "BCH", "fee_volume_currency" => "ZUSD",
                      "fees" => [[0, 0.26], [50000, 0.24], [100000, 0.22], [250000, 0.2],
                      [500000, 0.18], [1000000, 0.16], [2500000, 0.14], [5000000, 0.12],
                      [10000000, 0.1]],
                      "fees_maker" => [[0, 0.16], [50000, 0.14], [100000, 0.12], [250000, 0.1],
                      [500000, 0.08], [1000000, 0.06], [2500000, 0.04], [5000000, 0.02],
                      [10000000, 0]], "leverage_buy" => [], "leverage_sell" => [],
                      "lot" => "unit", "lot_decimals" => 8, "lot_multiplier" => 1,
                      "margin_call" => 80, "margin_stop" => 40, "pair_decimals" => 1,
                      "quote" => "ZEUR"}}
Link to this function assets(client \\ Krakex.API.public_client(), opts \\ []) View Source
assets(Krakex.Client.t(), keyword()) :: Krakex.API.response()

Get asset info.

Takes the following keyword options:

  • :info - info to retrieve. "info" (default)
  • :aclass - asset class. "currency" (default)
  • :asset - list of assets to get info on. Returns all (default)

Returns a map of asset names and a map of their info with the fields:

  • "altname" - alternate name.
  • "aclass" - asset class.
  • "decimals" - scaling decimal places for record keeping.
  • "display_decimals" - scaling decimal places for output display.

Example response:

{:ok, %{"BCH" => %{"aclass" => "currency", "altname" => "BCH",
                   "decimals" => 10, "display_decimals" => 5}}}
Link to this function balance(client \\ Krakex.API.private_client()) View Source

Get account balance.

Returns a map with the asset names and balance amount.

Example response:

{:ok, %{"XXBT" => "0.0400000000", "XXRP" => "160.00000000", "ZEUR" => "67.6613"}}
Link to this function closed_orders(client \\ Krakex.API.private_client(), opts \\ []) View Source
Link to this function depth(client \\ Krakex.API.public_client(), pair, opts \\ []) View Source
depth(Krakex.Client.t(), binary(), keyword()) :: Krakex.API.response()

Get order book.

Returns the market depth for an asset pair.

Takes an asset pair and the following keyword options:

  • :count - maximum number of asks/bids.

Returns a map of the asset pair and a map of the info with the fields:

  • "asks" - ask side array of array entries (price, volume, timestamp).
  • "bids" - bid side array of array entries (price, volume, timestamp).

Example response:

{:ok,
    %{"BCHEUR" => %{"asks" => [["2033.900000", "4.937", 1515082275],
                              ["2034.000000", "0.548", 1515081910],
                              ["2034.500000", "0.005", 1515081281],
                              ["2034.800000", "4.637", 1515082048]],
                    "bids" => [["2025.000000", "1.024", 1515081702],
                              ["2022.200000", "0.140", 1515078885],
                              ["2022.100000", "0.280", 1515078852],
                              ["2021.400000", "0.248", 1515080222]]}}}
Link to this function ledgers(client \\ Krakex.API.private_client(), offset, opts \\ []) View Source
Link to this function ohlc(client \\ Krakex.API.public_client(), pair, opts \\ []) View Source
ohlc(Krakex.Client.t(), binary(), keyword()) :: Krakex.API.response()

Get OHLC data.

An open-high-low-close chart is a type of chart typically used to illustrate movements in the price of a financial instrument over time. Each vertical line on the chart shows the price range (the highest and lowest prices) over one unit of time, e.g., one day or one hour Takes list of asset pairs to get info on.

Takes an asset pair and the following keyword options:

  • :interval - time frame interval in minutes. 1 (default), 5, 15, 30, 60, 240, 1440, 10080, 21600
  • :since - return committed OHLC data since given id (exclusive).

Returns a map with the asset pair and a list of lists with the entries (time, open, high, low, close, vwap, volume, count) and:

  • "last" - id to be used as since when polling for new, committed OHLC data.

Note: the last entry in the OHLC array is for the current, not-yet-committed frame and will always be present, regardless of the value of :since.

Example response:

{:ok,
  %{"BCHEUR" => [[1515037200, "2051.7", "2051.7", "2051.7", "2051.7", "0.0", "0.00000000", 0],
      [1515037260, "2051.7", "2051.7", "2045.0", "2045.0", "2045.0", "0.01500000", 1],
      [1515037320, "2045.0", "2050.8", "2045.0", "2050.8", "2050.7", "2.37135868", 2],
      [1515037380, "2050.8", "2050.8", "2050.8", "2050.8", "0.0", "0.00000000", 0],
      ...],
      "last" => 1515080280}}
Link to this function open_orders(client \\ Krakex.API.private_client(), opts \\ []) View Source
Link to this function open_positions(client \\ Krakex.API.private_client(), tx_ids, opts \\ []) View Source
Link to this function query_ledgers(client \\ Krakex.API.private_client(), ledger_ids) View Source
Link to this function query_orders(client \\ Krakex.API.private_client(), tx_ids, opts \\ []) View Source
Link to this function query_trades(client \\ Krakex.API.private_client(), tx_ids, opts \\ []) View Source
Link to this function server_time(client \\ Krakex.API.public_client()) View Source
server_time(Krakex.Client.t()) :: Krakex.API.response()

Get server time.

This is to aid in approximating the skew time between the server and client.

Returns a map with the fields:

  • "unixtime" - as unix timestamp.
  • "rfc1123" - as RFC 1123 time format.

Example response:

 {:ok, %{"rfc1123" => "Thu,  4 Jan 18 14:57:58 +0000", "unixtime" => 1515077878}}
Link to this function spread(client \\ Krakex.API.public_client(), pair, opts \\ []) View Source
spread(Krakex.Client.t(), binary(), keyword()) :: Krakex.API.response()

Get recent spread data.

Returns the spread data for an asset pair.

Takes an asset pair and the following keyword options:

  • :since - return spread data since given id (inclusive).

Returns a map with the asset pair and a list of lists with the entries (time, bid, ask) and:

  • "last" - id to be used as since when polling for new trade data.

Example response:

{:ok,
  %{"BCHEUR" => [[1515079584, "2025.000000", "2025.000000"],
                [1515079584, "2025.000000", "2036.100000"],
                [1515079594, "2025.000000", "2025.000000"],
                [1515079596, "2025.000000", "2026.000000"],
                [1515080461, "2025.500000", "2034.100000"],
                [1515080462, "2025.000000", "2034.100000"]],
    "last" => 1515083299}}
Link to this function ticker(client \\ Krakex.API.public_client(), pairs) View Source
ticker(Krakex.Client.t(), [binary()]) :: Krakex.API.response()

Get ticker information.

Takes list of asset pairs to get info on.

Returns a map of asset pairs and a map of their ticker info with the fields:

  • "a" - ask array(price, whole lot volume, lot volume).
  • "b" - bid array(price, whole lot volume, lot volume).
  • "c" - last trade closed array(price, lot volume).
  • "v" - volume array(today, last 24 hours).
  • "p" - volume weighted average price array(today, last 24 hours).
  • "t" - number of trades array(today, last 24 hours).
  • "l" - low array(today, last 24 hours).
  • "h" - high array(today, last 24 hours).
  • "o" - today’s opening price.

Example response:

{:ok,
  %{"BCHEUR" => %{"a" => ["2034.800000", "1", "1.000"],
      "b" => ["2025.000000", "8", "8.000"], "c" => ["2025.000000", "0.03660000"],
      "h" => ["2140.000000", "2227.600000"],
      "l" => ["1942.000000", "1942.000000"], "o" => "2134.000000",
      "p" => ["2021.440397", "2051.549114"], "t" => [3824, 6704],
      "v" => ["1956.76538027", "4086.36386115"]}}}
Link to this function trade_balance(client \\ Krakex.API.private_client(), opts \\ []) View Source
trade_balance(Krakex.Client.t(), keyword()) :: Krakex.API.response()

Get trade balance.

Takes the following keyword options:

  • :aclass - asset class. "currency" (default)
  • :asset - base asset used to determine balance. "ZUSD" (default)

Returns a map with the fields:

  • "eb" - equivalent balance (combined balance of all currencies).
  • "tb" - trade balance (combined balance of all equity currencies).
  • "m" - margin amount of open positions.
  • "n" - unrealized net profit/loss of open positions.
  • "c" - cost basis of open positions.
  • "v" - current floating valuation of open positions.
  • "e" - equity = trade balance + unrealized net profit/loss.
  • "mf" - free margin = equity - initial margin (maximum margin available to open new positions).
  • "ml" - margin level = (equity / initial margin) * 100.

Note: Rates used for the floating valuation is the midpoint of the best bid and ask prices.

Example response:

{:ok,
  %{"c" => "0.0000", "e" => "725.4974", "eb" => "1177.9857", "m" => "0.0000",
    "mf" => "725.4974", "n" => "0.0000", "tb" => "725.4974", "v" => "0.0000"}}
Link to this function trade_volume(client \\ Krakex.API.private_client(), pairs, opts \\ []) View Source
Link to this function trades(client \\ Krakex.API.public_client(), pair, opts \\ []) View Source
trades(Krakex.Client.t(), binary(), keyword()) :: Krakex.API.response()

Get recent trades.

Returns the trade data for an asset pair.

Takes an asset pair and the following keyword options:

  • :since - return committed OHLC data since given id (exclusive).

Returns a map with the asset pair and a list of lists with the entries (price, volume, time, buy/sell, market/limit, miscellaneous) and:

  • "last" - id to be used as since when polling for new trade data.

Example response:

{:ok,
  %{"BCHEUR" => [["2008.100000", "0.09000000", 1515066097.1379, "b", "m", ""],
                ["2008.200000", "0.24850000", 1515066097.1663, "b", "m", ""],
                ["2008.300000", "4.36233575", 1515066097.1771, "b", "m", ""],
                ["2005.000000", "0.04107303", 1515066117.0598, "s", "l", ""],
                ["2008.000000", "0.07700000", 1515066117.389, "b", "l", ""],
  "last" => "1515076587511702121"}}
Link to this function trades_history(client \\ Krakex.API.private_client(), offset, opts \\ []) View Source