Atem18/kraky
Fork: 9 Star: 26 (更新于 2024-11-01 16:32:08)
license: MIT
Language: Python .
Python asyncio client for Kraken API REST and Kraken Websockets API using httpx and websockets
最后发布版本: 2023.08.17 ( 2023-08-17 20:00:05)
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.8 and above
Licence
MIT License
最近版本更新:(数据更新于 2024-09-22 16:29:52)
2023-08-17 20:00:05 2023.08.17
2023-08-17 03:20:57 2023.08.16
2023-06-13 18:33:59 2023.06.13
2023-02-22 08:59:19 2023.02.22
2023-01-12 00:59:29 2023.01.11
2022-11-29 00:52:59 2022.11.28
2022-06-16 03:58:25 2022.06.15
2022-05-25 21:46:25 2022.05.25
2022-03-30 03:51:09 2022.03.29
2022-03-27 05:43:57 2022.03.26
主题(topics):
asyncio, httpx, kraken, websockets
Atem18/kraky同语言 Python最近更新仓库
2024-11-05 16:16:26 Guovin/TV
2024-11-05 15:03:24 Cinnamon/kotaemon
2024-11-05 11:00:51 home-assistant/core
2024-11-04 23:11:11 DS4SD/docling
2024-11-04 10:56:18 open-compass/opencompass
2024-11-04 08:51:21 yt-dlp/yt-dlp