Jump to content
james

Stop and Limit not set when opening new position

Recommended Posts

I realize my follow up question on a previous thread was confusing, so I'm moving it here. As always, I really appreciate all of your help and patience!

I'm having trouble getting a stop and limit set when I open a new position using the /newtradeorder api endpoint. The request gets accepted, the response looks okay other than IfDone being empty, and I can see the open position when logging in via the platform with no stop or limit set.

What am I doing wrong?  I'm spinning my wheels, and need the insights of some smarter eyes.

Here is the request I am sending:

{
  "BidPrice": "1511.21",
  "Direction": "buy",
  "MarketId": "401153870",
  "OfferPrice": "1511.66",
  "PositionMethodId": 1,
  "Quantity": 1,
  "TradingAccountId": "401589313",
  "IfDone": {
    "Stop": {
      "Applicability": "gtc",
      "Direction": "sell",
      "ExpiryDateTimeUTC": null,
      "Guaranteed": false,
      "IfDone": [],
      "OcoOrder": null,
      "OrderId": null,
      "Quantity": 1,
      "TriggerPrice": 1510.94
    },
    "Limit": {
      "Applicability": "gtc",
      "Direction": "sell",
      "ExpiryDateTimeUTC": null,
      "IfDone": [],
      "OcoOrder": null,
      "OrderId": null,
      "Quantity": 1,
      "TriggerPrice": 1511.94
    }
  }
}

 

and here is the response:

{
  "Status": 1,
  "StatusReason": 1,
  "OrderId": 693438627,
  "Orders": [
    {
      "OrderId": 693438627,
      "StatusReason": 1,
      "Status": 3,
      "OrderTypeId": 1,
      "Price": 1511.58,
      "Quantity": 1,
      "TriggerPrice": 0,
      "CommissionCharge": 0,
      "IfDone": [],
      "GuaranteedPremium": 0,
      "OCO": null,
      "AssociatedOrders": {
        "Stop": null,
        "Limit": null
      },
      "Associated": false
    }
  ],
  "Quote": null,
  "Actions": [
    {
      "ActionedOrderId": 0,
      "ActioningOrderId": 0,
      "Quantity": 1,
      "ProfitAndLoss": 0,
      "ProfitAndLossCurrency": null,
      "OrderActionTypeId": 1
    }
  ],
  "ErrorMessage": null
}

Thank you!

- James

Share this post


Link to post

Hi @james,

It looks as though it is a syntax error in your request - a simple case of missing square brackets [ ]  around the Stop and Limit orders. 

I sent a successful call to place a trade with attached stop/limit orders and then did a line by line examination of my request with yours. I spotted the missing square brackets in your pasted code and have highlighted with green arrows in my screenshot below. I think if you add the square brackets to your call then it should work fine.

Kind Regards, PM

image.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×