Set Short/Long & Close position Messege Template
Dears, It would be appreciated if you share a "Send Message" template to open buy/sell positions with specific TP/SL and close the following positions in the market type. All of the existing code is very ambiguous (or complicated) for even mid-level users that want to start their automation with Python.
fully agreed...unfortunately they doen't seem to care...
Dears, It would be appreciated if you share a "Send Message" template to open buy/sell positions with specific TP/SL and close the following positions in the market type. All of the existing code is very ambiguous (or complicated) for even mid-level users that want to start their automation with Python.
I don't know will it help you to understand the logic of Ctrader Messages, but here's a sample to request a send order in fix client with SL and TP
def send_order(
config, symbol, side, volume, position_id=None, bucket_side=None
):
from ctrader_fix.messages import NewOrderSingle
order = NewOrderSingle(config)
order.ClOrdID = time.time()
order.Symbol = handler.ticker_dict[symbol] # there is must be digit of ticker you want to buy (Example: EURUSD == 1)
order.Side = side # Buy = 1 Sell = 2
order.OrderQty = volume # you need to check volume before buying, because you are buying a number of units(EURUSD 1 Lot == 100_000)
order.OrdType = 1 # market order
order.Designation = "From FIX"
order.RelativeSL = 150 # stop loss, enter your price here
order.AbsoluteTP = 500 # take profit, enter your price here
if bucket_side == "close": # Trigger if you want to close existing position
order.PosMaintRptID = int(position_id) # id of existing position
handler.trade.fix_client.send(order) # sending to fix client
response = trade_queue.get() # some logic is hidden, i have response processing in other thread
return response
By the way, you can check the documentation and find what you want in that. Link: https://help.ctrader.com/fix/
RelativeSL and AbsoluteTP doesnt seem to work. Also i can't find it back in the New Order Single of the documentation: https://help.ctrader.com/fix/specification/#new-order-single-msgtype35d
is there yet a way to set TP or SL?