Python client for Kraken API REST and Kraken Websockets API using httpx and websockets. Supports both sync and async for API REST.
Project description
Kraky
Python client for Kraken API REST and Kraken Websockets API using httpx and websockets. Supports both sync and async for API REST.
Disclaimer
This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.
Always start by running a trading bot in Dry-run and do not engage money before you understand how it works and what profit/loss you should expect.
We strongly recommend you to have coding and Python knowledge. Do not hesitate to read the source code and understand the mechanism of this library.
Installation
pip install kraky
Docs
https://kraky.readthedocs.io/en/latest/
Usage
CLI
Kraky provides a CLI that matches the API function names and args.
You can use it like the following:
kraky get_ohlc_data pair=XBTUSD interval=240
You can replace get_ohlc_data by any kraky API function and pair=XBTUSD or interval=240 by any function argument. Please respect the format key=value.
It also supports .env files so you can also create a .env file with your api_key and secret and kraky will pick them up.
Example:
KRAKEN_API_KEY=""
KRAKEN_SECRET=""
Sync REST API
from kraky import KrakyApiClient
def get_web_sockets_token():
kraken_api_key = ""
kraken_secret = ""
kraky_api_client = KrakyApiClient(
api_key=kraken_api_key, secret=kraken_secret
)
ws_token = kraky_api_client.get_web_sockets_token()
return ws_token
get_web_sockets_token()
Async REST API
from kraky import KrakyApiAsyncClient
async def get_web_sockets_token():
kraken_api_key = ""
kraken_secret = ""
kraky_api_client = KrakyApiAsyncClient(
api_key=kraken_api_key, secret=kraken_secret
)
ws_token = await kraky_api_client.get_web_sockets_token()
return ws_token
asyncio.run(get_web_sockets_token)
Websocket
import asyncio
from kraky import KrakyApiAsyncClient, KrakyWsClient
async def get_web_sockets_token():
kraken_api_key = ""
kraken_secret = ""
kraky_api_client = KrakyApiAsyncClient(
api_key=kraken_api_key, secret=kraken_secret
)
ws_token = await kraky_api_client.get_web_sockets_token()
return ws_token
async def public_handler(response):
print(response)
async def private_handler(response):
print(response)
async def main():
interval = 30
ws_pairs = ["XBT/USD", "ETH/USD"]
ws_token = await get_web_sockets_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
Built Distribution
File details
Details for the file kraky-2022.11.28.tar.gz
.
File metadata
- Download URL: kraky-2022.11.28.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44085f3331eb7d7299582530ef5b464a60d8e25c5ece508afab6a285f935ee61 |
|
MD5 | be57a8f6f392923d762948247a49d454 |
|
BLAKE2b-256 | 034c7a7470e63c0183687fdb079ce1dd6b561723a8be88397b275cca3e1a37be |
File details
Details for the file kraky-2022.11.28-py3-none-any.whl
.
File metadata
- Download URL: kraky-2022.11.28-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b84d80edb3708ae8b56fb5d92720d198cb5a08c47841612f1b3fa0aafa09074e |
|
MD5 | 45b74b9153b113eec3d75920e3c86774 |
|
BLAKE2b-256 | 2445e401fa8cf6772f020db8d4d9f9ff9908153394550b989d975b6b8c35449a |