Jump to content
Sign in to follow this  
artisticIguana

"ErrorMessage": "The direction of the request is invalid." when placing newtradeorder

Recommended Posts

Hello,

I've been working on this for at least two hours now. I did a search of the forum for newtradeorder and the error code that was returned in the HTTP Response Body, which yielded no search results.

Referencing this documentation: https://docs.labs.gaincapital.com/#HTTP Services/Trade.htm?TocPath=CIAPI%20Reference%7CHTTP%20Services%7CTrades%20and%20Orders%7C_____16

And when I started I was receiving these two StatusCodes fixing one, and then getting the next and resolving that as well before I got stuck.

45 A Guaranteed Order cannot be set to trigger against external price.

and

75 The total quantity of guaranteed stop orders must be equal to trade order quantity.

 

Post Body:

{
        "Currency":"EUR/USD",
        "MarketId": 401166447,
        "Direction": "buy",
        "TradingAccountId": trading_account_id,
        "Quantity": 1000,
        "AuditId": "EL2131241",
        "OfferPrice": 1.1776,
        "BidPrice": 1.1774,
        "IfDone": [
            {
            "Stop": {
                "Guaranteed": true,
                "TriggerPrice": 1.1762,
                "Applicability": "GTC",
                "Associated": true
            }
        }
    ]
}

 

HTTP Response Body:

{
  "HttpStatus": 400,
  "ErrorMessage": "The direction of the request is invalid.",
  "ErrorCode": 60107
}

 

I also tried entering the direction as "Buy", since the docs write it that way. However, I saw a few other forum posts regarding limit orders and saw that direction was specified as all lowercase.

Share this post


Link to post

Hi,

By setting "Guaranteed: true", you are attempting to place a guaranteed stop loss order on EUR/USD. Guaranteed orders are not supported/possible for spot FX markets.

Please use "Guaranteed: false" in this case.

Kind Regards, PM

Share this post


Link to post

I just made that change, and am receiving the same response body of:

{
  "HttpStatus": 400,
  "ErrorMessage": "The direction of the request is invalid.",
  "ErrorCode": 60107
}

With Guaranteed set to false.

Also, the only reason why I added the true is due to the Status Code 75 message that I was initially receiving before I added any elements to the ifDone array

 

75 The total quantity of guaranteed stop orders must be equal to trade order quantity.

 

 

Share this post


Link to post

Hello,

I've spotted it. There is a missing direction field in the Stop order part of the request. I've used the following code to successfully place a trade with attached stop. If you edit your code to be in the same format with appropriate field values it should now also work for you. 

{
	"MarketId":401484347,
	"Direction":"buy",
	"Quantity":1000,
	"BidPrice": 1.17952,
	"OfferPrice": 1.17968,
    "AuditId": "EF34926023",  
	"TradingAccountId":401637645,
	"PositionMethodId":1,
	"IfDone":[
      {
        "Stop":{        			
          "OrderId":null,
          "Direction":"Sell",
          "Applicability":"gtc",
          "ExpiryDateTimeUTC":null,
          "Quantity":1000,
          "TriggerPrice":1.17848,
          "IfDone":[],
          "OcoOrder":null
       },
        "Limit":null
      }
    ]
}

 

Kind Regards, PM

Share this post


Link to post

Jeez, such a simple mistake I made lol. I assumed that because the order was denoted as Stop in the ifDone array, that it wasn't necessary to denote the Direction in the Stop Order's JSON. There are buy stops and sell stops though, so it does make sense... Thank you for your help.

Share this post


Link to post

I guess I replied too soon.

 

Didn't test it out earlier when reading your response, but just tried to issue the request and got back Status Code:

12 The Quantity, when divided by the market lot size, should be a whole number.

Tried updating quantity to be decimal format (as that is mentioned in the docs), but still receive the same response body.

Post Body

{
	"MarketId":401166447,
	"Direction":"buy",
	"Quantity":1000,
	"OfferPrice": 1.17750,
  "BidPrice": 1.17764,
  "AuditId": "EF34926025",  
	"TradingAccountId":trading_account_id,
	"PositionMethodId":1,
	"IfDone":[
      {
        "Stop":{        			
          "OrderId":null,
          "Direction":"sell",
          "Applicability":"gtc",
          "ExpiryDateTimeUTC":null,
          "Quantity":1000,
          "TriggerPrice":1.17640,
          "IfDone":[],
          "OcoOrder":null
       },
        "Limit":null
      }
    ]
}

 

Share this post


Link to post

Hello,

Are you a Forex.com US client or from some other region? The error message mentioning Lot sizes makes me think your account is not a US account.

Presumably you are using a test/demo account and it is NOT a live, real money account? Only if it is a test/demo account, please send me a private message with the account credentials. I'll then log on and try some trade calls to investigate further. 

Kind Regards, PM

Share this post


Link to post

Hello!

Thank you for sending your demo account credentials. I have managed to successfully place a trade with attached stop loss order. 

It looks as though there were a series of issues with the call, which lead us on this chain of error messages. The most recent, and hopefully final problem is that the wrong market ID was used in your call. The MarketID for EUR/USD to use in your calls is 401484347, instead of what you actually used.  

For future reference, you can follow the directions in https://docs.labs.gaincapital.com/#How Do I/Find Market ID.htm?TocPath=How%20Do%20I...%3F%7C_____1 to search/find the Market IDs you need in your trading.

The post body that finally worked is:

{
"MarketId":401484347,
"Direction":"buy",
"Quantity":1000,
"BidPrice": 1.1762,
"OfferPrice": 1.1764, 
"TradingAccountId":<redacted>,
"PositionMethodId":1,
"IfDone":[{"Stop":{"OrderId":null,"Direction":"Sell","Applicability":"gtc","ExpiryDateTimeUTC":null,"Quantity":1000,"TriggerPrice":1.1710,"IfDone":[],"OcoOrder":null},
           "Limit":null}]
}

 

image.png

 

Kind Regards, PM

 

Share this post


Link to post

Hi Physicsman,

In the example above, I see that you have omitted the AuditId, possibly because you are an Admin? I would assume that the rest of us need it just as for a regular trade order. Is that correct?

Share this post


Link to post

Hi Kevin,

The AuditId is there to help the user in case of any dispute as it exactly tracks what market price the user had received at the time they placed the trade or entry order. 

I omitted it in my example for expediency, but users should continue to include it in their calls.

Kind Regards, PM

 

 

 

 

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
Sign in to follow this  
×