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

Uploaded Source

Built Distribution

python_kraken_sdk-0.5.1-py2.py3-none-any.whl (24.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: python-kraken-sdk-0.5.1.tar.gz
  • Upload date:
  • Size: 14.6 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.1.tar.gz
Algorithm Hash digest
SHA256 507fb7977e23e17a9b2310cd63aa154b421d2336dcd544c5926eb1672efacd27
MD5 dad565d602eae6405e7fac0104e15186
BLAKE2b-256 546ea7ce661204f7f76c084abffb157c18c138001f8ae4f8b62e8e3364bdd2d7

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: python_kraken_sdk-0.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.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.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b8c71e12d4a78070d0e616dcf04720d5aa4ee519ca38331c034b4326f0af432
MD5 68ecc9a68c6039920bfe29dcc77a2e2d
BLAKE2b-256 763b86bf2c2c781f358144ad57648dbbf4a711716b3e85123d5fc359e3d75f38

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