This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def sub_order(api, request, args): | |
order_type = args[0].lower() | |
if order_type == "market": | |
if len(args) < 5: | |
reply_private(request, WRONG_NUM_ARGS) | |
return | |
try: | |
side = args[1] | |
qty = args[2] | |
symbol = args[3].upper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asyncio.run(sub_order(api, request, args)) | |
return "" | |
# Run on local port 3000 | |
if __name__ == "__main__": | |
app.run(port=3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MarketOrderIntentHandler = { | |
// Triggers when user invokes a market order | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'MarketOrderIntent'; | |
}, | |
async handle(handlerInput) { | |
// Get user inputs and declare the Alpaca object | |
const slots = handlerInput.requestEnvelope.request.intent.slots; | |
const api = new Alpaca({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Alexa = require('ask-sdk-core'); | |
const Alpaca = require('@alpacahq/alpaca-trade-api'); | |
const keyId = "KEY_ID_HERE"; | |
const secretKey = "SECRET_KEY_HERE"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lists certain things. Must contain 1 argument: orders, positions, or | |
# streams. | |
@app.route("/list", methods=["POST"]) | |
def list_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) == 0): | |
return WRONG_NUM_ARGS | |
if(args[0] == "positions"): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clears positions or orders. Must contain 1 argument: positions or orders | |
@app.route("/clear", methods=["POST"]) | |
def clear_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) == 0): | |
return WRONG_NUM_ARGS | |
if(args[0] == "positions"): | |
async def sub_clear_positions(api, request): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets basic account info. Takes no arguments. | |
@app.route("/account_info", methods=["POST"]) | |
def account_info_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) != 0 and not (len(args) == 1 and args[0].strip() == "")): | |
return WRONG_NUM_ARGS | |
try: | |
account = api.get_account() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets Polygon price specified stock symbols. Must include one or more | |
# arguments representing stock symbols. Must have live account to access. | |
@app.route("/get_price_polygon", methods=["POST"]) | |
def get_price_polygon_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) == 1 and args[0].strip() == ""): | |
return WRONG_NUM_ARGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cancels most recent order. Takes no arguments. | |
@app.route("/cancel_recent_order", methods=["POST"]) | |
def cancel_recent_order_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) != 0 and not (len(args) == 1 and args[0].strip() == "")): | |
return WRONG_NUM_ARGS | |
try: | |
orders = api.list_orders(status="open", limit=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const StopLimitOrderIntentHandler = { | |
// Triggers when user wants to execute a stop limit order | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'StopLimitOrderIntent'; | |
}, | |
async handle(handlerInput) { | |
// Get user inputs and declare the Alpaca object | |
const slots = handlerInput.requestEnvelope.request.intent.slots; | |
const api = new Alpaca({ |