-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parqet.lua
74 lines (64 loc) · 2.01 KB
/
Parqet.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
WebBanking{
version = 1.0,
url = 'https://parqet.com',
services = {'Parqet'},
description = 'Fetches portfolio from Parqet'
}
function SupportsBank (protocol, bankCode)
return bankCode == 'Parqet' and protocol == ProtocolWebBanking
end
local connection
local portfolio
function InitializeSession (protocol, bankCode, username, username2, password, username3)
connection = Connection()
portfolio = username
end
function ListAccounts (knownAccounts)
local account = {
name = 'Parqet',
accountNumber = portfolio,
portfolio = true,
type = AccountTypePortfolio
}
return {account}
end
function RefreshAccount (account, since)
local securities = {}
response = connection:get('https://api.parqet.com/v1/portfolios/' .. portfolio)
json = JSON(response):dictionary()
local holdings = json['holdings']
for index, values in pairs(holdings) do
if values['assetType'] == "security" then
securities[#securities+1] = {
name = values['sharedAsset']['name'],
isin = values['security'],
securityNumber = values['security']['wkn'],
currency = nil,
quantity = values['position']['shares'],
price = values['position']['currentPrice'],
purchasePrice = values['position']['purchasePrice']
}
elseif values['assetType'] == "crypto" then
securities[#securities+1] = {
name = values['sharedAsset']['name'],
currency = nil,
quantity = values['position']['shares'],
price = values['position']['currentPrice'],
purchasePrice = values['position']['purchasePrice']
}
elseif values['assetType'] == "cash" then
securities[#securities+1] = {
name = values['nickname'],
currency = nil,
quantity = values['position']['shares'],
price = values['position']['currentPrice'],
purchasePrice = values['position']['purchasePrice']
}
else
securities[#securities+1] = {}
end
end
return {securities=securities}
end
function EndSession ()
end