Jump to content

Recommended Posts

Hi there,

I have a series of unit tests that run against the methods I've written to call various GCAPI methods.

One part of this series tests my methods to call the various Trade/Order endpoints. First, I call /order/newstoplimitorder and successfully place a new resting entry order. After a few other things, I call /order/cancel on the entry order (only if the order hasn't already been triggered). This is where I'm getting a little stuck.

I'm using all the properties described in the documentation, including the Username and Session token I received on authorization (included both in the POST JSON data, and as separate headers). My OrderId property is the order id I received from opening the entry order, and the TradingAccountId was received from calling /UserAccount/ClientAndTradingAccount. This Account id was also successfully used to place the entry order.

Despite all this, I'm still receiving 401 response codes when calling /order/cancel.

Here is the POST packet: "{\"OrderId\":724499552,\"Reference\":\"Trade #724499552 setup invalidated\",\"UserName\":\"********\",\"Session\":\"a52f7a51-c01d-4a81-a6db-82eb37c70d06\",\"TradingAccountId\":*********}"

Can you tell me what I'm doing wrong?

Thanks!

Garrett

Share this post


Link to post

Hi,

I see that you are including the authentication data in the POST body. The authentication information should be sent in the headers or in the query string, NOT in the POST body. 

Please try moving the authentication out of the body and into the header and that should resolve the issue.

Kind Regards, PM

Share this post


Link to post

Hi PM,

Thanks for your reply. I was actually already including the authentication information in the headers, as well as in the POST body. I've removed it from the body, so it's solely being sent in the headers now, but I'm still having the same issue.

Strangely, my call to /order/newstoplimitorder is working fine, but /order/updatestoplimitorder and /order/cancel are returning Unauthorized, even though I'm using the same username and session token.

Any ideas as to what could be causing the issue?

Thanks!

Share this post


Link to post

Hi,

Are you using a test or demo (NOT a live real money) account for your development?

If it is a test/demo account only, please send me a private message with the account credentials. I can use it to send some cancel and update order calls to observe what happens. 

Many thanks, PM

Share this post


Link to post

Hi Garrett,

Using the account details you kindly provided, I performed the following steps in the Postman API development tool.

1) Placed an entry order.

image.png

 

2) Cancelled the order that I just placed in step 1.

image.png

 

NOTE: the headers used in calls 1, 2 and 3 are the same.

image.png

 

3) After placing a new entry order again, I then sent an /updatestoplimitorder call to modify the entry order. Important note: this call is only used to modify entry orders. If it is a stop loss or take profit limit order attached to an open position that you want to edit, use the /updatetradeorder call.

image.png

 

Please try sending your calls using the same set of parameters/headers to see if you can replicate these successful calls.

Kind Regards, PM

 

 

Share this post


Link to post

Hi PM,

Thank you for digging in to all this.

I tried replicating your calls, and still was unsuccessful in calling /order/cancel and /order/updatestoplimitorder, even with identical parameter and header signatures. This made me really dig through my application, and I finally figured out what the issue was.

As it turned out, while the headers were "correct", due to a quirk in how I had written the wrapper methods to call those endpoints, the Session token was being appended to the Session header twice just before the call took place. So, it looked like this: "Session: {token}{token}". Obviously, incorrect. Lol.

Once I fixed that, the calls worked as intended.

I feel a bit silly. Thank you for taking the time to dig through it.

Garrett

Share this post


Link to post

Hi Garrett,

Very hppy to hear you managed to figure out the problem and fix it. Glad that I could be of a little help. :)

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
×