krakenapi package

Submodules

krakenapi.kraken_api module

class krakenapi.kraken_api.KrakenApi(api_public_key: str = '', api_private_key: str = '')

Bases: object

Encapsulation of Kraken api through python object. Easily requests Kraken’s api endpoints.

api_private_key: str
api_public_key: str
static create_api_nonce() str

Create a unique number identifier as string used for each private REST API endpoints. :return: A unique number identifier as string

static create_api_path(public_method: bool, api_method: str) str

Given a method, return the api url to request.

Parameters:
  • public_method – Is the method a public market data.

  • api_method – Api method as string.

Returns:

Api url to request.

static create_api_post_data(post_inputs: dict = None, api_nonce: str = '') bytes

Create api post data for private user methods.

Parameters:
  • api_nonce – Unique API call identifier as string.

  • post_inputs – POST inputs as dict.

Returns:

API post data.

create_api_request(public_method: bool, api_method: str, post_inputs: dict = None) Request

Given a method, create a request object to send to Kraken API.

Parameters:
  • public_method – Is the method a public market data.

  • api_method – API method as string.

  • post_inputs – POST inputs as dict.

Returns:

Request object.

create_api_signature(api_nonce: str, api_post_data: bytes, api_method: str) str

Create api signature for private user methods.

Parameters:
  • api_nonce – Unique API call identifier as string.

  • api_post_data – Bytes encoded API POST data.

  • api_method – API method to call.

Returns:

API signature to use as HTTP header.

create_order(pair: str, type: str, order_type: str, price: float, volume: float, o_flags: str) dict

Create an order on kraken with passed arguments. More information on Kraken documentation (Add standard order): https://www.kraken.com/en-us/features/api

Parameters:
  • pair – Order pair.

  • type – Buy or sell order.

  • order_type – Order type.

  • price – Price to buy the pair.

  • volume – Order volume.

  • o_flags – Order additional flags.

Returns:

Pair ticker information as dict.

static extract_response_data(data: bytes) dict

Extract data from Kraken API request response.

Returns:

Request response data as dict

get_asset_altname(asset: str) str

From passed asset name, get its alt name on Kraken API.

Parameters:

asset – Asset as string.

Returns:

Asset alt name as string.

get_asset_pairs() dict

Get tradable asset pairs

Returns:

Dict of available asset pairs and their information.

get_assets() dict

Get information about the assets that are available for deposit, withdrawal, trading and staking.

Returns:

Dict of available asset pairs and their information.

get_balance() dict

Return current Kraken account balance.

Returns:

Dict of asset names and balance amount.

get_closed_orders(post_inputs: dict = None) dict

Return current Kraken closed orders.

Parameters:

post_inputs – POST inputs as dict.

Returns:

Dict of closed orders with txid as the key.

get_open_orders() dict

Return current Kraken open orders.

Returns:

Dict of open orders txid as the key.

get_pair_ticker(pair: str) dict

Return pair ticker information.

Parameters:

pair – Pair to get ticker information.

Returns:

Pair ticker information as dict.

get_time() int

Return current Kraken time as string.

Returns:

Kraken time as string.

get_trade_balance() dict

Return current Kraken account trade balance.

Returns:

Dict of asset names and balance amount.

get_trades_history(pair: str, start_unix_time: int, end_unix_time: int) list

Return trade history for specified pair from Kraken API as nested list. More information on Kraken documentation (Get trades history): https://www.kraken.com/en-us/features/api

Parameters:
  • pair – Order pair.

  • start_unix_time – Start date as unix time in seconds or nanoseconds.

  • end_unix_time – End date as unix time in seconds or nanoseconds.

Returns:

Trade history as list of list.

send_api_request(request: Request) dict

Given a method, request the Kraken api and return the response data.

Parameters:

request – Request object to send to Kraken API

Returns:

Kraken API’s response as dict.

krakenapi.utils module

krakenapi.utils.utc_unix_time_datetime(nix_time: int) datetime

Takes utc nix time in seconds or nanoseconds and returns date as Datetime.

Parameters:

nix_time – Nix time to convert to string date.

Returns:

Converted date as string.

Module contents