mql5metatrader5forex

Can't send Take Profit and Stop loss values when posting new order to Dxtrade using Dxtrade API


I've been working with dxtrade API for a while now but I can't seem to find how to send Take Profit and Stop Loss values while posting an order with dxtrade API. How do I define these take profit and stop loss fields in the body of the post order request? Your swift response will be highly appreciated.

Here's DxTrade API documentation: https://demo.dx.trade/developers/#/

I've gone through the documentation thoroughly but couldn't find TakeProfit and Stoploss fields


Solution

  • I was able to place stop loss and take profit using order type STOP and LIMIT, passing the position code in the body. Fill in the account and order code details along with the appropriate headers.

    Opening a position:

    {
        "account":"string",
        "orderCode": "string",
        "type": "MARKET",
        "instrument": "EUR/USD",
        "quantity": 10000,
        "positionEffect": "OPEN",
        "side": "BUY",
        "tif": "GTC"
    }
    

    Get the position code from the terminal or through the api, for stop loss

    {
        "account":"string",
        "orderCode": "string",
        "type": "STOP",
        "instrument": "EUR/USD",
        "quantity": 10000,
        "positionEffect":"CLOSE",
        "positionCode":"405148769",
        "side": "SELL",
        "stopPrice": 1.09240,
        "tif": "GTC"
    }
    

    Similarly take profit

    {
        "account":"string",
        "orderCode": "string",
        "type": "LIMIT",
        "instrument": "EUR/USD",
        "quantity": 10000,
        "positionEffect":"CLOSE",
        "positionCode":"405271029",
        "side": "SELL",
        "limitPrice":1.09300,
        "tif": "GTC"
    }
    

    Hope it helps!