-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bux.lua
147 lines (120 loc) · 4.23 KB
/
Bux.lua
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- Inofficial Bux Zero Extension for MoneyMoney
-- Author: Valentin Morlock
WebBanking {
version = 1.00,
url = "https://getbux.com",
services = {"Bux Zero"},
description = "View your Bux Zero portfolio in MoneyMoney"
}
local email
local passcode
local connection = Connection()
function SupportsBank(protocol, bankCode)
return protocol == ProtocolWebBanking and bankCode == "Bux Zero"
end
function InitializeSession2(protocol, bankCode, step, credentials, interactive)
if step == 1 then
email = credentials[1]
passcode = credentials[2]
end
if LocalStorage["token"] == nil and interactive == true and step == 1 then
body = JSON():set({
email = email
}):json()
headers = {
["accept-language"] = "en,",
["x-app-version"] = "4.7-7174",
["x-os-version"] = "9",
["content-type"] = "application/json",
["accept-encoding"] = "gzip",
["user-agent"] = "okhttp/4.9.1",
["Authorization"] = "Basic ODQ3MzYyMzAxMDpaTUhaM1RZT1pIVUxFRlhMUDRRQ1BIV0k1RDNWQVpNNw=="
}
connection:request("POST", "https://auth.getbux.com/api/3/magic-link", body, "application/json", headers)
return {
title = "Bux Login",
challenge = "Bitte Magic-Link aus der Mail kopieren & eingeben",
label = "Magic Link"
}
end
if LocalStorage["token"] == nil and interactive == true and step == 2 then
loginUrl = credentials[1]
_, _, loginCode = loginUrl:find("^.*/(.+)$")
if (loginCode == nil or loginCode == '') then
error("Ungültiger Link")
end
body = JSON():set({
credentials = {
token = loginCode
},
type = 'magiclink'
}):json()
headers = {
["accept-language"] = "en,",
["x-app-version"] = "4.7-7174",
["x-os-version"] = "9",
["content-type"] = "application/json",
["accept-encoding"] = "gzip",
["user-agent"] = "okhttp/4.9.1",
["Authorization"] = "Basic ODQ3MzYyMzAxMzpHRFNTS1ozUU5RQ081QkNXN0RJRFhVWEE2RENSUUNNRQ=="
}
result =
connection:request("POST", "https://auth.getbux.com/api/3/authorize", body, "application/json", headers)
LocalStorage["token"] = JSON(result):dictionary()["access_token"]
print("obtained token" .. LocalStorage["token"])
if LocalStorage["token"] == nil then
return LoginFailed
end
end
end
function ListAccounts(knownAccounts)
local account = {
name = "Bux Depot",
accountNumber = email,
currency = "EUR",
portfolio = true,
type = "AccountTypePortfolio"
}
return {account}
end
function RefreshAccount(account, since)
headers = {
["accept-language"] = "en,",
["x-app-version"] = "4.7-7174",
["x-os-version"] = "9",
["content-type"] = "application/json",
["accept-encoding"] = "gzip",
["user-agent"] = "okhttp/4.9.1",
["authorization"] = "Bearer " .. LocalStorage["token"]
}
raw = connection:request("GET", "https://stocks.prod.getbux.com/portfolio-query/13/users/me/portfolio", nil, nil,
headers)
result = JSON(raw):dictionary()
s = {}
for k, etf in pairs(result["positions"]["ETF"]) do
s[#s + 1] = {
name = etf["security"]["name"],
isin = etf["security"]["id"],
currency = nil,
quantity = etf["position"]["quantity"],
amount = etf["position"]["investmentAmount"]["amount"],
price = etf["security"]["offer"]["amount"]
}
end
for k, stock in pairs(result["positions"]["EQTY"]) do
s[#s + 1] = {
name = stock["security"]["name"],
isin = stock["security"]["id"],
currency = nil,
quantity = stock["position"]["quantity"],
amount = stock["position"]["investmentAmount"]["amount"],
price = stock["security"]["offer"]["amount"]
}
end
return {
securities = s
}
end
function EndSession()
end
-- SIGNATURE: MCwCFF9M767E2kjMhBQw+bh2g7uOcLuxAhQEv9qMeeMCdnJ9blp98uBEqfwXXA==