Skip to content

Instantly share code, notes, and snippets.

@andrewkim316
Created August 27, 2019 16:56
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/f6df6819b3e70ab30815a8286c3923ae to your computer and use it in GitHub Desktop.
Save andrewkim316/f6df6819b3e70ab30815a8286c3923ae to your computer and use it in GitHub Desktop.
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()
tif = args[4].lower()
order = api.submit_order(symbol,
side=side,
type=order_type,
qty=qty,
time_in_force=tif)
price = api.get_barset(symbol, 'minute', 1)[symbol][0].c
text = (f'Market order of | {side} {qty} {symbol} {tif} |, '
f'current equity price at {price}. '
f'Order id = {order.id}.')
requests.post(
url="https://slack.com/api/chat.postMessage",
data={
"token": config["slack_token"],
"channel": request.form.get("channel_id"),
"text": text})
except Exception as e:
reply_private(request, f"ERROR: {str(e)}")
else:
reply_private(request, BAD_ARGS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment