diff --git a/bank.go b/bank.go index 1bc8766..1af5fea 100644 --- a/bank.go +++ b/bank.go @@ -95,8 +95,8 @@ type Transaction struct { CCAcctTo *CCAcct `xml:"CCACCTTO,omitempty"` // If the transfer was to a credit card account we have the account information for Memo String `xml:"MEMO,omitempty"` // Extra information (not in NAME) ImageData []ImageData `xml:"IMAGEDATA,omitempty"` - Currency String `xml:"CURRENCY,omitempty"` // If different from CURDEF in STMTTRS - OrigCurrency String `xml:"ORIGCURRENCY,omitempty"` // If different from CURDEF in STMTTRS + Currency CurrSymbol `xml:"CURRENCY,omitempty"` // If different from CURDEF in STMTTRS + OrigCurrency CurrSymbol `xml:"ORIGCURRENCY,omitempty"` // If different from CURDEF in STMTTRS Inv401kSource inv401kSource `xml:"INV401KSOURCE,omitempty"` // One of PRETAX, AFTERTAX, MATCH, PROFITSHARING, ROLLOVER, OTHERVEST, OTHERNONVEST (Default if not present is OTHERNONVEST. The following cash source types are subject to vesting: MATCH, PROFITSHARING, and OTHERVEST.) } @@ -123,8 +123,8 @@ type PendingTransaction struct { ExtdName String `xml:"EXTDNAME,omitempty"` // Extended name of payee or transaction description Memo String `xml:"MEMO,omitempty"` // Extra information (not in NAME) ImageData []ImageData `xml:"IMAGEDATA,omitempty"` - Currency String `xml:"CURRENCY,omitempty"` // If different from CURDEF in STMTTRS - OrigCurrency String `xml:"ORIGCURRENCY,omitempty"` // If different from CURDEF in STMTTRS + Currency CurrSymbol `xml:"CURRENCY,omitempty"` // If different from CURDEF in STMTTRS + OrigCurrency CurrSymbol `xml:"ORIGCURRENCY,omitempty"` // If different from CURDEF in STMTTRS } // PendingTransactionList represents a list of pending transactions, along with @@ -161,7 +161,7 @@ type StatementResponse struct { Status Status `xml:"STATUS"` CltCookie String `xml:"CLTCOOKIE,omitempty"` // TODO `xml:"OFXEXTENSION,omitempty"` - CurDef String `xml:"STMTRS>CURDEF"` + CurDef CurrSymbol `xml:"STMTRS>CURDEF"` BankAcctFrom BankAcct `xml:"STMTRS>BANKACCTFROM"` BankTranList *TransactionList `xml:"STMTRS>BANKTRANLIST,omitempty"` BankTranListP *PendingTransactionList `xml:"STMTRS>BANKTRANLISTP,omitempty"` diff --git a/bank_test.go b/bank_test.go index 2576d77..4b56a82 100644 --- a/bank_test.go +++ b/bank_test.go @@ -252,13 +252,18 @@ func TestUnmarshalBankStatementResponse(t *testing.T) { balamt.SetFrac64(20029, 100) availbalamt.SetFrac64(20029, 100) + usd, err := ofxgo.NewCurrSymbol("USD") + if err != nil { + t.Fatalf("Unexpected error creating CurrSymbol for USD\n") + } + statementResponse := ofxgo.StatementResponse{ TrnUID: "1001", Status: ofxgo.Status{ Code: 0, Severity: "INFO", }, - CurDef: "USD", + CurDef: *usd, BankAcctFrom: ofxgo.BankAcct{ BankID: "318398732", AcctID: "78346129", diff --git a/cmd/ofx/banktransactions.go b/cmd/ofx/banktransactions.go index 9b42291..df0bf7e 100644 --- a/cmd/ofx/banktransactions.go +++ b/cmd/ofx/banktransactions.go @@ -75,12 +75,12 @@ func bankTransactions() { } } -func printTransaction(defCurrency ofxgo.String, tran *ofxgo.Transaction) { +func printTransaction(defCurrency ofxgo.CurrSymbol, tran *ofxgo.Transaction) { currency := defCurrency - if len(tran.Currency) > 0 { - currency = tran.Currency - } else if len(tran.OrigCurrency) > 0 { + if ok, _ := tran.Currency.Valid(); ok { currency = tran.Currency + } else if ok, _ := tran.OrigCurrency.Valid(); ok { + currency = tran.OrigCurrency } var name string @@ -94,5 +94,5 @@ func printTransaction(defCurrency ofxgo.String, tran *ofxgo.Transaction) { name = name + " - " + string(tran.Memo) } - fmt.Printf("%s %-15s %-11s %s\n", tran.DtPosted, tran.TrnAmt.String()+" "+string(currency), tran.TrnType, name) + fmt.Printf("%s %-15s %-11s %s\n", tran.DtPosted, tran.TrnAmt.String()+" "+currency.String(), tran.TrnType, name) } diff --git a/cmd/ofx/cctransactions.go b/cmd/ofx/cctransactions.go index 9b98269..4d9f055 100644 --- a/cmd/ofx/cctransactions.go +++ b/cmd/ofx/cctransactions.go @@ -60,10 +60,10 @@ func ccTransactions() { fmt.Println("Transactions:") for _, tran := range stmt.BankTranList.Transactions { currency := stmt.CurDef - if len(tran.Currency) > 0 { - currency = tran.Currency - } else if len(tran.OrigCurrency) > 0 { + if ok, _ := tran.Currency.Valid(); ok { currency = tran.Currency + } else if ok, _ := tran.OrigCurrency.Valid(); ok { + currency = tran.OrigCurrency } var name string @@ -77,7 +77,7 @@ func ccTransactions() { name = name + " - " + string(tran.Memo) } - fmt.Printf("%s %-15s %-11s %s\n", tran.DtPosted, tran.TrnAmt.String()+" "+string(currency), tran.TrnType, name) + fmt.Printf("%s %-15s %-11s %s\n", tran.DtPosted, tran.TrnAmt.String()+" "+currency.String(), tran.TrnType, name) } } } diff --git a/cmd/ofx/invtransactions.go b/cmd/ofx/invtransactions.go index f1a60f6..b0555b4 100644 --- a/cmd/ofx/invtransactions.go +++ b/cmd/ofx/invtransactions.go @@ -178,12 +178,12 @@ func printInvTran(it *ofxgo.InvTran) { fmt.Printf("%s", it.DtTrade) } -func printInvBuy(defCurrency ofxgo.String, ib *ofxgo.InvBuy) { +func printInvBuy(defCurrency ofxgo.CurrSymbol, ib *ofxgo.InvBuy) { printInvTran(&ib.InvTran) currency := defCurrency - if ib.Currency != nil { + if ok, _ := ib.Currency.CurSym.Valid(); ok { currency = ib.Currency.CurSym - } else if ib.OrigCurrency != nil { + } else if ok, _ := ib.OrigCurrency.CurSym.Valid(); ok { currency = ib.Currency.CurSym } @@ -191,15 +191,15 @@ func printInvBuy(defCurrency ofxgo.String, ib *ofxgo.InvBuy) { // TODO print ticker instead of CUSIP } -func printInvSell(defCurrency ofxgo.String, is *ofxgo.InvSell) { +func printInvSell(defCurrency ofxgo.CurrSymbol, is *ofxgo.InvSell) { printInvTran(&is.InvTran) currency := defCurrency - if is.Currency != nil { + if ok, _ := is.Currency.CurSym.Valid(); ok { currency = is.Currency.CurSym - } else if is.OrigCurrency != nil { + } else if ok, _ := is.OrigCurrency.CurSym.Valid(); ok { currency = is.Currency.CurSym } - fmt.Printf(" %s (%s %s)@%s %s (Total: %s)\n", is.Units, is.SecID.UniqueIDType, is.SecID.UniqueID, is.UnitPrice, currency, is.Total) + fmt.Printf(" %s (%s %s)@%s %s (Total: %s)\n", is.Units, is.SecID.UniqueIDType, is.SecID.UniqueID, is.UnitPrice, currency.String(), is.Total) // TODO print ticker instead of CUSIP } diff --git a/common.go b/common.go index 1831618..b7c8dc8 100644 --- a/common.go +++ b/common.go @@ -290,7 +290,7 @@ type InvAcct struct { // Currency represents one ISO-4217 currency type Currency struct { - XMLName xml.Name // CURRENCY or ORIGCURRENCY - CurRate Amount `xml:"CURRATE"` // Ratio of currency to currency - CurSym String `xml:"CURSYM"` // ISO-4217 3-character currency identifier + XMLName xml.Name // CURRENCY or ORIGCURRENCY + CurRate Amount `xml:"CURRATE"` // Ratio of currency to currency + CurSym CurrSymbol `xml:"CURSYM"` // ISO-4217 3-character currency identifier } diff --git a/creditcard.go b/creditcard.go index 066bafb..94b93e0 100644 --- a/creditcard.go +++ b/creditcard.go @@ -48,7 +48,7 @@ type CCStatementResponse struct { Status Status `xml:"STATUS"` CltCookie String `xml:"CLTCOOKIE,omitempty"` // TODO `xml:"OFXEXTENSION,omitempty"` - CurDef String `xml:"CCSTMTRS>CURDEF"` + CurDef CurrSymbol `xml:"CCSTMTRS>CURDEF"` CCAcctFrom CCAcct `xml:"CCSTMTRS>CCACCTFROM"` BankTranList *TransactionList `xml:"CCSTMTRS>BANKTRANLIST,omitempty"` //BANKTRANLISTP diff --git a/creditcard_test.go b/creditcard_test.go index 26eadc8..6cae6fa 100644 --- a/creditcard_test.go +++ b/creditcard_test.go @@ -132,13 +132,18 @@ NEWFILEUID:NONE balamt.SetFrac64(-933400, 100) availbalamt.SetFrac64(763017, 100) + usd, err := ofxgo.NewCurrSymbol("USD") + if err != nil { + t.Fatalf("Unexpected error creating CurrSymbol for USD\n") + } + statementResponse := ofxgo.CCStatementResponse{ TrnUID: "59e850ad-7448-b4ce-4b71-29057763b306", Status: ofxgo.Status{ Code: 0, Severity: "INFO", }, - CurDef: "USD", + CurDef: *usd, CCAcctFrom: ofxgo.CCAcct{ AcctID: "9283744488463775", }, diff --git a/invstmt.go b/invstmt.go index f258422..b2e6470 100644 --- a/invstmt.go +++ b/invstmt.go @@ -1163,7 +1163,7 @@ type InvStatementResponse struct { CltCookie String `xml:"CLTCOOKIE,omitempty"` // TODO `xml:"OFXEXTENSION,omitempty"` DtAsOf Date `xml:"INVSTMTRS>DTASOF"` - CurDef String `xml:"INVSTMTRS>CURDEF"` + CurDef CurrSymbol `xml:"INVSTMTRS>CURDEF"` InvAcctFrom InvAcct `xml:"INVSTMTRS>INVACCTFROM"` InvTranList *InvTranList `xml:"INVSTMTRS>INVTRANLIST,omitempty"` InvPosList PositionList `xml:"INVSTMTRS>INVPOSLIST,omitempty"` diff --git a/invstmt_test.go b/invstmt_test.go index 6ff44bf..0b58e9a 100644 --- a/invstmt_test.go +++ b/invstmt_test.go @@ -417,6 +417,11 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { oounits2.SetFrac64(25, 1) oolimitprice2.SetFrac64(1975, 100) + usd, err := ofxgo.NewCurrSymbol("USD") + if err != nil { + t.Fatalf("Unexpected error creating CurrSymbol for USD\n") + } + statementResponse := ofxgo.InvStatementResponse{ TrnUID: "1a0117ad-692b-4c6a-a21b-020d37d34d49", Status: ofxgo.Status{ @@ -424,7 +429,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { Severity: "INFO", }, DtAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0), - CurDef: "USD", + CurDef: *usd, InvAcctFrom: ofxgo.InvAcct{ BrokerID: "invstrus.com", AcctID: "91827364", @@ -861,6 +866,11 @@ NEWFILEUID: NONE posunitprice2.SetFrac64(2987, 100) posmktval2.SetFrac64(2987, 1) + usd, err := ofxgo.NewCurrSymbol("USD") + if err != nil { + t.Fatalf("Unexpected error creating CurrSymbol for USD\n") + } + statementResponse := ofxgo.InvStatementResponse{ TrnUID: "1283719872", Status: ofxgo.Status{ @@ -868,7 +878,7 @@ NEWFILEUID: NONE Severity: "INFO", }, DtAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0), - CurDef: "USD", + CurDef: *usd, InvAcctFrom: ofxgo.InvAcct{ BrokerID: "www.exampletrader.com", AcctID: "12341234",