Skip to content

Instantly share code, notes, and snippets.

@andrewkim316
Last active August 28, 2019 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewkim316/9d460481bd75646d3c7f2b02f6c5289c to your computer and use it in GitHub Desktop.
Save andrewkim316/9d460481bd75646d3c7f2b02f6c5289c to your computer and use it in GitHub Desktop.
# 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)
if(len(orders) == 0):
return "No orders to cancel."
api.cancel_order(orders[0].id)
text = f'Most recent order cancelled. Order id = {orders[0].id}'
return text
except Exception as e:
return f"ERROR: {str(e)}"
# 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()
text = f'Account info...\nBuying power = {account.buying_power}\nEquity = {account.equity}\nPortfolio value = {account.portfolio_value}\nShorting enabled? = {account.shorting_enabled}'
return text
except Exception as e:
return f"ERROR: {str(e)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment