Name | xapi-python JSON |
Version |
0.1.7
JSON |
| download |
home_page | https://github.com/pawelkn/xapi-python |
Summary | The xStation5 API Python library |
upload_time | 2023-10-13 08:54:47 |
maintainer | |
docs_url | None |
author | Paweł Knioła |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2023 Paweł Knioła Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
python
python3
bitcoin
trading
websocket
trading-api
forex
xapi
forex-trading
exchange-api
forex-data
xstation
xstation5
xtb
xopenhub
forex-api
xopenhub-api
xtb-api
xstation-api
x-trade-brokers
bfbcapital
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# xStation5 API Python Library
[![Test xapi-python](https://github.com/pawelkn/xapi-python/actions/workflows/test-xapi-python.yml/badge.svg)](https://github.com/pawelkn/xapi-python/actions/workflows/test-xapi-python.yml) [![PyPi](https://img.shields.io/pypi/v/xapi-python.svg)](https://pypi.python.org/pypi/xapi-python/) [![Downloads](https://img.shields.io/pypi/dm/xapi-python)](https://pypi.python.org/pypi/xapi-python/) [![Codecov](https://codecov.io/gh/pawelkn/xapi-python/branch/master/graph/badge.svg)](https://codecov.io/gh/pawelkn/xapi-python/)
The xStation5 API Python library provides a simple and easy-to-use API for interacting with the xStation5 trading platform. With this library, you can connect to the xStation5 platform, retrieve market data, and execute trades.
This library may be used for [BFB Capital](https://bfb.capital) and [XTB](https://www.xtb.com) xStation5 accounts.
API documentation: <http://developers.xstore.pro/documentation>
## Disclaimer
This xStation5 API Python library is not affiliated with, endorsed by, or in any way officially connected to the xStation5 trading platform or its parent company. The library is provided as-is and is not guaranteed to be suitable for any particular purpose. The use of this library is at your own risk, and the author(s) of this library will not be liable for any damages arising from the use or misuse of this library. Please refer to the license file for more information.
## Installation
You can install xAPI using pip. Simply run the following command:
```shell
pip install xapi-python
```
## Usage
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.
Here is an example of how to use the xAPI library to connect to the xStation5 platform:
```python
import asyncio
import xapi
# Replace these values with your own credentials
CREDENTIALS = {
"accountId": "<your_client_id>",
"password": "<your_password>",
"host": "ws.xtb.com",
"type": "real",
"safe": True
}
async def main():
try:
# Create a new xAPI object and connect to the xStation5 platform
async with await xapi.connect(**CREDENTIALS) as x:
pass
except xapi.LoginFailed as e:
print(f"Log in failed: {e}")
except xapi.ConnectionClosed as e:
print(f"Connection closed: {e}")
if __name__ == "__main__":
asyncio.run(main())
```
Once you have connected to the platform, you can use the xAPI object to retrieve market data and execute trades.
Here is an example of how to subscribe to market data using the xAPI library:
```python
import asyncio
import xapi
# Replace these values with your own credentials
CREDENTIALS = {
"accountId": "<your_client_id>",
"password": "<your_password>",
"host": "ws.xtb.com",
"type": "real",
"safe": True
}
async def main():
while True:
try:
async with await xapi.connect(**CREDENTIALS) as x:
# Subscribe for the current price of BITCOIN and ETHEREUM
await x.stream.getTickPrices("BITCOIN")
await x.stream.getTickPrices("ETHEREUM")
# Listen for coming price ticks
async for message in x.stream.listen():
print(message['data'])
except xapi.LoginFailed as e:
print(f"Log in failed: {e}")
return
except xapi.ConnectionClosed as e:
print(f"Connection closed: {e}, reconnecting ...")
await asyncio.sleep(1)
continue
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
```
And here is an example of how to execute a trade using the xAPI library:
```python
import asyncio
import xapi
from xapi import TradeCmd, TradeType, TradeStatus
# Replace these values with your own credentials
CREDENTIALS = {
"accountId": "<your_client_id>",
"password": "<your_password>",
"host": "ws.xtb.com",
"type": "real",
"safe": False
}
async def main():
try:
async with await xapi.connect(**CREDENTIALS) as x:
# Open a new trade for BITCOIN
response = await x.socket.tradeTransaction(
symbol="BITCOIN",
cmd=TradeCmd.BUY_LIMIT,
type=TradeType.OPEN,
price=10.00,
volume=1
)
if response['status'] == True:
print("Transaction sent to market")
else:
print("Failed to trade a transaction", response)
except xapi.LoginFailed as e:
print(f"Log in failed: {e}")
except xapi.ConnectionClosed as e:
print(f"Connection closed: {e}")
if __name__ == "__main__":
asyncio.run(main())
```
## Examples
To run the examples for the xAPI library, you will need to have an account with the xStation5 trading platform.
Before running the examples, you should create a file called _credentials.json_ in the project directory. This file should contain your account credentials, like this:
### credentials.json
```json
{
"accountId": "<your_client_id>",
"password": "<your_password>",
"host": "ws.xtb.com",
"type": "real",
"safe": false
}
```
Once you have created the _credentials.json_ file, you can run an example using the following command:
```shell
python3 examples/get-margin-level.py
```
## Unit Tests
This will run all of the unit tests in the tests directory:
```shell
git clone https://github.com/pawelkn/xapi-python.git
cd xapi-python
python3 -m unittest discover tests
```
## Buy Me A Coffee! ☕
If you find the project beneficial and would like to support me, please consider showing your appreciation by buying me a coffee on [Buy Me A Coffee](https://buycoffee.to/pawelkn)
Raw data
{
"_id": null,
"home_page": "https://github.com/pawelkn/xapi-python",
"name": "xapi-python",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "python,python3,bitcoin,trading,websocket,trading-api,forex,xapi,forex-trading,exchange-api,forex-data,xstation,xstation5,xtb,xopenhub,forex-api,xopenhub-api,xtb-api,xstation-api,x-trade-brokers,bfbcapital",
"author": "Pawe\u0142 Knio\u0142a",
"author_email": "Pawe\u0142 Knio\u0142a <pawel.kn@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/41/ff/f8a988739e9c16ea67aba834086a71a55cbb04f5296af624ccffcd64e459/xapi-python-0.1.7.tar.gz",
"platform": null,
"description": "# xStation5 API Python Library\n\n[![Test xapi-python](https://github.com/pawelkn/xapi-python/actions/workflows/test-xapi-python.yml/badge.svg)](https://github.com/pawelkn/xapi-python/actions/workflows/test-xapi-python.yml) [![PyPi](https://img.shields.io/pypi/v/xapi-python.svg)](https://pypi.python.org/pypi/xapi-python/) [![Downloads](https://img.shields.io/pypi/dm/xapi-python)](https://pypi.python.org/pypi/xapi-python/) [![Codecov](https://codecov.io/gh/pawelkn/xapi-python/branch/master/graph/badge.svg)](https://codecov.io/gh/pawelkn/xapi-python/)\n\nThe xStation5 API Python library provides a simple and easy-to-use API for interacting with the xStation5 trading platform. With this library, you can connect to the xStation5 platform, retrieve market data, and execute trades.\n\nThis library may be used for [BFB Capital](https://bfb.capital) and [XTB](https://www.xtb.com) xStation5 accounts.\n\nAPI documentation: <http://developers.xstore.pro/documentation>\n\n## Disclaimer\n\nThis xStation5 API Python library is not affiliated with, endorsed by, or in any way officially connected to the xStation5 trading platform or its parent company. The library is provided as-is and is not guaranteed to be suitable for any particular purpose. The use of this library is at your own risk, and the author(s) of this library will not be liable for any damages arising from the use or misuse of this library. Please refer to the license file for more information.\n\n## Installation\n\nYou can install xAPI using pip. Simply run the following command:\n\n```shell\npip install xapi-python\n```\n\n## Usage\n\nTo 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.\n\nHere is an example of how to use the xAPI library to connect to the xStation5 platform:\n\n```python\nimport asyncio\nimport xapi\n\n# Replace these values with your own credentials\nCREDENTIALS = {\n \"accountId\": \"<your_client_id>\",\n \"password\": \"<your_password>\",\n \"host\": \"ws.xtb.com\",\n \"type\": \"real\",\n \"safe\": True\n}\n\nasync def main():\n try:\n # Create a new xAPI object and connect to the xStation5 platform\n async with await xapi.connect(**CREDENTIALS) as x:\n pass\n\n except xapi.LoginFailed as e:\n print(f\"Log in failed: {e}\")\n\n except xapi.ConnectionClosed as e:\n print(f\"Connection closed: {e}\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nOnce you have connected to the platform, you can use the xAPI object to retrieve market data and execute trades.\n\nHere is an example of how to subscribe to market data using the xAPI library:\n\n```python\nimport asyncio\nimport xapi\n\n# Replace these values with your own credentials\nCREDENTIALS = {\n \"accountId\": \"<your_client_id>\",\n \"password\": \"<your_password>\",\n \"host\": \"ws.xtb.com\",\n \"type\": \"real\",\n \"safe\": True\n}\n\nasync def main():\n while True:\n try:\n async with await xapi.connect(**CREDENTIALS) as x:\n # Subscribe for the current price of BITCOIN and ETHEREUM\n await x.stream.getTickPrices(\"BITCOIN\")\n await x.stream.getTickPrices(\"ETHEREUM\")\n\n # Listen for coming price ticks\n async for message in x.stream.listen():\n print(message['data'])\n\n except xapi.LoginFailed as e:\n print(f\"Log in failed: {e}\")\n return\n\n except xapi.ConnectionClosed as e:\n print(f\"Connection closed: {e}, reconnecting ...\")\n await asyncio.sleep(1)\n continue\n\nif __name__ == \"__main__\":\n try:\n asyncio.run(main())\n\n except KeyboardInterrupt:\n pass\n```\n\nAnd here is an example of how to execute a trade using the xAPI library:\n\n```python\nimport asyncio\nimport xapi\nfrom xapi import TradeCmd, TradeType, TradeStatus\n\n# Replace these values with your own credentials\nCREDENTIALS = {\n \"accountId\": \"<your_client_id>\",\n \"password\": \"<your_password>\",\n \"host\": \"ws.xtb.com\",\n \"type\": \"real\",\n \"safe\": False\n}\n\nasync def main():\n try:\n async with await xapi.connect(**CREDENTIALS) as x:\n # Open a new trade for BITCOIN\n response = await x.socket.tradeTransaction(\n symbol=\"BITCOIN\",\n cmd=TradeCmd.BUY_LIMIT,\n type=TradeType.OPEN,\n price=10.00,\n volume=1\n )\n\n if response['status'] == True:\n print(\"Transaction sent to market\")\n else:\n print(\"Failed to trade a transaction\", response)\n\n except xapi.LoginFailed as e:\n print(f\"Log in failed: {e}\")\n\n except xapi.ConnectionClosed as e:\n print(f\"Connection closed: {e}\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n## Examples\n\nTo run the examples for the xAPI library, you will need to have an account with the xStation5 trading platform.\n\nBefore running the examples, you should create a file called _credentials.json_ in the project directory. This file should contain your account credentials, like this:\n\n### credentials.json\n\n```json\n{\n \"accountId\": \"<your_client_id>\",\n \"password\": \"<your_password>\",\n \"host\": \"ws.xtb.com\",\n \"type\": \"real\",\n \"safe\": false\n}\n```\n\nOnce you have created the _credentials.json_ file, you can run an example using the following command:\n\n```shell\npython3 examples/get-margin-level.py\n```\n\n## Unit Tests\n\nThis will run all of the unit tests in the tests directory:\n\n```shell\ngit clone https://github.com/pawelkn/xapi-python.git\ncd xapi-python\npython3 -m unittest discover tests\n```\n\n## Buy Me A Coffee! \u2615\n\nIf you find the project beneficial and would like to support me, please consider showing your appreciation by buying me a coffee on [Buy Me A Coffee](https://buycoffee.to/pawelkn)\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 Pawe\u0142 Knio\u0142a Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "The xStation5 API Python library",
"version": "0.1.7",
"project_urls": {
"Bug Tracker": "https://github.com/pawelkn/xapi-python/issues",
"Homepage": "https://github.com/pawelkn/xapi-python"
},
"split_keywords": [
"python",
"python3",
"bitcoin",
"trading",
"websocket",
"trading-api",
"forex",
"xapi",
"forex-trading",
"exchange-api",
"forex-data",
"xstation",
"xstation5",
"xtb",
"xopenhub",
"forex-api",
"xopenhub-api",
"xtb-api",
"xstation-api",
"x-trade-brokers",
"bfbcapital"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "41fff8a988739e9c16ea67aba834086a71a55cbb04f5296af624ccffcd64e459",
"md5": "a3eca2d635c8316889ceb2bbde10a466",
"sha256": "077dfb452e255ffbb16c3ba162cef0d3f7b3f0e3844eeec1b44d6d50244864aa"
},
"downloads": -1,
"filename": "xapi-python-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "a3eca2d635c8316889ceb2bbde10a466",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13021,
"upload_time": "2023-10-13T08:54:47",
"upload_time_iso_8601": "2023-10-13T08:54:47.390629Z",
"url": "https://files.pythonhosted.org/packages/41/ff/f8a988739e9c16ea67aba834086a71a55cbb04f5296af624ccffcd64e459/xapi-python-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-13 08:54:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pawelkn",
"github_project": "xapi-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "xapi-python"
}