Skip to content

Commit d96e857

Browse files
committed
XAPI: Add command line interface (CLI)
1 parent 3ab783d commit d96e857

File tree

7 files changed

+626
-46
lines changed

7 files changed

+626
-46
lines changed

README.md

+7-35
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,7 @@ pip install xapi-python
2424

2525
To use xAPI, you will need to have an active account with the xStation5 trading platform. Once you have an account, you can use the xAPI library to connect to the platform and begin trading.
2626

27-
Here is an example of how to use the xAPI library to connect to the xStation5 platform:
28-
29-
```python
30-
import asyncio
31-
import xapi
32-
33-
# Replace these values with your own credentials
34-
CREDENTIALS = {
35-
"accountId": "<your_client_id>",
36-
"password": "<your_password>",
37-
"host": "ws.xtb.com",
38-
"type": "real",
39-
"safe": True
40-
}
41-
42-
async def main():
43-
try:
44-
# Create a new xAPI object and connect to the xStation5 platform
45-
async with await xapi.connect(**CREDENTIALS) as x:
46-
pass
47-
48-
except xapi.LoginFailed as e:
49-
print(f"Log in failed: {e}")
50-
51-
except xapi.ConnectionClosed as e:
52-
print(f"Connection closed: {e}")
53-
54-
if __name__ == "__main__":
55-
asyncio.run(main())
56-
```
57-
58-
Once you have connected to the platform, you can use the xAPI object to retrieve market data and execute trades.
59-
60-
Here is an example of how to subscribe to market data using the xAPI library:
27+
Here is an example of how to use the xAPI library to connect to the xStation5 platform and subscribe to market data:
6128

6229
```python
6330
import asyncio
@@ -106,7 +73,6 @@ And here is an example of how to execute a trade using the xAPI library:
10673
```python
10774
import asyncio
10875
import xapi
109-
from xapi import TradeCmd, TradeType, TradeStatus
11076

11177
# Replace these values with your own credentials
11278
CREDENTIALS = {
@@ -144,6 +110,12 @@ if __name__ == "__main__":
144110
asyncio.run(main())
145111
```
146112

113+
## Command Line Interface (CLI)
114+
115+
The xAPI library provides a command line interface (CLI) for interacting with the xStation5 API. You can run the xAPI commands without leaving the terminal. Just use the `xapi` command.
116+
117+
![xAPI in action](assets/cli-example.gif)
118+
147119
## Examples
148120

149121
To run the examples for the xAPI library, you will need to have an account with the xStation5 trading platform.

assets/cli-example.gif

154 KB
Loading

pyproject.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[project]
22
name = "xapi-python"
3-
version = "0.1.7"
3+
version = "0.2.0"
44
authors = [
5-
{ name="Paweł Knioła", email="pawel[email protected]" },
5+
{ name="Paweł Knioła", email="pawel@kniola.pl" },
66
]
77
description = "The xStation5 API Python library"
88
keywords = [
@@ -21,12 +21,17 @@ classifiers = [
2121
"Programming Language :: Python :: 3.9",
2222
"Programming Language :: Python :: 3.10",
2323
"Programming Language :: Python :: 3.11",
24-
"Programming Language :: Python :: 3.12"
24+
"Programming Language :: Python :: 3.12",
25+
"Programming Language :: Python :: 3.13",
2526
]
2627
dependencies = [
27-
"websockets>=11.0.2"
28+
"websockets>=11.0.2",
29+
"click>=8.1.8"
2830
]
2931

3032
[project.urls]
3133
"Homepage" = "https://github.com/pawelkn/xapi-python"
32-
"Bug Tracker" = "https://github.com/pawelkn/xapi-python/issues"
34+
"Bug Tracker" = "https://github.com/pawelkn/xapi-python/issues"
35+
36+
[project.scripts]
37+
xapi = "xapi.cli:cli"

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
websockets>=11.0.2
1+
websockets>=11.0.2
2+
click>=8.1.8

setup.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='xapi-python',
55
author='Paweł Knioła',
6-
author_email='pawel[email protected]',
6+
author_email='pawel@kniola.pl',
77
description='The xStation5 API Python library',
88
long_description=open('README.md', encoding='utf-8').read(),
99
license='MIT',
@@ -17,9 +17,10 @@
1717
"Programming Language :: Python :: 3.9",
1818
"Programming Language :: Python :: 3.10",
1919
"Programming Language :: Python :: 3.11",
20-
"Programming Language :: Python :: 3.12"
20+
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
2122
],
2223
python_requires='>=3.7',
23-
version="0.1.7",
24+
version="0.2.0",
2425
packages=['xapi'],
2526
)

xapi/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
.. moduleauthor:: Paweł Knioła <pawel[email protected]>
2+
.. moduleauthor:: Paweł Knioła <pawel@kniola.pl>
33
"""
44

55
name = "xapi"
6-
__version__ = "0.1.7"
6+
__version__ = "0.2.0"
77

88
from .xapi import XAPI, connect
99
from .enums import TradeCmd, TradeType, TradeStatus, PeriodCode

0 commit comments

Comments
 (0)