Created
August 27, 2019 16:56
-
-
Save andrewkim316/f6df6819b3e70ab30815a8286c3923ae 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
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