Skip to main content

Python asyncio client for Kraken API REST and Kraken Websockets API using httpx and websockets

Project description

Kraky

Python asyncio client for Kraken API REST and Kraken Websockets API using httpx and websockets

Installation

pip install kraky

Usage

REST

from kraky import KrakyApiClient

async def get_ws_token():
    kraken_api_key = ""
    kraken_secret = ""
    kraky_api_client = KrakyApiClient(
        api_key=kraken_api_key, secret=kraken_secret
    )

    ws_token = await self.kraky_api_client.get_web_sockets_token()
    return ws_token

Websocket

from kraky import KrakyApiClient, KrakyWsClient

async def get_ws_token():
    kraken_api_key = ""
    kraken_secret = ""
    kraky_api_client = KrakyApiClient(
        api_key=kraken_api_key, secret=kraken_secret
    )

    ws_token = await self.kraky_api_client.get_web_sockets_token()
    return ws_token

async def public_handler(self, response):
    print(response)

async def private_handler(self, response):
    print(response)

async def main():

    interval = 30

    ws_pairs = ["XBT/USD", "ETH/USD]

    ws_token = get_token()

    kraky_public_ws_client = KrakyWsClient("production")
    kraky_private_ws_client = KrakyWsClient("production-auth")

    asyncio.create_task(
        kraky_public_ws_client.connect(
            public_handler, connection_name="public"
        )
    )

    asyncio.create_task(
        kraky_private_ws_client.connect(
            private_handler, connection_name="private"
        )
    )

    await kraky_public_ws_client.subscribe(
        {"name": "ohlc", "interval": interval},
        ws_pairs,
        connection_name="public",
    )

    await kraky_private_ws_client.subscribe(
        {
            "interval": interval,
            "token": ws_token,
            "name": "openOrders",
        },
        connection_name="private",
    )

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.create_task(main())
    loop.run_forever()

Compatibility

  • Python 3.7 and above

Licence

MIT License

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

kraky-0.4.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

kraky-0.4.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file kraky-0.4.1.tar.gz.

File metadata

  • Download URL: kraky-0.4.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for kraky-0.4.1.tar.gz
Algorithm Hash digest
SHA256 042cd2d1ee6edf7de1810a6b0c68220340c77d7123caf331649297b6dadc8335
MD5 58d71cfe66e2d70281fda795cb6d1285
BLAKE2b-256 929d488f07bec6e9a27f4b7cdc70d6fdada9e4cf40e278272d68c0fa5cc344b9

See more details on using hashes here.

File details

Details for the file kraky-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: kraky-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for kraky-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb67be0610005b8283d4c264678060a8ed1b13f53cd1980322b08b9f34238ef2
MD5 4a9164598d6c49cb522456e9329b6cc9
BLAKE2b-256 ad2865cffbdb665316557c8a0eb1a66de814fd0687a7098b581d53f37b62fce4

See more details on using hashes here.

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