areed1192 / td-ameritrade-python-api

Unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard API and allows users to build data pipelines for the Streaming API.
MIT License
684 stars 252 forks source link

td.exceptions.ForbidError: { "error" : "You don't have permission to access this resource." #241

Open andyquek opened 2 years ago

andyquek commented 2 years ago

Hi All

I'm trying to place a trade using the paper account, however im getting an error saying i dont have permission to access this resource.

i'm not able to find any info on what could be the problem, does anyone knows what could be causing the error?

import time

from config import CONSUMER_KEY, REDIRECT_URI, JSON_PATH, ACCOUNT_NUMBER
from hqtrades import TD_ACCOUNT
from datetime import datetime
from datetime import timedelta
import pprint
import pandas as pd

# Import the client
from td.client import TDClient

# Create a new session, credentials path is required.
TDSession = TDClient(
    client_id=CONSUMER_KEY,
    redirect_uri=REDIRECT_URI,
    credentials_path='JSON_PATH',
    account_number=ACCOUNT_NUMBER
)

# Login to the session
TDSession.login()

  # Define the Order.
  order_template = buy_limit_enter = {
      "orderType": "LIMIT",
      "session": "NORMAL",
      "duration": "DAY",
      "price": 10.0,
      "orderStrategyType": "SINGLE",
      "orderLegCollection": [
          {
              "instruction": "BUY",
              "quantity": 1,
              "instrument": {
                  "symbol": "MSFT",
                  "assetType": "EQUITY"
              }
          }
      ]
  }

  # Place the Order.
  order_response = TDSession.place_order(
      account=ACCOUNT_NUMBER,
      order=order_template
  )

  # Print the Response.
  pprint.pprint(order_response)

Below are the results:

Traceback (most recent call last):
  File "F:\using_td_library.py", line 145, in <module>
    order_response = TDSession.place_order(
  File "F:\venv\lib\site-packages\td\client.py", line 1925, in place_order
    return self._make_request(method='post', endpoint=endpoint, mode='json', json=order, order_details=True)
  File "F:\venv\lib\site-packages\td\client.py", line 624, in _make_request
    raise ForbidError(message=response.text)
td.exceptions.ForbidError: {
  "error" : "You don't have permission to access this resource."
}

Process finished with exit code 1
JuanFontana commented 2 years ago

Hello, I have the same problem, could you solve it?

TamirP commented 1 year ago

after debugging my issue, seems i passed incorrect account_id in the URL (None instead of the actual account Id), not an issue.