Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response.status_code 400: Validation error #10

Open
timcrose opened this issue Oct 9, 2020 · 1 comment
Open

response.status_code 400: Validation error #10

timcrose opened this issue Oct 9, 2020 · 1 comment

Comments

@timcrose
Copy link

timcrose commented Oct 9, 2020

I can't seem to post a trade to my real account. Most of the code below is from the trading_robot.py sample. Is this not the way to execute an order? I get NotNulError: A validation error occurred while processing the request. (this is under the _make_request function) in client.py.
`

Import libraries

from configparser import ConfigParser
from datetime import datetime
from pyrobot.robot import PyRobot

Grab configuration values.

config = ConfigParser()
config_fpath = r'C:\Users\timcr\Desktop\Documents\stocks\td_ameritrade_api\configs\config.ini'
config.read(config_fpath)
CLIENT_ID = config.get('main', 'CLIENT_ID')
REDIRECT_URI = config.get('main', 'REDIRECT_URI')
CREDENTIALS_PATH = config.get('main', 'JSON_PATH')
ACCOUNT_NUMBER = config.get('main', 'ACCOUNT_NUMBER')

Initalize the robot.

trading_robot = PyRobot(
client_id=CLIENT_ID,
redirect_uri=REDIRECT_URI,
credentials_path=CREDENTIALS_PATH,
trading_account=ACCOUNT_NUMBER,
paper_trading=False
)

Create a new Trade Object.

new_trade = trading_robot.create_trade(
trade_id='long_msft',
enter_or_exit='enter',
long_or_short='short',
order_type='lmt',
price=150.00
)

Make it Good Till Cancel.

new_trade.good_till_cancel(cancel_time=datetime.now())

Change the session

new_trade.modify_session(session='am')

Add an Order Leg.

new_trade.instrument(
symbol='MSFT',
quantity=2,
asset_type='EQUITY'
)

Add a Stop Loss Order with the Main Order.

new_trade.add_stop_loss(
stop_size=.10,
percentage=False
)

Execute order

trading_robot.execute_orders(new_trade)`

@areed1192
Copy link
Owner

I'll have to take a look and see what the issue is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants