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
# Execute an order. Must contain 5, 6, or 7 arguments: type, symbol, | |
# quantity, side, time in force, limit price (optional), and stop price | |
# (optional). | |
@app.route("/order", methods=["POST"]) | |
def order_handler(): | |
args = request.form.get("text").split(" ") | |
if(len(args) == 0): | |
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
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"; | |
const stock_dict = [ | |
{"abbVie": "ABBV"}, | |
{"apple": "AAPL"}, | |
{"activision blizzard": "ATVI"}, |
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
from flask import Flask, request | |
import alpaca_trade_api as tradeapi | |
import requests | |
import asyncio | |
import json | |
# Constants used throughout the script (names are self-explanatory). | |
# Must hard code SLACK TOKEN, KEY_ID, SECRET_KEY, channel | |
WRONG_NUM_ARGS = "ERROR: Incorrect amount of args. Action did not complete." | |
BAD_ARGS = "ERROR: Request error. Action did not complete." |
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 MarketOrderInProgressIntentHandler = { | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'MarketOrderIntent' | |
&& Alexa.getDialogState(handlerInput.requestEnvelope) !== 'COMPLETED'; | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.addDelegateDirective() | |
.getResponse(); |
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 stock_dict = [ | |
{"abbVie": "ABBV"}, | |
{"apple": "AAPL"}, | |
{"activision blizzard": "ATVI"}, | |
{"ak steel": "AKS"}, | |
{"alibaba": "BABA"}, | |
{"alphabet": "GOOGL"}, | |
{"amazon": "AMZN"}, | |
{"amd": "AMD"}, | |
{"aphria": "APHA"}, |
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
# Stream listeners | |
@conn.on(r'trade_updates') | |
async def trade_updates_handler(conn, chan, data): | |
if data.event == "new": | |
return "" | |
elif data.event == "fill" or data.event == "partial_fill": | |
text = f'*Event*: {data.event}, {data.order["type"]} order of | {data.order["side"]} {data.order["qty"]} {data.order["symbol"]} {data.order["time_in_force"]} | {data.event} at {data.price}' | |
else: |
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
# Unsubsribe to streaming channel(s). Must contain one or more arguments | |
# representing streams you want to disconnect to. | |
@app.route("/unsubscribe_streaming", methods=["POST"]) | |
def unsubscribe_handler(): | |
args = request.form.get("text").split(" ") | |
if len(args) == 1 and args[0].strip() == "": | |
return BAD_ARGS | |
try: |
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
# Subscribe to streaming channel(s). Must contain one or more arguments | |
# representing streams you want to connect to. | |
@app.route("/subscribe_streaming", methods=["POST"]) | |
def stream_data_handler(): | |
args = request.form.get("text").split(" ") | |
if len(args) == 1 and args[0].strip() == "": | |
return BAD_ARGS | |
try: |
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 CancelOrderIntentHandler = { | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'CancelOrderIntent'; | |
}, | |
async handle(handlerInput) { | |
// Get user inputs and declare the Alpaca object | |
const slots = handlerInput.requestEnvelope.request.intent.slots; | |
const api = new Alpaca({ | |
keyId: keyId, |
NewerOlder