-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataAPI.py
34 lines (26 loc) · 1.22 KB
/
dataAPI.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
from bokeh.models import ColumnDataSource
from CONSTANTS import SUU_URL, HOSE_URL, PS_ENDPOINT_PORT, PS_URL
import requests, json, pandas as pd
if not "DEBUG" in globals():
DEBUG = False
data = {"volumes": {}, "buySell": {}}
def requestHoseData():
global data
res = requests.post(HOSE_URL, json={})
data = res.json()
dicBS = {key: data['buySell'][key] for key in ['buyPressure', 'index', 'sellPressure']}
sourceBuySell = ColumnDataSource(dicBS) # ['buyPressure', 'index', 'sellPressure', 'time']
dicVol = {key: data['volumes'][key] for key in ['index', 'nnBuy', 'nnSell', 'totalValue']}
sourceVolume = ColumnDataSource(dicVol) # ['index', 'nnBuy', 'nnSell', 'time', 'totalValue']
return sourceBuySell, sourceVolume
def fetchSuuData():
import urllib, json, pandas as pd
with urllib.request.urlopen(SUU_URL) as url:
data = json.loads(url.read().decode())
return data
def requestPSData():
global data
res = requests.post(PS_URL, json={})
data = res.json() # ['ohlcDataDic', 'orders', 'psPressure']
#if DEBUG: print(len(data['ohlcDataDic']['open']), len(data['orders']['index']))
return data['orders'], ColumnDataSource(data['ohlcDataDic']), data['psPressure']