Jump to content
iapaddler

Close open orders

Recommended Posts

We are trying to cancel open orders, ones that have not yet been accepted.

We used the activeorders API to get a list of open orders.

We then used the cancel API passing an orderID for any of the orders returned from activeorders. We get a 400 error with the message: “Cannot cancel order that does not have a status of ‘Pending’ or ‘Accepted’.”
{“HttpStatus”:400,“ErrorCode”:60108,“ErrorMessage”:“Cannot cancel order that does not have a status of ‘Pending’ or ‘Accepted’.“}

We found documentation for the newtradeorder API that says this:
“Place a trade to close an open position. In this case, set the Close property with the Order ID of the opening trade.” So, we used a newtradeorder API setting the array of orderIDs in the Close argument. Example: “Close”:[669633274, 669463512]. It seems that no matter what arguments we use, when we include the Close argument we get a 200 return code with a status of 4 (Cancelled) and a StatusReason of 112 (The expiry date/time cannot be changed if order is Good For Day.). There is no date or time documented as an argument for the newtradeorder API. The orders specified in the Close argument are not closed.

Share this post


Link to post

Hello,

I'd like to clarify a few points with you as there appears to be some confusion in your initial post.

1) You wrote: "We are trying to cancel open orders, ones that have not yet been accepted." Presumably you meant to write orders that have not been executed / triggered rather than "not accepted"? 

2) We're talking about Stop or Limit orders rather than open positions / trades? The NewTradeOrder call you mentioned in the 2nd part of your post is used to either place a new trade, or close a trade (open position). The call is not used to cancel Stop or Limit orders.

Which account brand do you have? For example, are you a Forex.com client from the US?

It may help if you explain what you've done and what you are trying to do and I can then explain which API calls are required to achieve your end goals.

Kind Regards, PM  

Share this post


Link to post

Hi,

1) Regarding your order cancellation. Is the order a closing (stop loss or take profit limit) order attached to an open position, or is it an opening (entry) order? The method used to cancel the order is different based on whether it is a closing or an opening order.

The CancelOrder endpoint is used to cancel opening orders, whereas UpdateTrade is used to cancel a closing order. 

2) If you are trying to place a new trade, then you do not enter any OrderIDs in the Close parameter? The Close parameter is only used when you are closing an open position. What you wrote originally in your first post indicates that you are trying to close some open positions?

An example of the JSON code to close 2 positions would be POSTing to the /order/newtradeorder endpoint with the following payload:

{
    "MarketId": 401484347,
    "Direction": "sell",
    "Close": [
        672647153,
        672647263
    ],
    "Quantity": 2000,
    "BidPrice": 1.14147,
    "OfferPrice": 1.1416,
    "TradingAccountId": 401637645
}

 

Share this post


Link to post

Thank you. This helped. I get a 200 return code with a status ID of 4 (Cancelled). All is good. 

When I do an order/activeorders call subsequently the orders cancelled are returned all with a status ID of 3 (Open). Is this expected behavior?

Share this post


Link to post

Hi,

When making a ListActiveOrders (order/activeorders) call, this returns the ListActiveOrdersResponseDTO. Within that DTO, is the ActiveOrders property that contains a TypeId. I beleive it is the TypeId code you are seeing. The lookup table for Order Type codes show that 3 indicates your order was a Limit order.

Lookup codes can be found at: http://docs.labs.gaincapital.com/#APICodesList.htm%3FTocPath%3DGetting%20Started|Lookup%20Values|_____1

 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
×