-
Notifications
You must be signed in to change notification settings - Fork 8
/
nasdaq.py
54 lines (32 loc) · 955 Bytes
/
nasdaq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import websocket
import threading
import time
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run():
ws.send("")
time.sleep(1)
ws.close()
threading.Thread(target=run).start()
def get_stock_dict(ticker):
websocket.enableTrace(True)
url = 'ws://34.214.11.52/stream?symbol={}&start={}&end={}'.format(ticker, '20170717', '20170717')
# Create new socket and connect to url to hit API
ws = websocket.WebSocket()
ws.connect(url)
# send information and store response
ws.send("")
stock_info = ws.recv()
stock_dict = eval(stock_info)
return stock_dict
def get_high_price(ticker):
return get_stock_dict(ticker)["High"]
def get_low_price(ticker):
return get_stock_dict(ticker)["Low"]
def get_close_price(ticker):
return get_stock_dict(ticker)["Close"]