Last active
August 27, 2019 16:41
-
-
Save andrewkim316/42cd4402697d62455469e19d0da78ab8 to your computer and use it in GitHub Desktop.
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 | |
import os | |
# Constants used throughout the script (names are self-explanatory) | |
WRONG_NUM_ARGS = "ERROR: Incorrect amount of args. Action did not complete." | |
BAD_ARGS = "ERROR: Request error. Action did not complete." | |
KEY_ID = "" # Your API Key ID | |
SECRET_KEY = "" # Your Secret Key | |
SLACK_TOKEN = "" # Slack OAuth Access Token | |
config = { | |
"key_id": os.environ.get("KEY_ID", KEY_ID), | |
"secret_key": os.environ.get("SECRET_KEY", SECRET_KEY), | |
"base_url": os.environ.get("BASE_URL", "https://paper-api.alpaca.markets"), | |
"slack_token": os.environ.get("SLACK_TOKEN", SLACK_TOKEN), | |
} | |
api = tradeapi.REST( | |
key_id=config.get('key_id'), | |
secret_key=config.get('secret_key'), | |
base_url=config.get('base_url'), | |
) | |
# Initialize the Flask object which will be used to handle HTTP requests | |
# from Slack | |
app = Flask(__name__) | |
def reply_private(request, text): | |
requests.post( | |
url=request.form.get("response_url"), | |
data=json.dumps({"text": text}), | |
headers={"Content-type": "application/json"}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment