class key2client: # # https://github.com/polygon-io/client-python/blob/master/polygon/websocket/websocket_client.py # def my_customer_process_message(self, message): # print("this is my custom message processing", message) def __init__(self, key='aGls_e4_gw0XgXU_XY64XFrrP88o_tcQ3qmYWY'): # self.my_client = WebSocketClient(STOCKS_CLUSTER, key, self.my_customer_process_message) # self.my_client.run_async() self.RESTclient = RESTClient(key) # def subscribe(self): # self.my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA") # https://github.com/polygon-io/client-python/blob/master/rest-example.py def query(self, sym, time_str): #"AAPL", "2018-3-2" # sym, time_str = "AAPL", "2018-3-2" # client = RESTClient(key) resp = None try: resp = self.RESTclient.stocks_equities_daily_open_close( sym, time_str) # print(f"On: {resp.from_}\t{sym} opened at {resp.open} and closed at {resp.close}") except: pass # time.sleep(2) return resp
def main(): key = "your api key" client = RESTClient(key) resp = client.stocks_equities_daily_open_close("AAPL", "2018-3-2") print( f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}" )