Skip to content

Instantly share code, notes, and snippets.

@hasandiwan
Created February 22, 2020 02:21
Show Gist options
  • Save hasandiwan/6c8335c27edc615af78d4595765b0d86 to your computer and use it in GitHub Desktop.
Save hasandiwan/6c8335c27edc615af78d4595765b0d86 to your computer and use it in GitHub Desktop.
How to predict the Market using hd1-units.herokuapp.com
import argparse
import requests
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Get the next day's predicted market close and tolerance range for any US-listed equity")
parser.add_argument('SYMBOL', help='symbol', action='store', type=str)
parsed = parser.parse_args()
URL = 'https://hd1-units.herokuapp.com/stock'
params = {'sym': parsed.SYMBOL}
resp = requests.get(URL, params=params).json()
#[prices.update({r : resp[r]}) for r in resp if ' Close' in r else del(r)]
prices = {}
for r in resp:
if not r.endswith('Close'):
continue
prices[r[:r.index(' ')]] = resp[r]
csv = ','.join(prices.values())
stats_response = requests.post('https://hd1-units.herokuapp.com/stat', data=csv, headers={'Content-type': 'text/csv'}).json()
print(f'''Next {parsed.SYMBOL} close will be between {stats_response['lowerQuartile']} and {stats_response['upperQuartile']} with a predicted value of {stats_response['predictionNext']}.''')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment