1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-14 09:10:05 -05:00
ofxgo/cmd/ofx/get_accounts.go

71 lines
2.0 KiB
Go
Raw Normal View History

2017-03-22 20:29:08 -04:00
package main
import (
"flag"
"fmt"
"github.com/aclindsa/ofxgo"
"os"
"time"
)
2017-04-16 20:50:06 -04:00
var getAccountsCommand = command{
2017-03-22 20:29:08 -04:00
Name: "get-accounts",
Description: "List accounts at your financial institution",
Flags: flag.NewFlagSet("get-accounts", flag.ExitOnError),
CheckFlags: checkServerFlags,
Do: getAccounts,
}
func init() {
defineServerFlags(getAccountsCommand.Flags)
}
func getAccounts() {
2017-04-16 20:50:06 -04:00
client, query := newRequest()
2017-03-22 20:29:08 -04:00
uid, err := ofxgo.RandomUID()
if err != nil {
fmt.Println("Error creating uid for transaction:", err)
os.Exit(1)
}
acctInfo := ofxgo.AcctInfoRequest{
2017-03-30 10:24:26 -04:00
TrnUID: *uid,
DtAcctUp: ofxgo.Date{Time: time.Unix(0, 0)},
2017-03-22 20:29:08 -04:00
}
query.Signup = append(query.Signup, &acctInfo)
response, err := client.Request(query)
2017-03-22 20:29:08 -04:00
if err != nil {
fmt.Println("Error requesting account information:", err)
os.Exit(1)
}
if response.Signon.Status.Code != 0 {
meaning, _ := response.Signon.Status.CodeMeaning()
fmt.Printf("Nonzero signon status (%d: %s) with message: %s\n", response.Signon.Status.Code, meaning, response.Signon.Status.Message)
2017-03-22 20:29:08 -04:00
os.Exit(1)
}
if len(response.Signup) < 1 {
2017-03-22 20:29:08 -04:00
fmt.Println("No signup messages received")
return
}
2017-03-28 19:47:17 -04:00
fmt.Printf("\nFound the following accounts:\n\n")
2017-03-22 20:29:08 -04:00
if acctinfo, ok := response.Signup[0].(*ofxgo.AcctInfoResponse); ok {
2017-03-22 20:29:08 -04:00
for _, acct := range acctinfo.AcctInfo {
if acct.BankAcctInfo != nil {
2017-04-12 21:40:42 -04:00
fmt.Printf("Bank Account:\n\tBankID: \"%s\"\n\tAcctID: \"%s\"\n\tAcctType: %s\n", acct.BankAcctInfo.BankAcctFrom.BankID, acct.BankAcctInfo.BankAcctFrom.AcctID, acct.BankAcctInfo.BankAcctFrom.AcctType)
2017-03-22 20:29:08 -04:00
} else if acct.CCAcctInfo != nil {
2017-04-12 21:40:42 -04:00
fmt.Printf("Credit card:\n\tAcctID: \"%s\"\n", acct.CCAcctInfo.CCAcctFrom.AcctID)
2017-03-22 20:29:08 -04:00
} else if acct.InvAcctInfo != nil {
2017-04-12 21:40:42 -04:00
fmt.Printf("Investment account:\n\tBrokerID: \"%s\"\n\tAcctID: \"%s\"\n", acct.InvAcctInfo.InvAcctFrom.BrokerID, acct.InvAcctInfo.InvAcctFrom.AcctID)
2017-03-22 20:29:08 -04:00
} else {
fmt.Printf("Unknown type: %s %s\n", acct.Name, acct.Desc)
}
}
}
}