-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (35 loc) · 1.25 KB
/
main.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
import requests
import sys
import json
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import date, timedelta
def getAPI(url, params, headers,):
Request = requests.get(url,params=params,headers=headers)
if Request.status_code == 200:
Response = Request.json()
return Response
else:
return ""
BaseUrl = "https://gateway.saxobank.com/sim/openapi"
AccountKey = sys.argv[1]
ClientKey = sys.argv[2]
AccessToken = sys.argv[3]
Headers = {'Authorization': AccessToken,'Accept': "application/json"}
Parameters = {'AccountKey': AccountKey, 'ClientKey': ClientKey}
GetAccountPath = "/port/v1/balances"
#AccountInfo = getAPI(BaseUrl+GetAccountPath,Parameters,Headers)
#print(AccountInfo.get("TotalValue"))
GetAccountHistoryPath = "/hist/v3/accountvalues/"+ClientKey
MockParam = {"MockDataId":"001"}
AccountHistory = getAPI(BaseUrl+GetAccountHistoryPath,MockParam,Headers).get("Data")
today = date.today()
lastMonth = today - timedelta(days=30)
lastYear = today - timedelta(days=365)
for account in AccountHistory:
values = [account["AccountValue"],account["AccountValueMonth"],account["AccountValueYear"]]
dates = [lastYear, lastMonth, today]
plt.plot(dates,values)
plt.show()
exit()