-
Notifications
You must be signed in to change notification settings - Fork 4
/
GetTicks.py
47 lines (40 loc) · 1.46 KB
/
GetTicks.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
import datetime
import requests
import socket
import json
import re
def extract_ip():
st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
st.connect(('10.255.255.255', 1))
IP = st.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
st.close()
return IP
host = 'http://' + extract_ip() + ':8080'
if __name__ == "__main__":
url = host + '/Ticks'
contract = {"symbol": "ES",
"secType": "FUT",
"currency": "USD",
"exchange": "GLOBEX",
"durationStr" : "2 D",
"barSizeSetting" : "15 mins",
"endDateTime" : datetime.datetime.today().strftime("%Y%m%d %H:%M:%S"),
"localSymbol" : "ESH1"
}
# ([0-9]+):( \w+: ([\-\.0-9]+),)+
pattern = "([0-9]+): Date: ([0-9]+), Open: ([\\-0-9\\.]+), High: ([\\-0-9\\.]+), Low: ([\\-0-9\\.]+), Close: ([\\-0-9\\.]+), Volume: ([\\-0-9\\.]+), Average: ([\\-0-9\\.]+), BarCount: ([\\-0-9\\.]+)"
x = requests.post(url, data = contract)
print("{}".format(x.text))
mt = re.findall(pattern, x.text)
#print("{}".format(mt))
found = False
for m in mt:
found = True
print("Date: {}, Open: {}, High: {}, Low: {}, Close: {}, Volume: {}, Average: {}, BarCount: {}"
.format(m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]))
if not found:
print(x.text)