{"id":21969364,"url":"https://github.com/pawelkn/xapi-python","last_synced_at":"2025-09-14T19:08:01.301Z","repository":{"id":154767105,"uuid":"632278337","full_name":"pawelkn/xapi-python","owner":"pawelkn","description":"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.","archived":false,"fork":false,"pushed_at":"2025-01-11T15:04:30.000Z","size":204,"stargazers_count":45,"open_issues_count":2,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-08-23T12:38:35.575Z","etag":null,"topics":["bitcoin","exchange-api","forex","forex-data","forex-trading","python","python3","trading","trading-api","websocket","x-trade-brokers","xapi","xopenhub-api","xstation","xstation-api","xstation5","xtb","xtb-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pawelkn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-25T04:48:40.000Z","updated_at":"2025-07-31T07:36:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"27ff5e27-5d89-458a-81c4-a9541f179828","html_url":"https://github.com/pawelkn/xapi-python","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":"0.017857142857142905","last_synced_commit":"43428d3d2faecbab2a17ea6eddad109db73413d9"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/pawelkn/xapi-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawelkn%2Fxapi-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawelkn%2Fxapi-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawelkn%2Fxapi-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawelkn%2Fxapi-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pawelkn","download_url":"https://codeload.github.com/pawelkn/xapi-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawelkn%2Fxapi-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275152615,"owners_count":25414450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","exchange-api","forex","forex-data","forex-trading","python","python3","trading","trading-api","websocket","x-trade-brokers","xapi","xopenhub-api","xstation","xstation-api","xstation5","xtb","xtb-api"],"created_at":"2024-11-29T14:19:11.247Z","updated_at":"2025-09-14T19:08:01.286Z","avatar_url":"https://github.com/pawelkn.png","language":"Python","readme":"# 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\n## ⚠️ DEPRECATION NOTICE\n\n**This library will no longer be functional after March 14, 2025.**\n\nXTB has announced that access to the API service through the hosts `xapi.xtb.com` and `ws.xtb.com` will be discontinued as of March 14, 2025. This means that this Python library, which relies on these API endpoints, will no longer work.\n\n---\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: \u003chttp://developers.xstore.pro/documentation\u003e\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 and subscribe to market data:\n\n```python\nimport asyncio\nimport xapi\n\n# Replace these values with your own credentials\nCREDENTIALS = {\n    \"accountId\": \"\u003cyour_client_id\u003e\",\n    \"password\": \"\u003cyour_password\u003e\",\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\n\n# Replace these values with your own credentials\nCREDENTIALS = {\n    \"accountId\": \"\u003cyour_client_id\u003e\",\n    \"password\": \"\u003cyour_password\u003e\",\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## Command Line Interface (CLI)\n\nThe 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.\n\n![xAPI in action](assets/cli-example.gif)\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\": \"\u003cyour_client_id\u003e\",\n    \"password\": \"\u003cyour_password\u003e\",\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! ☕\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelkn%2Fxapi-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawelkn%2Fxapi-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelkn%2Fxapi-python/lists"}