Skip to content

Commit 118cd0a

Browse files
Resolve "Add command-line interface" (#224)
1 parent e4a51fe commit 118cd0a

13 files changed

Lines changed: 512 additions & 26 deletions

File tree

.github/workflows/dependabot_auto_approve.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
with:
2727
github-token: "${{ secrets.GITHUB_TOKEN }}"
2828
- name: Approve a PR
29+
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
2930
run: gh pr review --approve "$PR_URL"
3031
env:
3132
PR_URL: ${{ github.event.pull_request.html_url }}

README.md

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,25 @@ regarding the use of this software.
4545

4646
## Features
4747

48-
Available Clients:
49-
50-
- NFT REST Clients
51-
- Spot REST Clients
52-
- Spot Websocket Clients (Websocket API v1 and v2)
53-
- Spot Orderbook Clients (Websocket API v1 and v2)
54-
- Futures REST Clients
55-
- Futures Websocket Client
56-
5748
General:
5849

50+
- command-line interface
5951
- access both public and private, REST and websocket endpoints
6052
- responsive error handling and custom exceptions
6153
- extensive example scripts (see `/examples` and `/tests`)
6254
- tested using the [pytest](https://docs.pytest.org/en/7.3.x/) framework
6355
- releases are permanently archived at [Zenodo](https://zenodo.org/badge/latestdoi/510751854)
6456
- releases before v2.0.0 also support Python 3.7+
6557

58+
Available Clients:
59+
60+
- NFT REST Clients
61+
- Spot REST Clients
62+
- Spot Websocket Clients (Websocket API v1 and v2)
63+
- Spot Orderbook Clients (Websocket API v1 and v2)
64+
- Futures REST Clients
65+
- Futures Websocket Client
66+
6667
Documentation:
6768

6869
- [https://python-kraken-sdk.readthedocs.io/en/stable](https://python-kraken-sdk.readthedocs.io/en/stable)
@@ -84,6 +85,8 @@ new releases.
8485
## Table of Contents
8586

8687
- [ Installation and setup ](#installation)
88+
- [ Command-line interface ](#cliusage)
89+
- [ SDK Usage Hints ](#sdkusage)
8790
- [ Spot Clients ](#spotusage)
8891
- [REST API](#spotrest)
8992
- [Websocket API V2](#spotws)
@@ -96,8 +99,6 @@ new releases.
9699
- [ Notes ](#notes)
97100
- [ References ](#references)
98101

99-
---
100-
101102
<a name="installation"></a>
102103

103104
# 🛠 Installation and setup
@@ -123,7 +124,59 @@ API permissions</b>, <b style="color: yellow">rate limits</b>, update the
123124
python-kraken-sdk, see the [Troubleshooting](#trouble) section, and if the error
124125
persists please open an issue.
125126

126-
---
127+
<a name="cliusage"></a>
128+
129+
# 📍 Command-line interface
130+
131+
The python-kraken-sdk provides a command-line interface to access the Kraken API
132+
using basic instructions while performing authentication tasks in the
133+
background. The Spot, NFT and Futures API are accessible and follow the pattern
134+
`kraken {spot,futures} [OPTIONS] URL`. See examples below.
135+
136+
```bash
137+
# get server time
138+
kraken spot https://api.kraken.com/0/public/Time
139+
{'unixtime': 1716707589, 'rfc1123': 'Sun, 26 May 24 07:13:09 +0000'}
140+
141+
# get user's balances
142+
kraken spot --api-key=<api-key> --secret-key=<secret-key> -X POST https://api.kraken.com/0/private/Balance
143+
{'ATOM': '17.28229999', 'BCH': '0.0000077100', 'ZUSD': '1000.0000'}
144+
145+
# get user's trade balances
146+
kraken spot --api-key=<api-key> --secret-key=<secret-key> -X POST https://api.kraken.com/0/private/TradeBalance --data '{"asset": "DOT"}'
147+
{'eb': '2.8987347115', 'tb': '1.1694303513', 'm': '0.0000000000', 'uv': '0', 'n': '0.0000000000', 'c': '0.0000000000', 'v': '0.0000000000', 'e': '1.1694303513', 'mf': '1.1694303513'}
148+
149+
# get 1D candles for a futures instrument
150+
kraken futures https://futures.kraken.com/api/charts/v1/spot/PI_XBTUSD/1d
151+
{'candles': [{'time': 1625616000000, 'open': '34557.84000000000', 'high': '34803.20000000000', 'low': '33816.32000000000', 'close': '33880.22000000000', 'volume': '0' ...
152+
153+
# get user's open futures positions
154+
kraken futures --api-key=<api-key> --secret-key=<secret-key> https://futures.kraken.com/derivatives/api/v3/openpositions
155+
{'result': 'success', 'openPositions': [], 'serverTime': '2024-05-26T07:15:38.91Z'}
156+
```
157+
158+
... All endpoints of the Kraken Spot and Futurs API can be accessed like that.
159+
160+
<a name="sdkusage"></a>
161+
162+
# 📍 SDK Usage Hints
163+
164+
The python-kraken-sdk provides lots of functions to easily access most of the
165+
REST and websocket endpoints of the Kraken Cryptocurrency Exchange API. Since
166+
these endpoints and their parameters may change, all implemented endpoints are
167+
tested on a regular basis.
168+
169+
If certain parameters or settings are not available, or
170+
specific endpoints are hidden and not implemented, it is always possible to
171+
execute requests to the endpoints directly using the `_request` method provided
172+
by any client. This is demonstrated below.
173+
174+
```python
175+
from kraken.spot import User
176+
177+
user = User(key="<your-api-key>", secret="<your-secret-key>")
178+
print(user._request(method="POST", uri="/0/private/Balance"))
179+
```
127180
128181
<a name="spotusage"></a>
129182
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. -*- coding: utf-8 -*-
2+
.. Copyright (C) 2024 Benjamin Thomas Schwertfeger
3+
.. GitHub: https://github.com/btschwertfeger
4+
5+
.. _section-command-line-interface-examples:
6+
7+
Command-line Interface
8+
======================
9+
10+
The python-kraken-sdk provides a command-line interface to access the Kraken API
11+
using basic instructions while performing authentication tasks in the
12+
background. The Spot, NFT and Futures API are accessible and follow the pattern
13+
``kraken {spot,futures} [OPTIONS] URL``. All endpoints of the Kraken Spot and
14+
Futurs API can be accessed like that. See examples below.
15+
16+
.. code-block:: bash
17+
:linenos:
18+
:caption: Command-line Interface Examples
19+
20+
# get server time
21+
kraken spot https://api.kraken.com/0/public/Time
22+
{'unixtime': 1716707589, 'rfc1123': 'Sun, 26 May 24 07:13:09 +0000'}
23+
24+
# get user's balances
25+
kraken spot --api-key=<api-key> --secret-key=<secret-key> -X POST https://api.kraken.com/0/private/Balance
26+
{'ATOM': '17.28229999', 'BCH': '0.0000077100', 'ZUSD': '1000.0000'}
27+
28+
# get user's trade balances
29+
kraken spot --api-key=<api-key> --secret-key=<secret-key> -X POST https://api.kraken.com/0/private/TradeBalance --data '{"asset": "DOT"}'
30+
{'eb': '2.8987347115', 'tb': '1.1694303513', 'm': '0.0000000000', 'uv': '0', 'n': '0.0000000000', 'c': '0.0000000000', 'v': '0.0000000000', 'e': '1.1694303513', 'mf': '1.1694303513'}
31+
32+
# get 1D candles for a futures instrument
33+
kraken futures https://futures.kraken.com/api/charts/v1/spot/PI_XBTUSD/1d
34+
{'candles': [{'time': 1625616000000, 'open': '34557.84000000000', 'high': '34803.20000000000', 'low': '33816.32000000000', 'close': '33880.22000000000', 'volume': '0' ...
35+
36+
# get user's open futures positions
37+
kraken futures --api-key=<api-key> --secret-key=<secret-key> https://futures.kraken.com/derivatives/api/v3/openpositions
38+
{'result': 'success', 'openPositions': [], 'serverTime': '2024-05-26T07:15:38.91Z'}

doc/examples/rest_example_usage.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
Usage Examples
88
==============
99

10+
The python-kraken-sdk provides lots of functions to easily access most of the
11+
REST and websocket endpoints of the Kraken Cryptocurrency Exchange API. Since
12+
these endpoints and their parameters may change, all implemented endpoints are
13+
tested on a regular basis.
14+
15+
If certain parameters or settings are not available, or specific endpoints are
16+
hidden and not implemented, it is always possible to execute requests to the
17+
endpoints directly using the ``_request`` method provided by all clients. This
18+
is demonstrated below.
19+
20+
.. code-block:: python
21+
:linenos:
22+
:caption: Usage of the basic _request method
23+
24+
from kraken.spot import User
25+
26+
user = User(key="<your-api-key>", secret="<your-secret-key>")
27+
print(user._request(method="POST", uri="/0/private/Balance"))
28+
1029
The repository of the `python-kraken-sdk`_ provides some example scripts that
1130
demonstrate some of the implemented methods. Please see the sections listed
1231
below.

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Welcome to python-kraken-sdk's documentation!
2222

2323
introduction.rst
2424
getting_started/getting_started.rst
25+
examples/command_line_interface.rst
2526
examples/rest_example_usage.rst
2627
examples/trading_bot_templates.rst
2728
spot/rest.rst

doc/introduction.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ regarding the use of this software.
5656
Features
5757
--------
5858

59-
Available Clients:
60-
61-
- NFT REST Clients
62-
- Spot REST Clients
63-
- Spot Websocket Clients (Websocket API v1 and v2)
64-
- Spot Orderbook Clients (Websocket API v1 and v2)
65-
- Futures REST Clients
66-
- Futures Websocket Client
67-
6859
General:
6960

61+
- command-line interface
7062
- access both public and private, REST and websocket endpoints
7163
- responsive error handling and custom exceptions
7264
- extensive examples
7365
- tested using the `pytest <https://docs.pytest.org/en/7.3.x/>`_ framework
7466
- releases are permanently archived at `Zenodo <https://zenodo.org/badge/latestdoi/510751854>`_
7567
- releases before v2.0.0 also support Python 3.7+
7668

69+
Available Clients:
70+
71+
- NFT REST Clients
72+
- Spot REST Clients
73+
- Spot Websocket Clients (Websocket API v1 and v2)
74+
- Spot Orderbook Clients (Websocket API v1 and v2)
75+
- Futures REST Clients
76+
- Futures Websocket Client
7777

7878
Important Notice
7979
-----------------

kraken/base_api/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ def __init__(
212212

213213
self.__err_handler: KrakenErrorHandler = KrakenErrorHandler()
214214
self.__session: requests.Session = requests.Session()
215-
self.__session.headers.update({"User-Agent": "python-kraken-sdk"})
215+
self.__session.headers.update(
216+
{
217+
"User-Agent": "python-kraken-sdk"
218+
" (https://github.com/btschwertfeger/python-kraken-sdk)",
219+
},
220+
)
216221

217222
def _request( # noqa: PLR0913 # pylint: disable=too-many-arguments
218223
self: KrakenSpotBaseAPI,
@@ -483,7 +488,12 @@ def __init__(
483488

484489
self.__err_handler: KrakenErrorHandler = KrakenErrorHandler()
485490
self.__session: requests.Session = requests.Session()
486-
self.__session.headers.update({"User-Agent": "python-kraken-sdk"})
491+
self.__session.headers.update(
492+
{
493+
"User-Agent": "python-kraken-sdk"
494+
" (https://github.com/btschwertfeger/python-kraken-sdk)",
495+
},
496+
)
487497

488498
def _request( # noqa: PLR0913 # pylint: disable=too-many-arguments
489499
self: KrakenFuturesBaseAPI,

0 commit comments

Comments
 (0)