Skip to main content

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

Project description

Welcome to python-kraken-sdk

Generic badge Generic badge PyPI download month GitHub

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 his 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.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

python_kraken_sdk-0.5.4-py2.py3-none-any.whl (26.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: python-kraken-sdk-0.5.4.tar.gz
  • Upload date:
  • Size: 15.8 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.tar.gz
Algorithm Hash digest
SHA256 f6df3c08b45de11108bb2b81cccb59f2fb56de0452a4994aba28c3c56d008661
MD5 77bf3b4f081491c1f81981ba44d6869e
BLAKE2b-256 524d49137db97eb00a603a32e0e5ade69bb66ca831ab43d6476dd269094f2e20

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: python_kraken_sdk-0.5.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 26.7 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-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4cb79e1e06ab7f9582554ac9ace0ce166628beee616d29f779a138d065d3878c
MD5 d9216ef1ab980f638f59572351ecaf28
BLAKE2b-256 b94b766fbac1dc933d70a35993c463e1fba5cfaeb6c6343f5a0e1b5d02d281c9

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