-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdataFilter.py
39 lines (33 loc) · 1.19 KB
/
dataFilter.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
import json
def socket(feed, prev={}):
try:
# only full feed will not raise exception
prev['currentPrice']= feed['ltp']
prev['commulativeVolume']= feed['v']
# prev['vwap']= feed['ap'] ........ will be updated by our own function
prev['intervalHigh']= max(feed['ltp'], prev['intervalHigh'])
prev['intervalLow']= min(feed['ltp'], prev['intervalLow'])
prev['dayHigh']= max(feed['ltp'], prev['dayHigh'])
prev['dayLow']= min(feed['ltp'], prev['dayLow'])
prev['intervalVolume']= feed['v']-prev['intervalOpenVolume']
except:
print('required data missing in the tick')
return 0
#print('updated to:', temp)
return prev
def historicDataFilter(data):
# data is in the form of string
# data will be called in chunks from the api
dataList= data.split('\n')
for i in range(len(dataList)):
vals= dataList[i].split(',')
obj= {
'time': vals[0],
'open': vals[1],
'high': vals[2],
'low': vals[3],
'close': vals[4],
'volume': vals[5]
}
dataList[i]= json.dumps(obj)
return json.dumps(dataList)