Krakex (krakex v0.5.0) View Source

Kraken API Client.

The Kraken API is divided into several sections:

Public market data

Private user data

Private user trading

Private user funding

  • deposit_methods/3 - Get deposit methods.
  • deposit_addresses/4 - Get deposit addresses.
  • deposit_status/4 - Get status of recent deposits.
  • withdraw_info/5 - 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

Functions

Link to this section Functions

Link to this function

add_order(client \\ Krakex.API.private_client(), pair, type, order_type, volume, opts \\ [])

View Source

Specs

Add standard order.

Takes the following arguments:

  • asset pair
  • type - "buy" or "sell".
  • ordertype - one of the following:
    • "market"
    • "limit" - (price = limit price).
    • "stop-loss" - (price = stop loss price).
    • "take-profit" - (price = take profit price).
    • "stop-loss-profit" - (price = stop loss price, price2 = take profit price).
    • "stop-loss-profit-limit" - (price = stop loss price, price2 = take profit price).
    • "stop-loss-limit" - (price = stop loss trigger price, price2 = triggered limit price).
    • "take-profit-limit" - (price = take profit trigger price, price2 = triggered limit price).
    • "trailing-stop" - (price = trailing stop offset).
    • "trailing-stop-limit" - (price = trailing stop offset, price2 = triggered limit offset).
    • "stop-loss-and-limit" - (price = stop loss price, price2 = limit price).
    • "settle-position"
  • volume - order volume in lots.

and the following keyword options:

  • :price - price (dependent upon ordertype).
  • :price2 - secondary price (dependent upon ordertype).
  • :leverage - amount of leverage desired (default = none).
  • :oflags - list of order flags:
    • :viqc - volume in quote currency (not available for leveraged orders).
    • :fcib - prefer fee in base currency.
    • :fciq - prefer fee in quote currency.
    • :nompp - no market price protection.
    • :post - post only order (available when ordertype = limit).
  • :starttm - scheduled start time:
    • 0 - now (default).
    • +<n> - schedule start time <n> seconds from now.
    • <n> - unix timestamp of start time.
  • :expiretm - expiration time:
    • 0 - no expiration (default).
    • +<n> - expire <n> seconds from now.
    • <n> - unix timestamp of expiration time.
  • :userref - user reference id. 32-bit signed number.
  • :validate - validate inputs only (does not submit order).

Returns a map with the following fields:

  • "descr" - order description info.
    • "order" - order description.
    • "close" - onditional close order description (if conditional close set).
  • "txid" - array of transaction ids for order (if order was added successfully).

Note:

  • See asset_pairs/2 for specifications on asset pair prices, lots, and leverage.
  • Prices can be preceded by +, -, or # to signify the price as a relative amount (with the exception of trailing stops, which are always relative). + adds the amount to the current offered price. - subtracts the amount from the current offered price. # will either add or subtract the amount to the current offered price, depending on the type and order type used. Relative prices can be suffixed with a % to signify the relative amount as a percentage of the offered price.
  • For orders using leverage, 0 can be used for the volume to auto-fill the volume needed to close out your position.
  • If you receive the error "EOrder:Trading agreement required", refer to your API key management page for further details.

Example response:

{:ok,
  %{
    "descr" => %{"order" => "sell 100.00000000 XRPEUR @ limit 1.50000"},
    "txid" => ["OL63HZ-UFU23-CKEBRA"]
  }}
Link to this function

asset_pairs(client \\ Krakex.API.public_client(), opts \\ [])

View Source

Specs

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

Specs

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

Specs

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

cancel_order(client \\ Krakex.API.private_client(), tx_id)

View Source

Specs

cancel_order(Krakex.Client.t(), binary()) :: Krakex.API.response()

Cancel open order.

Takes a tx_id for the order to cancel.

Returns a map with the following fields:

  • "count" - number of orders canceled.
  • "pending" - if set, order(s) is/are pending cancellation.

Note: tx_id may be a user reference id.

Example response:

{:ok, %{"count" => 1}}
Link to this function

closed_orders(client \\ Krakex.API.private_client(), opts \\ [])

View Source

Specs

closed_orders(Krakex.Client.t(), keyword()) :: Krakex.API.response()

Get closed orders.

Takes the following keyword options:

  • :trades - whether or not to include trades in output. false (default)
  • :userref - restrict results to given user reference id.
  • :start - starting unix timestamp or order tx id of results (exclusive).
  • :end - ending unix timestamp or order tx id of results (inclusive).
  • :ofs - result offset.
  • :closetime - which time to use.
    • "open"
    • "close"
    • "both" - (default).

Returns a map with the key "closed" and a map of closed orders as the value. Additionally, the map may contain:

  • "count" - amount of available order info matching criteria.

The map of closed orders has the txid as the key and the value is a map with the same fields as in open orders (see open_orders/2) but can contain the additional fields:

  • "closetm" - unix timestamp of when order was closed.
  • "reason" - additional info on status (if any).

Note: Times given by order tx ids are more accurate than unix timestamps. If an order tx id is given for the time, the order's open time is used.

Example response:

{:ok,
  %{
    "closed" => %{
      "O5KKP6-NXBOJ-KPXCTA" => %{
        "closetm" => 1516182880.603,
        "cost" => "57.0",
        "descr" => %{
          "close" => "",
          "leverage" => "none",
          "order" => "buy 0.00670000 XBTEUR @ market",
          "ordertype" => "market",
          "pair" => "XBTEUR",
          "price" => "0",
          "price2" => "0",
          "type" => "buy"
        },
        "expiretm" => 0,
        "fee" => "0.00000",
        "limitprice" => "0.00000",
        "misc" => "",
        "oflags" => "fciq",
        "opentm" => 1516182880.5874,
        "price" => "8510.4",
        "reason" => nil,
        "refid" => nil,
        "starttm" => 0,
        "status" => "closed",
        "stopprice" => "0.00000",
        "userref" => 0,
        "vol" => "0.00670000",
        "vol_exec" => "0.00670000"
      }
    }
  }}
Link to this function

deposit_addresses(client \\ Krakex.API.private_client(), asset, method, opts \\ [])

View Source

Specs

deposit_addresses(Krakex.Client.t(), binary(), binary(), keyword()) ::
  Krakex.API.response()

Get deposit addresses.

Takes an asset, a deposit method, and the following keyword options:

  • :aclass - asset class. "currency" (default)
  • :new - whether or not to generate a new address. (default: false)

Returns a list of maps with the following fields:

  • "address" - deposit address.
  • "expiretm" - expiration time in unix timestamp, or 0 if not expiring.
  • "new" - whether or not address has ever been used.

Example response:

{:ok,
  [
    %{
      "address" => "38mKXaQiKBZn549tx41igEdLPPYMVeD34h",
      "expiretm" => "0",
      "new" => true
    }
  ]}
Link to this function

deposit_methods(client \\ Krakex.API.private_client(), asset, opts \\ [])

View Source

Specs

deposit_methods(Krakex.Client.t(), binary(), keyword()) :: Krakex.API.response()

Get deposit methods.

Takes an asset and the following keyword options:

  • :aclass - asset class. "currency" (default)

Returns a list of maps with the following fields:

  • "method" - name of deposit method.
  • "limit" - maximum net amount that can be deposited right now, or false if no limit.
  • "fee" - amount of fees that will be paid.
  • "address-setup-fee" - whether or not method has an address setup fee (optional).

Example response:

{:ok, [%{"fee" => "5.00", "limit" => "25000.00", "method" => "SynapsePay (US Wire)"}]}
Link to this function

deposit_status(client \\ Krakex.API.private_client(), asset, method, opts \\ [])

View Source

Specs

deposit_status(Krakex.Client.t(), binary(), binary(), keyword()) ::
  Krakex.API.response()

Get status of recent deposits.

Takes an asset, a deposit method, and the following keyword options:

  • :aclass - asset class. "currency" (default)

Returns a list of maps with the following fields:

  • "method" - name of the deposit method used.
  • "aclass" - asset class.
  • "asset" - asset X-ISO4217-A3 code.
  • "refid" - reference id.
  • "txid" - method transaction id.
  • "info" - method transaction information.
  • "amount" - amount deposited.
  • "fee" - fees paid.
  • "time" - unix timestamp when request was made.
  • "status" - status of deposit.
  • "status-prop" - additional status properties (if available):
    • "return" - a return transaction initiated by Kraken.
    • "onhold" - deposit is on hold pending review.
Link to this function

depth(client \\ Krakex.API.public_client(), pair, opts \\ [])

View Source

Specs

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

Specs

Get ledgers info.

Takes an offset and the following keyword options:

  • :aclass - asset class. "currency" (default)
  • :asset - list of assets to restrict output to. "currency" (default)
  • :type - type of ledger to retrieve:
    • "all" - default.
    • "deposit"
    • "withdrawal"
    • "trade"
    • "margin"
  • :start - starting unix timestamp or ledger id of results. (exclusive)
  • :end - ending unix timestamp or ledger id of results. (inclusive)

Returns a map with the ledger id as the key and the value is a map with fields:

  • "refid" - reference id.
  • "time" - unix timestamp of ledger.
  • "type" - type of ledger entry.
  • "aclass" - asset class.
  • "asset" - asset.
  • "amount" - transaction amount.
  • "fee" - transaction fee.
  • "balance" - resulting balance.

Note: Times given by ledger ids are more accurate than unix timestamps.

Link to this function

ohlc(client \\ Krakex.API.public_client(), pair, opts \\ [])

View Source

Specs

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

Specs

Get open orders.

Takes the following keyword options:

  • :trades - whether or not to include trades in output. false (default)
  • :userref - restrict results to given user reference id.

Returns a map with the txid as the key and the value is a map with the fields:

  • "refid" - Referral order transaction id that created this order.
  • "userref" - user reference id.
  • "status" - status of order:
    • "pending" - order pending book entry.
    • "open" - open order.
    • "closed" - closed order.
    • "canceled" - order cancelled.
    • "expired" - order expired.
  • "opentm" - unix timestamp of when order was placed.
  • "starttm" - unix timestamp of order start time (or 0 if not set).
  • "expiretm" - unix timestamp of order end time (or 0 if not set).
  • "descr" - order description info:
    • "pair" - asset pair.
    • "type" - type of order (buy/sell).
    • "ordertype" - order type (See Add standard order).
    • "price" - primary price.
    • "price2" - secondary price.
    • "leverage" - amount of leverage.
    • "order" - order description.
    • "close" - conditional close order description (if conditional close set).
  • "vol" - volume of order (base currency unless viqc set in oflags).
  • "vol_exec" - volume executed (base currency unless viqc set in oflags).
  • "cost" - total cost (quote currency unless unless viqc set in oflags).
  • "fee" - total fee (quote currency).
  • "price" - average price (quote currency unless viqc set in oflags).
  • "stopprice" - stop price (quote currency, for trailing stops).
  • "limitprice" - triggered limit price (quote currency, when limit based order type triggered).
  • "misc" - comma delimited list of miscellaneous info:
    • "stopped" - triggered by stop price.
    • "touched" - triggered by touch price.
    • "liquidated" - liquidation.
    • "partial" - partial fill.
  • "oflags" - comma delimited list of order flags:
    • "viqc" - volume in quote currency.
    • "fcib" - prefer fee in base currency (default if selling).
    • "fciq" - prefer fee in quote currency (default if buying).
    • "nompp" - no market price protection.
  • "trades" - array of trade ids related to order (if trades info requested and data available).

Note: Unless otherwise stated, costs, fees, prices, and volumes are in the asset pair's scale, not the currency's scale. For example, if the asset pair uses a lot size that has a scale of 8, the volume will use a scale of 8, even if the currency it represents only has a scale of 2. Similarly, if the asset pair's pricing scale is 5, the scale will remain as 5, even if the underlying currency has a scale of 8.

Example response:

{:ok,
  %{
    "open" => %{
      "OVAQ4T-WFN4B-J246BW" => %{
        "cost" => "0.00000000",
        "descr" => %{
          "close" => "",
          "leverage" => "none",
          "order" => "sell 100.00000000 XRPEUR @ limit 1.55000",
          "ordertype" => "limit",
          "pair" => "XRPEUR",
          "price" => "1.55000",
          "price2" => "0",
          "type" => "sell"
        },
        "expiretm" => 0,
        "fee" => "0.00000000",
        "limitprice" => "0.00000000",
        "misc" => "",
        "oflags" => "fciq",
        "opentm" => 1516957593.9522,
        "price" => "0.00000000",
        "refid" => nil,
        "starttm" => 0,
        "status" => "open",
        "stopprice" => "0.00000000",
        "userref" => 0,
        "vol" => "100.00000000",
        "vol_exec" => "0.00000000"
      }
    }
  }}
Link to this function

open_positions(client \\ Krakex.API.private_client(), tx_ids, opts \\ [])

View Source

Specs

open_positions(Krakex.Client.t(), [binary()], keyword()) ::
  Krakex.API.response()

Get open positions.

Takes a list of tx_ids to restrict output to and the following keyword options:

  • :docalcs - whether or not to include profit/loss calculations. (default: false)

Returns a map with the txid as the key and the value is a map with fields:

  • "ordertxid" - order responsible for execution of trade.
  • "pair" - asset pair.
  • "time" - unix timestamp of trade.
  • "type" - type of order used to open position (buy/sell).
  • "ordertype" - order type used to open position.
  • "cost" - opening cost of position (quote currency unless viqc set in "oflags").
  • "fee" - opening fee of position (quote currency).
  • "vol" - position volume (base currency unless viqc set in "oflags").
  • "vol_closed" - position volume closed (base currency unless viqc set in "oflags").
  • "margin" - initial margin (quote currency).
  • "value" - current value of remaining position (if docalcs requested. quote currency).
  • "net" - unrealized profit/loss of remaining position (if docalcs requested. quote currency, quote currency scale).
  • "misc" - comma delimited list of miscellaneous info.
  • "oflags" - comma delimited list of order flags:
    • "viqc" - volume in quote currency.

Note: Unless otherwise stated, costs, fees, prices, and volumes are in the asset pair's scale, not the currency's scale.

Link to this function

query_ledgers(client \\ Krakex.API.private_client(), ledger_ids)

View Source

Specs

query_ledgers(Krakex.Client.t(), [binary()]) :: Krakex.API.response()

Query ledgers.

Takes a list of (maximum 20) ledger ids to query info about.

Returns a map with the ledger id as the key and the value is a map with fields as described in ledgers/3.

Link to this function

query_orders(client \\ Krakex.API.private_client(), tx_ids, opts \\ [])

View Source

Specs

query_orders(Krakex.Client.t(), [binary()], keyword()) :: Krakex.API.response()

Query orders info.

Takes a list of (maximum 20) tx_ids to query info about and the following keyword options:

  • :trades - whether or not to include trades in output. false (default)
  • :userref - restrict results to given user reference id.

Returns a map with the txid as the key and the value is a map with the fields as described in open_orders/2.

Link to this function

query_trades(client \\ Krakex.API.private_client(), tx_ids, opts \\ [])

View Source

Specs

query_trades(Krakex.Client.t(), [binary()], keyword()) :: Krakex.API.response()

Query trades info.

Takes a list of (maximum 20) tx_ids and the following keyword options:

  • :trades - whether or not to include trades related to position in output. (default: false)

Returns a map with the same fields as described in trades_history/2.

Link to this function

server_time(client \\ Krakex.API.public_client())

View Source

Specs

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

Specs

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

Specs

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

Specs

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(), opts \\ [])

View Source

Specs

trade_volume(Krakex.Client.t(), keyword()) :: Krakex.API.response()

Get trade volume.

Takes the following keyword options:

  • :pair - list of asset pairs to get fee info on.
  • :"fee-info" - whether or not to include fee info in results.

Returns a map with the following fields:

  • "currency" - volume currency.
  • "volume" - current discount volume.
  • "fees" - map of asset pairs and fee tier info (if requested):
    • "fee" - current fee in percent.
    • "minfee" - minimum fee for pair (if not fixed fee).
    • "maxfee" - maximum fee for pair (if not fixed fee).
    • "nextfee" - next tier's fee for pair (if not fixed fee. nil if at lowest fee tier).
    • "nextvolume" - volume level of next tier (if not fixed fee. nil if at lowest fee tier).
    • "tiervolume" - volume level of current tier (if not fixed fee. nil if at lowest fee tier).
  • "fees_maker" - map of asset pairs and maker fee tier info (if requested) for any pairs on maker/taker schedule:
    • "fee" - current fee in percent.
    • "minfee" - minimum fee for pair (if not fixed fee).
    • "maxfee" - maximum fee for pair (if not fixed fee).
    • "nextfee" - next tier's fee for pair (if not fixed fee. nil if at lowest fee tier).
    • "nextvolume" - volume level of next tier (if not fixed fee. nil if at lowest fee tier).
    • "tiervolume" - volume level of current tier (if not fixed fee. nil if at lowest fee tier).

Note: If an asset pair is on a maker/taker fee schedule, the taker side is given in "fees" and maker side in "fees_maker". For pairs not on maker/taker, they will only be given in "fees".

Link to this function

trades(client \\ Krakex.API.public_client(), pair, opts \\ [])

View Source

Specs

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

Specs

trades_history(Krakex.Client.t(), integer(), keyword()) :: Krakex.API.response()

Get trades history.

Takes an offset and the following keyword options:

  • :type - type of trade:
    • "all" - all types. (default)
    • "any position" - any position (open or closed).
    • "closed position" - positions that have been closed.
    • "closing position" - any trade closing all or part of a position.
    • "no position" - non-positional trades.
  • :trades - whether or not to include trades related to position in output. (default: false)
  • :start - starting unix timestamp or trade tx id of results. (exclusive)
  • :end - ending unix timestamp or trade tx id of results. (inclusive)

Returns a map with the fields "trades" and "count". The map of trades has the txid as the key and the value is a map with fields:

  • "ordertxid" - order responsible for execution of trade.
  • "pair" - asset pair.
  • "time" - unix timestamp of trade.
  • "type" - type of order (buy/sell).
  • "ordertype" - order type.
  • "price" - average price order was executed at (quote currency).
  • "cost" - total cost of order (quote currency).
  • "fee" - total fee (quote currency).
  • "vol" - volume (base currency).
  • "margin" - initial margin (quote currency).
  • "misc" - comma delimited list of miscellaneous info:
    • "closing" - trade closes all or part of a position.

If the trade opened a position, the follow fields are also present in the trade info:

  • "posstatus" - position status (open/closed).
  • "cprice" - average price of closed portion of position (quote currency).
  • "ccost" - total cost of closed portion of position (quote currency).
  • "cfee" - total fee of closed portion of position (quote currency).
  • "cvol" - total fee of closed portion of position (quote currency).
  • "cmargin" - total margin freed in closed portion of position (quote currency).
  • "net" - net profit/loss of closed portion of position (quote currency, quote currency scale).
  • "trades" - list of closing trades for position (if available).

Note:

  • Unless otherwise stated, costs, fees, prices, and volumes are in the asset pair's scale, not the currency's scale.
  • Times given by trade tx ids are more accurate than unix timestamps.

Example response:

{:ok,
  %{
    "count" => 82,
    "trades" => %{
      "TECAE6-7ZWNZ-WICHNR" => %{
        "cost" => "5.11000",
        "fee" => "0.00818",
        "margin" => "0.00000",
        "misc" => "",
        "ordertxid" => "OAOO5O-RAUU2-BCKZIH",
        "ordertype" => "limit",
        "pair" => "XXBTZEUR",
        "price" => "365.00000",
        "time" => 1457183489.6049,
        "type" => "buy",
        "vol" => "0.01400000"
      }
    }
  }}
Link to this function

withdraw_info(client \\ Krakex.API.private_client(), asset, key, amount, opts \\ [])

View Source

Specs

withdraw_info(Krakex.Client.t(), binary(), binary(), binary(), keyword()) ::
  Krakex.API.response()

Get withdrawal information.

Takes an asset, the withdrawal key name as set up in your account, an amount to withdraw and the following keyword options:

  • :aclass - asset class. "currency" (default)

Returns a map with the following fields:

  • "method" - name of the withdrawal method that will be used.
  • "limit" - maximum net amount that can be withdrawn right now.
  • "fee" - amount of fees that will be paid.

Example response:

{:ok,
  %{
    "amount" => "0.10670000",
    "fee" => "0.00100000",
    "limit" => "0.10770000",
    "method" => "Bitcoin"
  }}