Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Short/Long & Close position Messege Template #18

Open
ArmanAzadi opened this issue Jun 10, 2023 · 2 comments
Open

Set Short/Long & Close position Messege Template #18

ArmanAzadi opened this issue Jun 10, 2023 · 2 comments

Comments

@ArmanAzadi
Copy link

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.

@vism211
Copy link

vism211 commented Mar 5, 2024

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

@Simongolovinskiy
Copy link

Simongolovinskiy commented Jun 11, 2024

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants