Getting Access is denied erro when trying to place an order

Hello, I am trying to place an order using a python script with the help of the REST API. I am getting this error.

Below is my request code.

import requests

headers = {
    'accept': 'application/json',
    'Authorization': 'Bearer <my_token_here>'
}

json_data = {
    'accountSpec': 'my_username',
    'accountId': 100001,
    'action': 'Buy',
    'symbol': 'MYMM1',
    'orderQty': 1,
    'orderType': 'Market',
    'isAutomated': True
}

requests.post(url='https://demo.tradovateapi.com/v1/order/placeorder', headers=headers, json=json_data)

print(requests.json())

This is the error which I get when I make a request. I have enabled all the permission for my test API account.

{"failureReason":"UnknownReason","failureText":"Access is denied"}

Sorry for all the edits. Can someone please let me out?

Thanks

In this case, the first thing I’d check is your API Key permissions. You’ll need to make sure you have Contract Library set to Read, Positions set to Read, Account Information set to at least Read, and Orders set to Full Access. For development purposes, I’d just enable them all. You can always filter out what you don’t need before you transition to the Live API.

Thanks, for the help I was able to get it working using the correct Account id. But all my orders are getting rejected as I have checked from https://demo.tradovateapi.com/v1/order/list endpoint.

How can I get the reason for the order getting failed?

You can find the ExecutionReport entity associated with the order (/executionReport/deps?masterid=orderId), it should have a rejectReason field.

I’m having the same issues, I have a Full Permission API created. But not able to create an order on either demo or live endpoints.

I’m also having the same problem. I’m getting:

{
  s: 200,
  i: 4,
  d: { failureReason: 'UnknownReason', failureText: 'Access is denied' }
}

I’m using the demo endpoint. I have full permissions on my API key. I’m having no issues authorizing both websocket connections. I’m sure I’m using the correct websocket (I’m getting status code 200 on my responses). I’m getting the same error on the HTTP interface. I created a device UUID that is hardcoded but I’ve only run my application from the same device so far. The “accountSpec” field on my placeOrder request is using the value of the “name” field on the response from the “user/list” endpoint and the “accountId” uses the “id” field from the same response.
I can’t think of anything else I could do differently.

I am now at the same point, with full access on the api permissions. Did anyone get this resolved?

no, support in these forums from tradovate is almost non-existent. they really need to revamp their entire API docs with proper examples…that work

Below is the code that working for me(Python):

     body = {
        "accountSpec": "XXXX",
        "accountId": 'XXXXX',
        "action": "Buy",
        "symbol": MESZ2,
        "orderQty": 1,
        "orderType": "Market",
        "isAutomated": "true"
        }
     response = requests.post("https://" + API + '/order/placeorder', headers=headers, data=body)

I suggest trying the below command to validate your API:

response = requests.post(“https://” + API + ‘/position/list’, headers=headers)

print(response.json())

I too have the same problem with access denied. My setting for the endpoint is
“accountSpec”: “My Demo Account Name”, (exp DEMO1234)
“accountId”: is my live account id number’, (exp 783458)

is Automated is set to True (with the capital T no quote because it is expecting a bool)

Do I have the correct info setup?

thank in advance for your help

I just think I am not putting the right info for the accountSpec, and accountId. Can some please explain where you get that info for the demo account

Thanks

isAutomated should not be a bool. It’s counterintuitive but it should be “true” or maybe even “True”.
Strings worked for me, not bools.

are you using JavaScript or Python, because when i tried using “true” or “True” it gave me an error, besides I don’t think the access denied has anything to do with that, am I wrong?

Thanks in advance

I’m using Python. You can check out my code below. I used “true”
And yes, I would assume that sending an incorrectly formatted request to the API would have something to do with the access denied error - but who knows.

First of all, I want to personally thank you for your library. It is awesome and very easy to understand. i actually am using your library as a model for what I am trying to do and also help me understand this API. Using your code structure I did get an error when I put the quotes for the “true”, and when I put True, it’s fine exempt for the error {“failureReason”:“UnknownReason”,“failureText”:“Access is denied”}

In your code “accountSpec”: USER_NAME which I get, but the"accountId": accId which is a refrence to DEMO_ACCOUNT_ID in your code. Is that the same as DEMO12345 in the tradovate platform.

I see your problem. You need to get your account ID from “GetAccountList.py” in my repo. It is not what you see in the desktop app that looks like “DEMO1235” it will be a number.

My Demo id is 7 digits long and my Live id is 4 digits long.

I just updated the repo so this should be really easy. I don’t know why Tradovate makes this as unintuitive as it is. I hope this helps!

Thank you so much for responding, hope this conversation not only help me but also help some one else who is having this problem.

I got the account number from the account list

‘id’: 18####, ‘name’: ‘10#####’, ‘userId’: 72####, ‘accountType’: ‘Customer’, ‘active’: True, ‘clearingHouseId’: 4, etc…

My question is in setting up the “accountSpec” and “accountId”. Is the setup as follow:
“accountSpec”: “your_tradovate_user_login_id”,
“accountId”: 18#### or 10##### or 72#### (from the account list), cause I tried every combination and still get the access denied.

thanks in advance

AccountId should be the ‘id’ field. I would try putting this into your request as a string; that’s what worked for me. Something like this:

{
...
"accountId": "18####"
...
}
#Instead of 
{...
"accountId": 18####
...}

I’m not entirely sure what “accountSpec” is but it sounds like it should be your Tradovate username.

Thank you for your help today supah. The problem was I had the wrong accountId, accountSpec,

So for anyone who may run into this problem. Try this.

Once you get your access token, run the account list to get your demo account info.
url = “https://demo.tradovateapi.com/v1/account/list
header = {
‘Authorization’: f’Bearer ${token}',
‘Content-Type’: ‘application/json’,
‘Accept’: ‘application/json’
}
res = requests.get(url, headers=header)

your json results (res) should be similar to this:

‘id’: 13#####, ‘name’: ‘DEMO######’, ‘userId’:72####, ‘accountType’: ‘Customer’,

from that you can set “accountId”: 13#####, “accountSpec”: “DEMO######”

Hope this helps someone else with access denied error.