Package: ejtraderCT
Python Ctrader Fix APIejtraderCTis a Python library to access the Ctrader trading platform's FIX API.FeaturesMarket Position buy and sellPending orders limit and stop (No SL and TP)Partial close (No SL and TP)Stop loss & Take profit Only PositionReal-time bid & askCheck connection statusCustom Client ID and commend in PositionRest API server (in development)Webhook for Tradingviewer (in development)PrerequisitesThe library has been tested on Python 3.7 to 3.9.InstallationTo install the latest version ofejtraderCT, you can use pip:pipinstallejtraderCT-UOr if you want to install from source, you can use:pipinstallgit+https://github.com/ejtraderLabs/ejtraderCT.gitAccessing the Ctrader FIX APITo access your API, follow these simple steps:Open the cTrader desktop or web platform.In the bottom left corner of the platform, you will find theSettingsoption. Click on it.A popup window will appear. In the menu of the popup, look for the last option:FIX API.First, click on theChange Passwordbutton. Make sure to add a numeric password of at least 8 digits.After changing the password, click on theCopy to Clipboardbutton fromTrade Connection.Now, let's move to theTrade Connectionsection. 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.1104926TargetCompID: cServerSenderSubID: TRADEImport librariesfromejtraderCTimportCtraderFix account login and detailsserver="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.1104926password="12345678"# - The password you configuredapi=Ctrader(server,account,password)Check the connection statusapi.isconnected()Logoutapi.logout()Real-time quoteSubscribe to symbolsapi.subscribe("EURUSD","GBPUSD")List of quotes for all symbolsquote=api.quote()print(quote)# Output{'EURUSD':{'bid':1.02616,'ask':1.02618},'GBPUSD':{'bid':1.21358,'ask':1.21362}}Quote for a single symbolquote=api.quote("EURUSD")print(quote)# Output{'bid':1.02612,'ask':1.02614}Market position and pending orders.Market position# Buy positionprice=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 positionprice=api.quote()price=price['EURUSD']['bid']symbol="EURUSD"volume=0.01# position sizestoploss=round(price+0.00010,6)takeprofit=round(price-0.00010,6)id=api.sell(symbol,volume,stoploss,takeprofit)print(f"Position:{id}")Limit Orders# Buy limit ordersymbol="EURUSD"volume=0.01# order sizeprice=1.18# entry priceid=api.buyLimit(symbol,volume,price)print(f"Order:{id}")# Sell limit ordersymbol="EURUSD"volume=0.01# Order sizeprice=1.22# entry priceid=api.sellLimit(symbol,volume,price)print(f"Order:{id}")Stop Orders# Buy stop ordersymbol="EURUSD"volume=0.01# order sizeprice=1.22# entry priceid=api.buyStop(symbol,volume,price)print(f"Order:{id}")# Sell stop ordersymbol="EURUSD"volume=0.01# order sizeprice=1.18# entry priceapi.sellStop(symbol,volume,price)List Positionspositions=api.positions()print(positions)List limit and stop Ordersorders=api.orders()print(orders)Cancel order by idorders=api.orders()fororderinorders:api.orderCancelById(order['ord_id'])Close position by idforpositioninpositions:api.positionCloseById(position['pos_id'],position['amount'])Cancel all ordersapi.cancel_all()Close all positionsapi.close_all()Parcial Close positionapi.positionPartialClose(id,volume)DisclosureDue 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 ejtraderCT library or the application itself.However, you can avoid this problem by using either the SL or TP, but not both simultaneously.ContributingWe welcome any contribution toejtraderCT. Here are some ways to contribute:Report issues or suggest improvements by opening anissue.Contribute with code to fix issues or add features via aPull Request.Before submitting a pull request, please make sure your codes are well formatted and tested.AcknowledgementsI would like to express my gratitude to@HarukaMafor creating the initial project. Their work has been an invaluable starting point for my modifications and improvements.