Error when placing an order in real account

Hello everyone,

I am able to place orders in both DEMO and Market Replay modes.

When I connect to the real account, I’m able to get an auth token, request market data and do syncRequests. However, every time I try to place an order I get the following error:

What do you suggest to fix it?

Thanks.

Hello @gustrom,

Can you please share the request body?

Sure thing

Are you using the same account ID for live and demo? There is a separate account for each environment, so the IDs will differ.

For the Demo account the ID is different, this is the request body for the demo:

I am using the tutorial files, which automatically store the account id and spec after each initial connection. In this case, the order went through with no issues.

There should also be a text error accompanying the response. If you can log the message before it tries to decode it as JSON you should see raw text accompanying the error that should describe why it went wrong. It’s possible you don’t meet margin requirements, you may have a risk config on that account that prevents the order’s submission, or something to that effect (since its a 401 error).

Are you familiar with cURL? If you call this cURL and replace the angle bracketed parts with the values for your account it should return the text with the 401 response.

curl -X POST "https://live.tradovateapi.com/v1/order/placeorder" -H  "accept: application/json" -H  "Authorization: Bearer <token>" -H  "Content-Type: application/json" -d "{\"accountSpec\":\"<accountSpec>\",\"accountId\":22423,\"action\":\"Buy\",\"symbol\":\"NQH2\",\"orderQty\":1,\"orderType\":\"Limit\",\"price\":13000,\"isAutomated\":true}" 

I’ve finally fixed my issue, as @EOD_Trader said in his post…

https://community.tradovate.com/t/401-access-denied-in-order-placeorder/3650/8

When using the real account, it seems to be mandatory to include the deviceId field in the login credentials if orders are to be placed.

Later I found that the deviceId can be directly located in the Tradovate platform, when clicking Curl in the API keys configuration.

Thanks for your support.

2 Likes