-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIG_market_data.py
67 lines (41 loc) · 1.52 KB
/
IG_market_data.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
55
56
57
58
59
60
61
62
63
64
65
66
67
# Getting IG Market data
import requests
head = {"Content-Type":"application/json; charset=UTF-8",
"Accept":"application/json; charset=UTF-8",
"VERSION":"2",
"X-IG-API-KEY":""}
playloads = {"identifier":"",
"password":""}
# CST and X_SECURITY_TOKEN
import json
r = requests.post("https://demo-api.ig.com/gateway/deal/session",headers=head,data=json.dumps(playloads))
CST = r.headers['CST']
X_SECURITY_TOKEN = r.headers['X-SECURITY-TOKEN']
#We will now simply ask for the market sentiment using a query, for example. We want to use CST and X_SECURITY_TOKEN. Note that we are switching to a GET request.
head = {"Content-Type":"application/json; charset=UTF-8",
"Accept":"application/json; charset=UTF-8",
"X-IG-API-KEY":"",
"CST":CST,
"X-SECURITY-TOKEN":X_SECURITY_TOKEN}
r = requests.get("https://demo-api.ig.com/gateway/deal/clientsentiment/EURUSD", headers=head)
json.loads(r.text)
r = requests.get("https://demo-api.ig.com/gateway/deal/markets?searchTerm=eur",headers=head)
json.loads(r.text)
url = "https://demo-api.ig.com/gateway/deal/prices/"
url += "CS.D.sp_EURRUB.CFD.IP/"
url+= "MINUTE_5"
url+= "?startdate="
url+="2021:03:15-15:00:00"
url+="&enddate="
url+= "2021:03:19-12:00:00"
r = requests.get(url,headers=head)
r.text
#make an acceptable format
import json
commit_data = json.loads(r.text)
commit_data.keys()
commit_data['prices'] #on
df = pd.json_normalize(commit_data['prices'])
print(df)
plt.figure(figsize=(20,10))
df['openPrice.bid'].plot()