SinanProjectCTP


NameSinanProjectCTP JSON
Version 1.1.13 PyPI version JSON
download
home_pagehttps://SinanProjectCTP.readthedocs.io/
SummaryCtrader Fix API
upload_time2023-12-18 22:13:13
maintainer
docs_urlNone
authorEmerson Pedroso & Douglas Barros
requires_python>=3
licenseMIT License
keywords ctrader fix-api historical-data financial-data stocks funds etfs indices currency crosses bonds commodities crypto currencies
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Pypi Publish](https://github.com/SinanProjectCTPLabs/SinanProjectCTP/actions/workflows/python-publish.yml/badge.svg)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/SinanProjectCTPLabs/SinanProjectCTP)
[![License](https://img.shields.io/github/license/SinanProjectCTPLabs/SinanProjectCTP)](https://github.com/SinanProjectLabs/SinanProjectCTP/blob/master/LICENSE)
[![PyPi downloads](https://img.shields.io/pypi/dm/SinanProjectCTP?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/SinanProjectCTP/)

# Python Ctrader Fix API

`SinanProjectCTP` is a Python library to access the Ctrader trading platform's FIX API.

## Features

- [x] Market Position buy and sell
- [x] Pending orders limit and stop (No SL and TP)
- [x] Partial close (No SL and TP)
- [x] Stop loss & Take profit Only Position
- [x] Real-time bid & ask
- [x] Check connection status
- [x] Custom Client ID and commend in Position
- [ ] Rest API server (in development)
- [ ] Webhook for Tradingviewer (in development)

## Prerequisites

The library has been tested on Python 3.7 to 3.9.

## Installation

To install the latest version of `SinanProjectCTP`, you can use pip:

```shell
pip install SinanProjectCTP -U
```
Or if you want to install from source, you can use:
```shell
pip install git+https://github.com/Omer_CP/SinanProjectCTP.git
```

## Accessing the Ctrader FIX API


To access your API, follow these simple steps:

1. Open the cTrader desktop or web platform.
2. In the bottom left corner of the platform, you will find the **Settings** option. Click on it.
3. A popup window will appear. In the menu of the popup, look for the last option: **FIX API**.
4. First, click on the **Change Password** button. Make sure to add a numeric password of at least 8 digits.
5. After changing the password, click on the **Copy to Clipboard** button from  **Trade Connection**.
6. Now, let's move to the **Trade Connection** section. Here, you will receive your data in the following format (this is an example with IC Markets for a real account):

   - Host name: (Current IP address 168.205.95.20 can be changed without notice)
   - Port: 5212 (SSL), 5202 (Plain text)
   - Password: (a/c 1104928 password)
   - SenderCompID: live.icmarkets.1104926 or demo.icmarkets.1104926  or live2.icmarkets.1104926 
   - TargetCompID: cServer
   - SenderSubID: TRADE





### Import libraries

```python
from SinanProjectCTP import Ctrader
```

### Fix account login and details

```python
server="168.205.95.20" # - Host name: (Current IP address 168.205.95.20 can be changed without notice)
account="live.icmarkets.1104926" #  - SenderCompID: live.icmarkets.1104926
password="12345678" # - The password you configured

api = Ctrader(server,account,password)

```
##### Check the connection status
```python
api.isconnected()
```
##### Logout 
```python
api.logout()
```

#### Real-time quote

##### Subscribe to symbols
```python
api.subscribe("EURUSD", "GBPUSD")
```
##### List of quotes for all symbols
```python
quote = api.quote()
print(quote)

# Output

{'EURUSD': {'bid': 1.02616, 'ask': 1.02618}, 'GBPUSD': {'bid': 1.21358, 'ask': 1.21362}}
```

#### Quote for a single symbol 
```python
quote = api.quote("EURUSD")
print(quote)

# Output

{'bid': 1.02612, 'ask': 1.02614}

```
### Market position and pending orders.

##### Market position

```python
# Buy position
price = api.quote()
price = price['EURUSD']['bid'] 

symbol = "EURUSD"
volume = 0.01 # position size:
stoploss =  round(price - 0.00010,6)
takeprofit = round(price + 0.00010,6)

id = api.buy(symbol, volume, stoploss, takeprofit)
print(f"Position: {id}")

# sell position 
price = api.quote()
price = price['EURUSD']['bid'] 

symbol = "EURUSD"
volume = 0.01 # position size
stoploss =  round(price + 0.00010,6)
takeprofit = round(price - 0.00010,6)

id = api.sell(symbol, volume, stoploss, takeprofit)
print(f"Position: {id}")
```

##### Limit Orders

```python

# Buy limit order

symbol = "EURUSD"
volume = 0.01 # order size
price = 1.18 # entry price 

id = api.buyLimit(symbol, volume, price)
print(f"Order: {id}")


# Sell limit order

symbol = "EURUSD"
volume = 0.01 # Order size
price = 1.22 # entry price 

id = api.sellLimit(symbol, volume, price)
print(f"Order: {id}")
```

#### Stop Orders

```python

# Buy stop order

symbol = "EURUSD"
volume = 0.01 # order size
price = 1.22 # entry price

id = api.buyStop(symbol, volume, price)
print(f"Order: {id}")

# Sell stop order

symbol = "EURUSD"
volume = 0.01 # order size
price = 1.18 # entry price 

api.sellStop(symbol, volume, price)

```

#### List Positions

```python
positions = api.positions()
print(positions)

```
#### List limit and stop Orders

```python
orders = api.orders()
print(orders)

```
#### Cancel order by id

```python
orders = api.orders()
for order in orders:
    api.orderCancelById(order['ord_id'])

```
#### Close position by id

```python
for position in positions:
    api.positionCloseById(position['pos_id'], position['amount'])

```

#### Cancel all orders

```python
api.cancel_all()
```

#### Close all positions

```python
api.close_all()
```
#### Parcial Close position 

```python
api.positionPartialClose(id, volume) 
```

### Disclosure

Due to certain limitations of the FIX API, there's a specific issue that arises when both the Stop Loss (SL) and Take Profit (TP) features are used concurrently. This issue occurs when one of them is triggered, the other remains open and will execute when the price reaches the specified level again, causing it to open another order. This issue needs to be addressed either within the SinanProjectCTP library or the application itself.

However, you can avoid this problem by using either the SL or TP, but not both simultaneously.

## Contributing

We welcome any contribution to `SinanProjectCTP`. Here are some ways to contribute:

1. Report issues or suggest improvements by opening an [issue](https://github.com/OmerCPLabs/SinanProjectCTP/issues).
2. Contribute with code to fix issues or add features via a [Pull Request](https://github.com/OmerCPLabs/SinanProjectCTP/pulls).

Before submitting a pull request, please make sure your codes are well formatted and tested.

## Acknowledgements

I would like to express my gratitude to [@HarukaMa](https://github.com/HarukaMa) for creating the initial project. Their work has been an invaluable starting point for my modifications and improvements.


            

Raw data

            {
    "_id": null,
    "home_page": "https://SinanProjectCTP.readthedocs.io/",
    "name": "SinanProjectCTP",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "ctrader,fix-api,historical-data,financial-data,stocks,funds,etfs,indices,currency crosses,bonds,commodities,crypto currencies",
    "author": "Emerson Pedroso & Douglas Barros",
    "author_email": "support@SinanProject.com",
    "download_url": "https://files.pythonhosted.org/packages/af/5d/2c48402453f0daaff5bef21ae60189a96d2ba3c832ba5b7e675a9830f5d7/SinanProjectCTP-1.1.13.tar.gz",
    "platform": null,
    "description": "![Pypi Publish](https://github.com/SinanProjectCTPLabs/SinanProjectCTP/actions/workflows/python-publish.yml/badge.svg)\r\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/SinanProjectCTPLabs/SinanProjectCTP)\r\n[![License](https://img.shields.io/github/license/SinanProjectCTPLabs/SinanProjectCTP)](https://github.com/SinanProjectLabs/SinanProjectCTP/blob/master/LICENSE)\r\n[![PyPi downloads](https://img.shields.io/pypi/dm/SinanProjectCTP?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/SinanProjectCTP/)\r\n\r\n# Python Ctrader Fix API\r\n\r\n`SinanProjectCTP` is a Python library to access the Ctrader trading platform's FIX API.\r\n\r\n## Features\r\n\r\n- [x] Market Position buy and sell\r\n- [x] Pending orders limit and stop (No SL and TP)\r\n- [x] Partial close (No SL and TP)\r\n- [x] Stop loss & Take profit Only Position\r\n- [x] Real-time bid & ask\r\n- [x] Check connection status\r\n- [x] Custom Client ID and commend in Position\r\n- [ ] Rest API server (in development)\r\n- [ ] Webhook for Tradingviewer (in development)\r\n\r\n## Prerequisites\r\n\r\nThe library has been tested on Python 3.7 to 3.9.\r\n\r\n## Installation\r\n\r\nTo install the latest version of `SinanProjectCTP`, you can use pip:\r\n\r\n```shell\r\npip install SinanProjectCTP -U\r\n```\r\nOr if you want to install from source, you can use:\r\n```shell\r\npip install git+https://github.com/Omer_CP/SinanProjectCTP.git\r\n```\r\n\r\n## Accessing the Ctrader FIX API\r\n\r\n\r\nTo access your API, follow these simple steps:\r\n\r\n1. Open the cTrader desktop or web platform.\r\n2. In the bottom left corner of the platform, you will find the **Settings** option. Click on it.\r\n3. A popup window will appear. In the menu of the popup, look for the last option: **FIX API**.\r\n4. First, click on the **Change Password** button. Make sure to add a numeric password of at least 8 digits.\r\n5. After changing the password, click on the **Copy to Clipboard** button from  **Trade Connection**.\r\n6. Now, let's move to the **Trade Connection** section. Here, you will receive your data in the following format (this is an example with IC Markets for a real account):\r\n\r\n   - Host name: (Current IP address 168.205.95.20 can be changed without notice)\r\n   - Port: 5212 (SSL), 5202 (Plain text)\r\n   - Password: (a/c 1104928 password)\r\n   - SenderCompID: live.icmarkets.1104926 or demo.icmarkets.1104926  or live2.icmarkets.1104926 \r\n   - TargetCompID: cServer\r\n   - SenderSubID: TRADE\r\n\r\n\r\n\r\n\r\n\r\n### Import libraries\r\n\r\n```python\r\nfrom SinanProjectCTP import Ctrader\r\n```\r\n\r\n### Fix account login and details\r\n\r\n```python\r\nserver=\"168.205.95.20\" # - Host name: (Current IP address 168.205.95.20 can be changed without notice)\r\naccount=\"live.icmarkets.1104926\" #  - SenderCompID: live.icmarkets.1104926\r\npassword=\"12345678\" # - The password you configured\r\n\r\napi = Ctrader(server,account,password)\r\n\r\n```\r\n##### Check the connection status\r\n```python\r\napi.isconnected()\r\n```\r\n##### Logout \r\n```python\r\napi.logout()\r\n```\r\n\r\n#### Real-time quote\r\n\r\n##### Subscribe to symbols\r\n```python\r\napi.subscribe(\"EURUSD\", \"GBPUSD\")\r\n```\r\n##### List of quotes for all symbols\r\n```python\r\nquote = api.quote()\r\nprint(quote)\r\n\r\n# Output\r\n\r\n{'EURUSD': {'bid': 1.02616, 'ask': 1.02618}, 'GBPUSD': {'bid': 1.21358, 'ask': 1.21362}}\r\n```\r\n\r\n#### Quote for a single symbol \r\n```python\r\nquote = api.quote(\"EURUSD\")\r\nprint(quote)\r\n\r\n# Output\r\n\r\n{'bid': 1.02612, 'ask': 1.02614}\r\n\r\n```\r\n### Market position and pending orders.\r\n\r\n##### Market position\r\n\r\n```python\r\n# Buy position\r\nprice = api.quote()\r\nprice = price['EURUSD']['bid'] \r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # position size:\r\nstoploss =  round(price - 0.00010,6)\r\ntakeprofit = round(price + 0.00010,6)\r\n\r\nid = api.buy(symbol, volume, stoploss, takeprofit)\r\nprint(f\"Position: {id}\")\r\n\r\n# sell position \r\nprice = api.quote()\r\nprice = price['EURUSD']['bid'] \r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # position size\r\nstoploss =  round(price + 0.00010,6)\r\ntakeprofit = round(price - 0.00010,6)\r\n\r\nid = api.sell(symbol, volume, stoploss, takeprofit)\r\nprint(f\"Position: {id}\")\r\n```\r\n\r\n##### Limit Orders\r\n\r\n```python\r\n\r\n# Buy limit order\r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # order size\r\nprice = 1.18 # entry price \r\n\r\nid = api.buyLimit(symbol, volume, price)\r\nprint(f\"Order: {id}\")\r\n\r\n\r\n# Sell limit order\r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # Order size\r\nprice = 1.22 # entry price \r\n\r\nid = api.sellLimit(symbol, volume, price)\r\nprint(f\"Order: {id}\")\r\n```\r\n\r\n#### Stop Orders\r\n\r\n```python\r\n\r\n# Buy stop order\r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # order size\r\nprice = 1.22 # entry price\r\n\r\nid = api.buyStop(symbol, volume, price)\r\nprint(f\"Order: {id}\")\r\n\r\n# Sell stop order\r\n\r\nsymbol = \"EURUSD\"\r\nvolume = 0.01 # order size\r\nprice = 1.18 # entry price \r\n\r\napi.sellStop(symbol, volume, price)\r\n\r\n```\r\n\r\n#### List Positions\r\n\r\n```python\r\npositions = api.positions()\r\nprint(positions)\r\n\r\n```\r\n#### List limit and stop Orders\r\n\r\n```python\r\norders = api.orders()\r\nprint(orders)\r\n\r\n```\r\n#### Cancel order by id\r\n\r\n```python\r\norders = api.orders()\r\nfor order in orders:\r\n    api.orderCancelById(order['ord_id'])\r\n\r\n```\r\n#### Close position by id\r\n\r\n```python\r\nfor position in positions:\r\n    api.positionCloseById(position['pos_id'], position['amount'])\r\n\r\n```\r\n\r\n#### Cancel all orders\r\n\r\n```python\r\napi.cancel_all()\r\n```\r\n\r\n#### Close all positions\r\n\r\n```python\r\napi.close_all()\r\n```\r\n#### Parcial Close position \r\n\r\n```python\r\napi.positionPartialClose(id, volume) \r\n```\r\n\r\n### Disclosure\r\n\r\nDue to certain limitations of the FIX API, there's a specific issue that arises when both the Stop Loss (SL) and Take Profit (TP) features are used concurrently. This issue occurs when one of them is triggered, the other remains open and will execute when the price reaches the specified level again, causing it to open another order. This issue needs to be addressed either within the SinanProjectCTP library or the application itself.\r\n\r\nHowever, you can avoid this problem by using either the SL or TP, but not both simultaneously.\r\n\r\n## Contributing\r\n\r\nWe welcome any contribution to `SinanProjectCTP`. Here are some ways to contribute:\r\n\r\n1. Report issues or suggest improvements by opening an [issue](https://github.com/OmerCPLabs/SinanProjectCTP/issues).\r\n2. Contribute with code to fix issues or add features via a [Pull Request](https://github.com/OmerCPLabs/SinanProjectCTP/pulls).\r\n\r\nBefore submitting a pull request, please make sure your codes are well formatted and tested.\r\n\r\n## Acknowledgements\r\n\r\nI would like to express my gratitude to [@HarukaMa](https://github.com/HarukaMa) for creating the initial project. Their work has been an invaluable starting point for my modifications and improvements.\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Ctrader Fix API",
    "version": "1.1.13",
    "project_urls": {
        "Bug Reports": "https://github.com/SinanProjectCTPLabs/SinanProjectCTP/issues",
        "Documentation": "https://SinanProjectCTP.readthedocs.io/",
        "Download": "https://SinanProject.com",
        "Homepage": "https://SinanProjectCTP.readthedocs.io/",
        "Source": "https://github.com/SinanProjectCTPLabs/SinanProjectCTP"
    },
    "split_keywords": [
        "ctrader",
        "fix-api",
        "historical-data",
        "financial-data",
        "stocks",
        "funds",
        "etfs",
        "indices",
        "currency crosses",
        "bonds",
        "commodities",
        "crypto currencies"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17a441eca366f68387c1c3b61f9e59a309055e1f4e7607fa3cd6265caca09cb3",
                "md5": "ab325a16f4449c1839128a847092fa85",
                "sha256": "e8277b4e6d34b9116ae57582c31ad14ab1536f75e97532c57d939e62cd8a09a8"
            },
            "downloads": -1,
            "filename": "SinanProjectCTP-1.1.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ab325a16f4449c1839128a847092fa85",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 16870,
            "upload_time": "2023-12-18T22:13:11",
            "upload_time_iso_8601": "2023-12-18T22:13:11.928954Z",
            "url": "https://files.pythonhosted.org/packages/17/a4/41eca366f68387c1c3b61f9e59a309055e1f4e7607fa3cd6265caca09cb3/SinanProjectCTP-1.1.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af5d2c48402453f0daaff5bef21ae60189a96d2ba3c832ba5b7e675a9830f5d7",
                "md5": "1238f69539cf651df24f71fea3d83274",
                "sha256": "660e31fd459affbcd41db04effa2abd8e749bcf4f618dbd0ee69c9c5ac418db6"
            },
            "downloads": -1,
            "filename": "SinanProjectCTP-1.1.13.tar.gz",
            "has_sig": false,
            "md5_digest": "1238f69539cf651df24f71fea3d83274",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 19349,
            "upload_time": "2023-12-18T22:13:13",
            "upload_time_iso_8601": "2023-12-18T22:13:13.917887Z",
            "url": "https://files.pythonhosted.org/packages/af/5d/2c48402453f0daaff5bef21ae60189a96d2ba3c832ba5b7e675a9830f5d7/SinanProjectCTP-1.1.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-18 22:13:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SinanProjectCTPLabs",
    "github_project": "SinanProjectCTP",
    "github_not_found": true,
    "lcname": "sinanprojectctp"
}
        
Elapsed time: 0.16451s