Skip to content

Instantly share code, notes, and snippets.

View andrewkim316's full-sized avatar
🙃
Proud user of Github Desktop

Andrew Kim andrewkim316

🙃
Proud user of Github Desktop
View GitHub Profile
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()
asyncio.run(sub_order(api, request, args))
return ""
# Run on local port 3000
if __name__ == "__main__":
app.run(port=3000)
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({
const Alexa = require('ask-sdk-core');
const Alpaca = require('@alpacahq/alpaca-trade-api');
const keyId = "KEY_ID_HERE";
const secretKey = "SECRET_KEY_HERE";
# 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"):
# 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):
# 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()
# 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
# 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)
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({