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/64c35d8ed05e77cf44272349caf2babc to your computer and use it in GitHub Desktop.
Save andrewkim316/64c35d8ed05e77cf44272349caf2babc to your computer and use it in GitHub Desktop.
# 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
async def sub_get_price_polygon(api, request, args):
try:
text = "Listing prices..."
args = map(lambda x: x.upper(), args)
for symbol in args:
quote = api.polygon.last_quote(symbol)
text += f'\n{symbol}: Bid price = {quote.bidprice}, Ask price = {quote.askprice}'
reply_private(request, text)
except Exception as e:
reply_private(request, f"ERROR: {str(e)}")
asyncio.run(sub_get_price_polygon(api, request, args))
return ""
# Gets price specified stock symbols. Must include one or more arguments
# representing stock symbols.
@app.route("/get_price", methods=["POST"])
def get_price_handler():
args = request.form.get("text").split(" ")
if(len(args) == 1 and args[0].strip() == ""):
return WRONG_NUM_ARGS
async def sub_get_price(api, request, args):
try:
text = "Listing prices..."
args = map(lambda x: x.upper(), args)
bars = api.get_barset(args, "minute", 1)
for bar in bars:
text += f'\n{bar}: Price = {bars[bar][0].c}, Time = {bars[bar][0].t}'
reply_private(request, text)
except Exception as e:
reply_private(request, f"ERROR: {str(e)}")
asyncio.run(sub_get_price(api, request, args))
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment