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
Docs
[Krkay docs](https://kraky.readthedocs.io/en/latest/ "Docs")
Usage
REST
from kraky import KrakyApiClient
async def get_web_sockets_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
Release history Release notifications | RSS feed
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.9.0.tar.gz
(7.8 kB
view details)
Built Distribution
kraky-0.9.0-py3-none-any.whl
(8.7 kB
view details)
File details
Details for the file kraky-0.9.0.tar.gz
.
File metadata
- Download URL: kraky-0.9.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15e0d9c984cf58167e3d8edac773bed1ecf4deae575276da7e67327996f4ff52 |
|
MD5 | 1fb3481703268efb968ce8c675bc4962 |
|
BLAKE2b-256 | 0f76c46d32f1ac6bd39fd7e3b4a44460411f80ae859860cad81a1d708125ede2 |
File details
Details for the file kraky-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: kraky-0.9.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f8bb7d8e805deda69ae6946a1e8621dcaa3f4bfdce50e3f4f5efa813d4ca48 |
|
MD5 | 6e8576d4497271d4d20a9ebfa50bb2f5 |
|
BLAKE2b-256 | c7070dce1a7dff6e3c0e75ff379672a9ae28e38e511302a571236fe23fb0d214 |