1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-12-25 22:43:21 -05:00
Golang library for querying and parsing OFX
Go to file
John Starich 677a09295a Continue parsing after hitting validation errors
Supports mixed-case severity for Ally Bank's Quicken downloads 🙄
2020-03-30 10:50:10 -04:00
cmd/ofx detect_settings: Add newer APPVER's for 'QWIN' APPID 2018-10-04 06:50:38 -04:00
samples Work around missing blank line after last header 2019-01-04 11:18:55 -05:00
.travis.yml Remove old cover tool installer 2019-07-01 06:01:57 -04:00
bank_test.go Omit end tags for encoding OFX 100-series requests 2019-07-01 06:11:16 -04:00
bank.go Bank transactions: Allow transaction currencies to be empty 2019-03-06 06:00:05 -05:00
basic_client.go Support carriage returns on new lines 2019-06-26 06:23:52 -04:00
client.go Support carriage returns on new lines 2019-06-26 06:23:52 -04:00
common_test.go go vet 2017-04-10 06:05:03 -04:00
common.go Support carriage returns on new lines 2019-06-26 06:23:52 -04:00
constants_test.go go fmt 2017-11-18 05:58:32 -05:00
constants.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
creditcard_test.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
creditcard.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
discovercard_client.go Add Hack for Discover 2018-10-08 05:55:08 -04:00
doc.go Update/improve documentation 2017-05-09 16:30:35 -04:00
generate_constants.py go fmt 2017-11-18 05:58:32 -05:00
go.mod Add Go version to go.mod for compatibility guarantees 2020-03-30 10:50:10 -04:00
go.sum Update xml module 2019-07-01 06:11:17 -04:00
invstmt_test.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
invstmt.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
leaf_elements.go Omit end tags for encoding OFX 100-series requests 2019-07-01 06:11:16 -04:00
LICENSE Add license 2017-04-08 11:48:55 -04:00
profile_test.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
profile.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
README.md Add BasicClient, update Client to be interface 2018-10-02 20:55:25 -04:00
request_test.go Omit end tags for encoding OFX 100-series requests 2019-07-01 06:11:16 -04:00
request.go Omit end tags for encoding OFX 100-series requests 2019-07-01 06:11:16 -04:00
response_test.go Continue parsing after hitting validation errors 2020-03-30 10:50:10 -04:00
response.go Continue parsing after hitting validation errors 2020-03-30 10:50:10 -04:00
seclist.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
signon_test.go Add BasicClient, update Client to be interface 2018-10-02 20:55:25 -04:00
signon.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
signup_test.go Add the ability to marshal a Response to SGML/XML and test it 2019-03-02 07:03:11 -05:00
signup.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
types_test.go go fmt 2017-11-18 05:58:32 -05:00
types.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
util.go Switch to copy of encoding/xml with only that subdirectory 2017-10-02 09:21:56 -04:00
vanguard_client.go Make Client an interface instead of a struct 2018-10-03 10:18:54 -04:00

OFXGo

Go Report Card Build Status Coverage Status GoDoc

OFXGo is a library for querying OFX servers and/or parsing the responses. It also provides an example command-line client to demonstrate the use of the library.

Goals

The main purpose of this project is to provide a library to make it easier to query financial information with OFX from the comfort of Golang, without having to marshal/unmarshal to SGML or XML. The library does not intend to abstract away all of the details of the OFX specification, which would be difficult to do well. Instead, it exposes the OFX SGML/XML hierarchy as structs which mostly resemble it. Its primary goal is to enable the creation of other personal finance software in Go (as it was created to allow me to fetch OFX transactions for my own project, MoneyGo).

Because the OFX specification is rather... 'comprehensive,' it can be difficult for those unfamiliar with it to figure out where to start. To that end, I have created a sample command-line client which uses the library to do simple tasks (currently it does little more than list accounts and query for balances and transactions). My hope is that by studying its code, new users will be able to figure out how to use the library much faster than staring at the OFX specification (or this library's API documentation). The command-line client also serves as an easy way for me to test/debug the library with actual financial institutions, which frequently have 'quirks' in their implementations. The command-line client can be found in the cmd/ofx directory of this repository.

Library documentation

Documentation can be found with the go doc tool, or at https://godoc.org/github.com/aclindsa/ofxgo

Example Usage

The following code snippet demonstrates how to use OFXGo to query and parse OFX code from a checking account, printing the balance and returned transactions:

client := ofxgo.BasicClient{} // Accept the default Client settings

// These values are specific to your bank
var query ofxgo.Request
query.URL = "https://secu.example.com/ofx"
query.Signon.Org = ofxgo.String("SECU")
query.Signon.Fid = ofxgo.String("1234")

// Set your username/password
query.Signon.UserID = ofxgo.String("username")
query.Signon.UserPass = ofxgo.String("hunter2")

uid, _ := ofxgo.RandomUID() // Handle error in real code
query.Bank = append(query.Bank, &ofxgo.StatementRequest{
	TrnUID: *uid,
	BankAcctFrom: ofxgo.BankAcct{
		BankID:   ofxgo.String("123456789"),   // Possibly your routing number
		AcctID:   ofxgo.String("00011122233"), // Possibly your account number
		AcctType: ofxgo.AcctTypeChecking,
	},
	Include: true, // Include transactions (instead of only balance information)
})

response, _ := client.Request(&query) // Handle error in real code

// Was there an OFX error while processing our request?
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)
	os.Exit(1)
}

if len(response.Bank) < 1 {
	fmt.Println("No banking messages received")
	os.Exit(1)
}

if stmt, ok := response.Bank[0].(*ofxgo.StatementResponse); ok {
	fmt.Printf("Balance: %s %s (as of %s)\n", stmt.BalAmt, stmt.CurDef, stmt.DtAsOf)
	fmt.Println("Transactions:")
	for _, tran := range stmt.BankTranList.Transactions {
		currency := stmt.CurDef
		if ok, _ := tran.Currency.Valid(); ok {
			currency = tran.Currency.CurSym
		}
		fmt.Printf("%s %-15s %-11s %s%s%s\n", tran.DtPosted, tran.TrnAmt.String()+" "+currency.String(), tran.TrnType, tran.Name, tran.Payee.Name, tran.Memo)
	}
}

Requirements

OFXGo requires go >= 1.9

Using the command-line client

To install the command-line client and test it out, you may do the following:

$ go get -v github.com/aclindsa/ofxgo/cmd/ofx && go install -v github.com/aclindsa/ofxgo/cmd/ofx

Once installed (at ~/go/bin/ofx by default, if you haven't set $GOPATH), the command's usage should help you to use it (./ofx --help for a listing of the available subcommands and their purposes, ./ofx subcommand --help for individual subcommand usage).