My set up is to have tradingview JSON alerts be sent to my AWS lamda Rest API and then have that communicate with TD Ameritrade’s REST API to trigger a limit order. I am able to run this app.py file by entering ‘chalice local’ with the command prompt while inside a virtual environment. I go to my web browser and enter hhtp://localhost:8000/quote/BA and it outputs Boeing quote information. However, when I tried to run the app.py file on AWS via ‘chalice deploy’ I updated my REST API url but when I entered (my rest api url)/quote/BA I received {"message": "Internal server error"}
I am a super noob to coding and would greatly appreciate any and all help. I have been able to successfully deploy an Alpaca script via chalice to AWS and have it place orders but I want to switch it to TD Ameritrade. I am really trying to learn more about coding in general so any extra explanations/tips/etc are welcomed.
DEMO -> app.py
from tda import auth, client
import os, json, datetime
from chalice import Chalice
from chalicelib import TDconfig
app = Chalice(app_name='AWS Algobot')
token_path = os.path.join(os.path.dirname(__file__), 'chalicelib', 'token')
c = auth.client_from_token_file(token_path, TDconfig.api_key)
u/app.route('/quote/{symbol}')
def quote(symbol):
response = c.get_quote(symbol)
return response.json()
DEMO -> chalicelib -> TDconfig.py
api_key = ‘XXXXXXXXXXX'
DEMO -> chalicelib -> token.file
I am ultimately wanting to send out limit buy and sell orders, so if anybody could help with that too, I would greatly appreciate it. I want to be able to calculate the max amount of shares I can buy and then be able to multiply that by a number in order to determine the quantity.
u/app.route('/buy_stock')def buy_stock():#Tradingview Inputrequest = app.current_requestwebhook_message = request.json_body
#Order Datadata = {"orderType": "LIMIT","session": "EXT","price": webhook_message['close'],"duration": "DAY","orderStrategyType": "SINGLE","orderLegCollection": [{"instruction": "BUY","quantity": 1#', #0.5 * {"account balance" / webhook_message['close']}"instrument": {"symbol": webhook_message['ticker'],"assetType": "EQUITY"}}]}
response = json.loads(r.content)
#Order Receiptreturn {response,'webhook_message': webhook_message}
Submitted November 12, 2020 at 07:22PM by black_squirrelist
via https://ift.tt/2IwgFeW