Skip to main content

Collection of clients and methods to interact with the cryptocurrency exchange Kraken.

Project description

Welcome to python-kraken-sdk

GitHub License: GPL v3 Generic badge Downloads PyPI download month

This is an unofficial Python collection of REST and websocket clients to interact with the Kraken exchange API.

There is no guarantee that this software will work flawlessly at this or later times. Everyone has to look at the underlying source code themselves and consider whether this is appropriate for their own use.

Of course, no responsibility is taken for possible profits or losses. No one should be motivated or tempted to invest assets in speculative forms of investment.

Installation

python3 -m pip install python-kraken-sdk

Usage

REST

... can be found in /examples/examples.py

from kraken.spot.client import User, Market, Trade, Funding, Staking

def main() -> None:
    key = 'kraken pub key'
    secret = 'kraken secret key'

    user = User(key=key, secret=secret)
    print(user.get_account_balance())
    print(user.get_open_orders())

    market = Market(key=key, secret=secret)
    print(market.get_ticker(pair='BTCUSD'))

    trade = Trade(key=key, secret=secret)
    print(trade.create_order(
         ordertype='limit',
         side='buy',
         volume=1,
         pair='BTC/EUR',
         price=20000
    ))

    funding = Funding(key=key, secret=secret)
    print(funding.withdraw_funds(asset='DOT', key='MyPolkadotWallet', amount=200))
    print(funding.cancel_widthdraw(asset='DOT', refid='<some id>'))

    staking = Staking(key=key, secret=secret)
    print(staking.list_stakeable_assets())
    print(staking.stake_asset(asset='DOT', amount=20, method='polkadot-staked'))

if __name__ == '__main__':
    main()

Websockets

... can be found in /examples/ws_examples.py

import asyncio
from kraken.spot.client import WsClient
from kraken.spot.websocket.websocket import KrakenSpotWSClient

async def main() -> None:

    key = 'kraken public key'
    secret = 'kraken secret key'

    class Bot(KrakenSpotWSClient):

        async def on_message(self, msg) -> None:
            if 'event' in msg:
                if msg['event'] in ['pong', 'heartbeat']: return

            print(msg)
            # await self._client.create_order(
            #     ordertype='limit',
            #     side='buy',
            #     pair='BTC/EUR',
            #     price=20000,
            #     volume=1
            # )
            # ... it is also possible to call regular REST endpoints
            # but using the websocket messages is more efficient

    bot = Bot(WsClient(key=key, secret=secret))
    await bot.subscribe(pair=['BTC/EUR'], subscription={ 'name': 'ticker' }, private=False)
    await bot.subscribe(subscription={ 'name': 'ownTrades' }, private=True)

    while True: await asyncio.sleep(6)

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

What else?

Logging

Logging messages are enabled, so you can configure your own logger to track every event. One example can be found in /examples/examples.py.

References

Notes:

  • Pull requests will be ignored until the owner finished the core idea

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-kraken-sdk-0.5.4.2.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

python_kraken_sdk-0.5.4.2-py2.py3-none-any.whl (37.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-kraken-sdk-0.5.4.2.tar.gz.

File metadata

  • Download URL: python-kraken-sdk-0.5.4.2.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for python-kraken-sdk-0.5.4.2.tar.gz
Algorithm Hash digest
SHA256 d1b44d5465fedef35e5ecd96ca2c7244b9cb8951772b16973a3b20cf0569dfde
MD5 e6cc98d9d196dca84085eb5e636c367a
BLAKE2b-256 cac309b533b042ed01ead2e06c8ef0f1b9f46f7b1f9f494cacefb39693b955ab

See more details on using hashes here.

Provenance

File details

Details for the file python_kraken_sdk-0.5.4.2-py2.py3-none-any.whl.

File metadata

  • Download URL: python_kraken_sdk-0.5.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for python_kraken_sdk-0.5.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 107e1114000e44f9a1a887fd9787a230abc0aa748c1a692ff9bf8fb13a0f6db7
MD5 c3f3add3f40ca32376f8c440471ed9d9
BLAKE2b-256 ae8bf67726a7566802d1391dab35cdd5c1186505b2c12d957ceab02fdede615f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page