This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
forked from plaid/plaid-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
investment_transactions.go
103 lines (91 loc) · 3.7 KB
/
investment_transactions.go
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
package plaid
import (
"encoding/json"
"errors"
)
type InvestmentTransaction struct {
InvestmentTransactionID string `json:"investment_transaction_id"`
AccountID string `json:"account_id"`
SecurityID string `json:"security_id"`
CancelTransactionID string `json:"cancel_transaction_id"`
Date string `json:"date"`
Name string `json:"name"`
Quantity float64 `json:"quantity"`
Amount float64 `json:"amount"`
Price float64 `json:"price"`
Fees float64 `json:"fees"`
Type string `json:"type"`
Subtype string `json:"subtype"`
ISOCurrencyCode string `json:"iso_currency_code"`
UnofficialCurrencyCode string `json:"unofficial_currency_code"`
}
type GetInvestmentTransactionsResponse struct {
APIResponse
Item Item `json:"item"`
Accounts []Account `json:"accounts"`
InvestmentTransactions []InvestmentTransaction `json:"investment_transactions"`
Securities []Security `json:"securities"`
TotalInvestmentTransactions int `json:"total_investment_transactions"`
}
type GetInvestmentTransactionsOptions struct {
StartDate string
EndDate string
AccountIDs []string
Count int
Offset int
}
type getInvestmentTransactionsRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
AccessToken string `json:"access_token"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
Options getInvestmentTransactionsRequestOptions `json:"options,omitempty"`
}
type getInvestmentTransactionsRequestOptions struct {
AccountIDs []string `json:"account_ids"`
Count int `json:"count"`
Offset int `json:"offset"`
}
// GetInvestmentTransactionsWithOptions retrieves user-authorized investment transaction data for investment-type accounts.
// See https://plaid.com/docs/#investment-transactions.
func (c *Client) GetInvestmentTransactionsWithOptions(accessToken string, options GetInvestmentTransactionsOptions) (resp GetInvestmentTransactionsResponse, err error) {
if accessToken == "" {
return resp, errors.New("/investments/transactions/get - access token must be specified")
}
if options.StartDate == "" || options.EndDate == "" {
return resp, errors.New("/investment/transactions/get - start date and end date must be specified")
}
req := getInvestmentTransactionsRequest{
ClientID: c.clientID,
Secret: c.secret,
AccessToken: accessToken,
StartDate: options.StartDate,
EndDate: options.EndDate,
Options: getInvestmentTransactionsRequestOptions{
Count: options.Count,
Offset: options.Offset,
},
}
if len(options.AccountIDs) > 0 {
req.Options.AccountIDs = options.AccountIDs
}
jsonBody, err := json.Marshal(req)
if err != nil {
return resp, err
}
err = c.Call("/investments/transactions/get", jsonBody, &resp)
return resp, err
}
// GetInvestmentTransactions retrieves user-authorized transaction data for investment-type accounts.
// See https://plaid.com/docs/#investment-transactions.
func (c *Client) GetInvestmentTransactions(accessToken, startDate, endDate string) (resp GetInvestmentTransactionsResponse, err error) {
options := GetInvestmentTransactionsOptions{
StartDate: startDate,
EndDate: endDate,
AccountIDs: []string{},
Count: 100,
Offset: 0,
}
return c.GetInvestmentTransactionsWithOptions(accessToken, options)
}