cTraderFixPy icon indicating copy to clipboard operation
cTraderFixPy copied to clipboard

Set Short/Long & Close position Messege Template

Open ArmanAzadi opened this issue 2 years ago • 3 comments

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.

ArmanAzadi avatar Jun 10 '23 22:06 ArmanAzadi

fully agreed...unfortunately they doen't seem to care...

vism211 avatar Mar 05 '24 17:03 vism211

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/

Simongolovinskiy avatar Jun 11 '24 15:06 Simongolovinskiy

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?

danielgroen avatar Nov 19 '24 22:11 danielgroen