1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-22 11:30:05 -05:00

Add comments for generated constants

This commit is contained in:
Aaron Lindsay 2017-04-12 06:02:50 -04:00
parent a05882fcda
commit c6ef8be074
3 changed files with 197 additions and 154 deletions

View File

@ -15,6 +15,7 @@ import (
type acctType uint type acctType uint
// AcctType* constants represent types of bank accounts
const ( const (
AcctTypeChecking acctType = 1 + iota AcctTypeChecking acctType = 1 + iota
AcctTypeSavings AcctTypeSavings
@ -82,6 +83,7 @@ func NewAcctType(s string) (acctType, error) {
type trnType uint type trnType uint
// TrnType* constants represent types of transactions. INT, ATM, and POS depend on the signage of the account.
const ( const (
TrnTypeCredit trnType = 1 + iota TrnTypeCredit trnType = 1 + iota
TrnTypeDebit TrnTypeDebit
@ -162,6 +164,7 @@ func NewTrnType(s string) (trnType, error) {
type imageType uint type imageType uint
// ImageType* constants represent what this image contains
const ( const (
ImageTypeStatement imageType = 1 + iota ImageTypeStatement imageType = 1 + iota
ImageTypeTransaction ImageTypeTransaction
@ -227,6 +230,7 @@ func NewImageType(s string) (imageType, error) {
type imageRefType uint type imageRefType uint
// ImageRefType* constants represent the type of reference to the image
const ( const (
ImageRefTypeOpaque imageRefType = 1 + iota ImageRefTypeOpaque imageRefType = 1 + iota
ImageRefTypeURL ImageRefTypeURL
@ -292,6 +296,7 @@ func NewImageRefType(s string) (imageRefType, error) {
type checkSup uint type checkSup uint
// CheckSup* constants represent what portions of the check this image contains
const ( const (
CheckSupFrontOnly checkSup = 1 + iota CheckSupFrontOnly checkSup = 1 + iota
CheckSupBackOnly CheckSupBackOnly
@ -357,6 +362,7 @@ func NewCheckSup(s string) (checkSup, error) {
type correctAction uint type correctAction uint
// CorrectAction* constants represent whether this transaction correction replaces or deletes the transaction matching its CORRECTFITID
const ( const (
CorrectActionDelete correctAction = 1 + iota CorrectActionDelete correctAction = 1 + iota
CorrectActionReplace CorrectActionReplace
@ -421,6 +427,7 @@ func NewCorrectAction(s string) (correctAction, error) {
type balType uint type balType uint
// BalType* constants represent how this BAL's VALUE field should be interpreted
const ( const (
BalTypeDollar balType = 1 + iota BalTypeDollar balType = 1 + iota
BalTypePercent BalTypePercent
@ -486,6 +493,7 @@ func NewBalType(s string) (balType, error) {
type inv401kSource uint type inv401kSource uint
// Inv401kSource* constants represent the source of money used for this security in a 401(k) account. Default if not present is OTHERNONVEST. The following cash source types are subject to vesting: MATCH, PROFITSHARING, and OTHERVEST.
const ( const (
Inv401kSourcePreTax inv401kSource = 1 + iota Inv401kSourcePreTax inv401kSource = 1 + iota
Inv401kSourceAfterTax Inv401kSourceAfterTax
@ -555,6 +563,7 @@ func NewInv401kSource(s string) (inv401kSource, error) {
type subAcctType uint type subAcctType uint
// SubAcctType* constants represent the sub-account type for a source and/or destination of a transaction. Used in fields named SubAcctFrom, SubAcctTo, SubAcctSec, SubAcctFund, HeldInAcct.
const ( const (
SubAcctTypeCash subAcctType = 1 + iota SubAcctTypeCash subAcctType = 1 + iota
SubAcctTypeMargin SubAcctTypeMargin
@ -621,6 +630,7 @@ func NewSubAcctType(s string) (subAcctType, error) {
type buyType uint type buyType uint
// BuyType* constants represent types of purchases
const ( const (
BuyTypeBuy buyType = 1 + iota BuyTypeBuy buyType = 1 + iota
BuyTypeBuyToCover BuyTypeBuyToCover
@ -685,6 +695,7 @@ func NewBuyType(s string) (buyType, error) {
type optAction uint type optAction uint
// OptAction* constants represent types of actions for options
const ( const (
OptActionExercise optAction = 1 + iota OptActionExercise optAction = 1 + iota
OptActionAssign OptActionAssign
@ -750,6 +761,7 @@ func NewOptAction(s string) (optAction, error) {
type tferAction uint type tferAction uint
// TferAction* constants represent whether the transfer is into or out of this account
const ( const (
TferActionIn tferAction = 1 + iota TferActionIn tferAction = 1 + iota
TferActionOut TferActionOut
@ -814,6 +826,7 @@ func NewTferAction(s string) (tferAction, error) {
type posType uint type posType uint
// PosType* constants represent position type
const ( const (
PosTypeLong posType = 1 + iota PosTypeLong posType = 1 + iota
PosTypeShort PosTypeShort
@ -878,6 +891,7 @@ func NewPosType(s string) (posType, error) {
type secured uint type secured uint
// Secured* constants represent how an option is secured
const ( const (
SecuredNaked secured = 1 + iota SecuredNaked secured = 1 + iota
SecuredCovered SecuredCovered
@ -942,6 +956,7 @@ func NewSecured(s string) (secured, error) {
type duration uint type duration uint
// Duration* constants represent how long the investment order is good for
const ( const (
DurationDay duration = 1 + iota DurationDay duration = 1 + iota
DurationGoodTilCancel DurationGoodTilCancel
@ -1007,6 +1022,7 @@ func NewDuration(s string) (duration, error) {
type restriction uint type restriction uint
// Restriction* constants represent a special restriction on an investment order
const ( const (
RestrictionAllOrNone restriction = 1 + iota RestrictionAllOrNone restriction = 1 + iota
RestrictionMinUnits RestrictionMinUnits
@ -1072,6 +1088,7 @@ func NewRestriction(s string) (restriction, error) {
type unitType uint type unitType uint
// UnitType* constants represent type of the UNITS value
const ( const (
UnitTypeShares unitType = 1 + iota UnitTypeShares unitType = 1 + iota
UnitTypeCurrency UnitTypeCurrency
@ -1136,6 +1153,7 @@ func NewUnitType(s string) (unitType, error) {
type optBuyType uint type optBuyType uint
// OptBuyType* constants represent types of purchases for options
const ( const (
OptBuyTypeBuyToOpen optBuyType = 1 + iota OptBuyTypeBuyToOpen optBuyType = 1 + iota
OptBuyTypeBuyToClose OptBuyTypeBuyToClose
@ -1200,6 +1218,7 @@ func NewOptBuyType(s string) (optBuyType, error) {
type sellType uint type sellType uint
// SellType* constants represent types of sales
const ( const (
SellTypeSell sellType = 1 + iota SellTypeSell sellType = 1 + iota
SellTypeSellShort SellTypeSellShort
@ -1264,6 +1283,7 @@ func NewSellType(s string) (sellType, error) {
type loanPmtFreq uint type loanPmtFreq uint
// LoanPmtFreq* constants represent the frequency of loan payments
const ( const (
LoanPmtFreqWeekly loanPmtFreq = 1 + iota LoanPmtFreqWeekly loanPmtFreq = 1 + iota
LoanPmtFreqBiweekly LoanPmtFreqBiweekly
@ -1336,6 +1356,7 @@ func NewLoanPmtFreq(s string) (loanPmtFreq, error) {
type incomeType uint type incomeType uint
// IncomeType* constants represent types of investment income
const ( const (
IncomeTypeCGLong incomeType = 1 + iota IncomeTypeCGLong incomeType = 1 + iota
IncomeTypeCGShort IncomeTypeCGShort
@ -1403,6 +1424,7 @@ func NewIncomeType(s string) (incomeType, error) {
type sellReason uint type sellReason uint
// SellReason* constants represent the reason the sell of a debt security was generated: CALL (the debt was called), SELL (the debt was sold), MATURITY (the debt reached maturity)
const ( const (
SellReasonCall sellReason = 1 + iota SellReasonCall sellReason = 1 + iota
SellReasonSell SellReasonSell
@ -1468,6 +1490,7 @@ func NewSellReason(s string) (sellReason, error) {
type optSellType uint type optSellType uint
// OptSellType* constants represent types of sales for options
const ( const (
OptSellTypeSellToClose optSellType = 1 + iota OptSellTypeSellToClose optSellType = 1 + iota
OptSellTypeSellToOpen OptSellTypeSellToOpen
@ -1532,6 +1555,7 @@ func NewOptSellType(s string) (optSellType, error) {
type relType uint type relType uint
// RelType* constants represent related option transaction types
const ( const (
RelTypeSpread relType = 1 + iota RelTypeSpread relType = 1 + iota
RelTypeStraddle RelTypeStraddle
@ -1598,6 +1622,7 @@ func NewRelType(s string) (relType, error) {
type charType uint type charType uint
// CharType* constants represent types of characters allowed in password
const ( const (
CharTypeAlphaOnly charType = 1 + iota CharTypeAlphaOnly charType = 1 + iota
CharTypeNumericOnly CharTypeNumericOnly
@ -1664,6 +1689,7 @@ func NewCharType(s string) (charType, error) {
type syncMode uint type syncMode uint
// SyncMode* constants represent data synchronization mode supported (see OFX spec for more details)
const ( const (
SyncModeFull syncMode = 1 + iota SyncModeFull syncMode = 1 + iota
SyncModeLite SyncModeLite
@ -1726,8 +1752,74 @@ func NewSyncMode(s string) (syncMode, error) {
return e, nil return e, nil
} }
type ofxSec uint
// OfxSec* constants represent the type of application-level security required for the message set
const (
OfxSecNone ofxSec = 1 + iota
OfxSecType1
)
var ofxSecs = [...]string{"NONE", "TYPE 1"}
func (e ofxSec) Valid() bool {
// This check is mostly out of paranoia, ensuring e != 0 should be
// sufficient
return e >= OfxSecNone && e <= OfxSecType1
}
func (e ofxSec) String() string {
if e.Valid() {
return ofxSecs[e-1]
}
return fmt.Sprintf("invalid ofxSec (%d)", e)
}
func (e *ofxSec) FromString(in string) error {
value := strings.TrimSpace(in)
for i, s := range ofxSecs {
if s == value {
*e = ofxSec(i + 1)
return nil
}
}
*e = 0
return errors.New("Invalid OfxSec: \"" + in + "\"")
}
func (e *ofxSec) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var value string
err := d.DecodeElement(&value, &start)
if err != nil {
return err
}
return e.FromString(value)
}
func (e *ofxSec) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
if !e.Valid() {
return nil
}
enc.EncodeElement(ofxSecs[*e-1], start)
return nil
}
// NewOfxSec returns returns an 'enum' value of type ofxSec given its
// string representation
func NewOfxSec(s string) (ofxSec, error) {
var e ofxSec
err := e.FromString(s)
if err != nil {
return 0, err
}
return e, nil
}
type debtType uint type debtType uint
// DebtType* constants represent debt type
const ( const (
DebtTypeCoupon debtType = 1 + iota DebtTypeCoupon debtType = 1 + iota
DebtTypeZero DebtTypeZero
@ -1792,6 +1884,7 @@ func NewDebtType(s string) (debtType, error) {
type debtClass uint type debtClass uint
// DebtClass* constants represent the class of debt
const ( const (
DebtClassTreasury debtClass = 1 + iota DebtClassTreasury debtClass = 1 + iota
DebtClassMunicipal DebtClassMunicipal
@ -1858,6 +1951,7 @@ func NewDebtClass(s string) (debtClass, error) {
type couponFreq uint type couponFreq uint
// CouponFreq* constants represent when debt coupons mature
const ( const (
CouponFreqMonthly couponFreq = 1 + iota CouponFreqMonthly couponFreq = 1 + iota
CouponFreqQuarterly CouponFreqQuarterly
@ -1925,6 +2019,7 @@ func NewCouponFreq(s string) (couponFreq, error) {
type callType uint type callType uint
// CallType* constants represent type of next call (for a debt)
const ( const (
CallTypeCall callType = 1 + iota CallTypeCall callType = 1 + iota
CallTypePut CallTypePut
@ -1991,6 +2086,7 @@ func NewCallType(s string) (callType, error) {
type assetClass uint type assetClass uint
// AssetClass* constants represent type of asset classes
const ( const (
AssetClassDomesticBond assetClass = 1 + iota AssetClassDomesticBond assetClass = 1 + iota
AssetClassIntlBond AssetClassIntlBond
@ -2060,6 +2156,7 @@ func NewAssetClass(s string) (assetClass, error) {
type mfType uint type mfType uint
// MfType* constants represent types of mutual funds
const ( const (
MfTypeOpenEnd mfType = 1 + iota MfTypeOpenEnd mfType = 1 + iota
MfTypeCloseEnd MfTypeCloseEnd
@ -2125,6 +2222,7 @@ func NewMfType(s string) (mfType, error) {
type optType uint type optType uint
// OptType* constants represent whether the option is a PUT or a CALL
const ( const (
OptTypePut optType = 1 + iota OptTypePut optType = 1 + iota
OptTypeCall OptTypeCall
@ -2189,6 +2287,7 @@ func NewOptType(s string) (optType, error) {
type stockType uint type stockType uint
// StockType* constants represent types of stock
const ( const (
StockTypeCommon stockType = 1 + iota StockTypeCommon stockType = 1 + iota
StockTypePreferred StockTypePreferred
@ -2253,72 +2352,9 @@ func NewStockType(s string) (stockType, error) {
return e, nil return e, nil
} }
type ofxSec uint
const (
OfxSecNone ofxSec = 1 + iota
OfxSecType1
)
var ofxSecs = [...]string{"NONE", "TYPE 1"}
func (e ofxSec) Valid() bool {
// This check is mostly out of paranoia, ensuring e != 0 should be
// sufficient
return e >= OfxSecNone && e <= OfxSecType1
}
func (e ofxSec) String() string {
if e.Valid() {
return ofxSecs[e-1]
}
return fmt.Sprintf("invalid ofxSec (%d)", e)
}
func (e *ofxSec) FromString(in string) error {
value := strings.TrimSpace(in)
for i, s := range ofxSecs {
if s == value {
*e = ofxSec(i + 1)
return nil
}
}
*e = 0
return errors.New("Invalid OfxSec: \"" + in + "\"")
}
func (e *ofxSec) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var value string
err := d.DecodeElement(&value, &start)
if err != nil {
return err
}
return e.FromString(value)
}
func (e *ofxSec) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
if !e.Valid() {
return nil
}
enc.EncodeElement(ofxSecs[*e-1], start)
return nil
}
// NewOfxSec returns returns an 'enum' value of type ofxSec given its
// string representation
func NewOfxSec(s string) (ofxSec, error) {
var e ofxSec
err := e.FromString(s)
if err != nil {
return 0, err
}
return e, nil
}
type holderType uint type holderType uint
// HolderType* constants represent how the account is held
const ( const (
HolderTypeIndividual holderType = 1 + iota HolderTypeIndividual holderType = 1 + iota
HolderTypeJoint HolderTypeJoint
@ -2386,6 +2422,7 @@ func NewHolderType(s string) (holderType, error) {
type acctClassification uint type acctClassification uint
// AcctClassification* constants represent the type of an account
const ( const (
AcctClassificationPersonal acctClassification = 1 + iota AcctClassificationPersonal acctClassification = 1 + iota
AcctClassificationBusiness AcctClassificationBusiness
@ -2452,6 +2489,7 @@ func NewAcctClassification(s string) (acctClassification, error) {
type svcStatus uint type svcStatus uint
// SvcStatus* constants represent the status of the account: AVAIL = Available, but not yet requested, PEND = Requested, but not yet available, ACTIVE = In use
const ( const (
SvcStatusAvail svcStatus = 1 + iota SvcStatusAvail svcStatus = 1 + iota
SvcStatusPend SvcStatusPend
@ -2517,6 +2555,7 @@ func NewSvcStatus(s string) (svcStatus, error) {
type usProductType uint type usProductType uint
// UsProductType* constants represent type of investment account (in the US)
const ( const (
UsProductType401K usProductType = 1 + iota UsProductType401K usProductType = 1 + iota
UsProductType403B UsProductType403B

View File

@ -1183,6 +1183,51 @@ func TestSyncMode(t *testing.T) {
} }
} }
func TestOfxSec(t *testing.T) {
e, err := ofxgo.NewOfxSec("NONE")
if err != nil {
t.Fatalf("Unexpected error creating new OfxSec from string \"NONE\"\n")
}
if !e.Valid() {
t.Fatalf("OfxSec unexpectedly invalid\n")
}
err = e.FromString("TYPE 1")
if err != nil {
t.Fatalf("Unexpected error on OfxSec.FromString(\"TYPE 1\")\n")
}
if e.String() != "TYPE 1" {
t.Fatalf("OfxSec.String() expected to be \"TYPE 1\"\n")
}
marshalHelper(t, "TYPE 1", &e)
overwritten, err := ofxgo.NewOfxSec("THISWILLNEVERBEAVALIDENUMSTRING")
if err == nil {
t.Fatalf("Expected error creating new OfxSec from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n")
}
if overwritten.Valid() {
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
}
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
}
b, err := xml.Marshal(&overwritten)
if err != nil {
t.Fatalf("Unexpected error on xml.Marshal(OfxSec): %s\n", err)
}
if string(b) != "" {
t.Fatalf("Expected empty string, got '%s'\n", string(b))
}
unmarshalHelper(t, "TYPE 1", &e, &overwritten)
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
if err == nil {
t.Fatalf("Expected error unmarshalling garbage value\n")
}
}
func TestDebtType(t *testing.T) { func TestDebtType(t *testing.T) {
e, err := ofxgo.NewDebtType("COUPON") e, err := ofxgo.NewDebtType("COUPON")
if err != nil { if err != nil {
@ -1543,51 +1588,6 @@ func TestStockType(t *testing.T) {
} }
} }
func TestOfxSec(t *testing.T) {
e, err := ofxgo.NewOfxSec("NONE")
if err != nil {
t.Fatalf("Unexpected error creating new OfxSec from string \"NONE\"\n")
}
if !e.Valid() {
t.Fatalf("OfxSec unexpectedly invalid\n")
}
err = e.FromString("TYPE 1")
if err != nil {
t.Fatalf("Unexpected error on OfxSec.FromString(\"TYPE 1\")\n")
}
if e.String() != "TYPE 1" {
t.Fatalf("OfxSec.String() expected to be \"TYPE 1\"\n")
}
marshalHelper(t, "TYPE 1", &e)
overwritten, err := ofxgo.NewOfxSec("THISWILLNEVERBEAVALIDENUMSTRING")
if err == nil {
t.Fatalf("Expected error creating new OfxSec from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n")
}
if overwritten.Valid() {
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
}
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
}
b, err := xml.Marshal(&overwritten)
if err != nil {
t.Fatalf("Unexpected error on xml.Marshal(OfxSec): %s\n", err)
}
if string(b) != "" {
t.Fatalf("Expected empty string, got '%s'\n", string(b))
}
unmarshalHelper(t, "TYPE 1", &e, &overwritten)
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
if err == nil {
t.Fatalf("Expected error unmarshalling garbage value\n")
}
}
func TestHolderType(t *testing.T) { func TestHolderType(t *testing.T) {
e, err := ofxgo.NewHolderType("INDIVIDUAL") e, err := ofxgo.NewHolderType("INDIVIDUAL")
if err != nil { if err != nil {

View File

@ -2,53 +2,53 @@
enums = { enums = {
# Bank/general # Bank/general
"AcctType": ["Checking", "Savings", "MoneyMrkt", "CreditLine", "CD"], "AcctType": (["Checking", "Savings", "MoneyMrkt", "CreditLine", "CD"], "types of bank accounts"),
"TrnType": ["Credit", "Debit", "Int", "Div", "Fee", "SrvChg", "Dep", "ATM", "POS", "Xfer", "Check", "Payment", "Cash", "DirectDep", "DirectDebit", "RepeatPmt", "Hold", "Other"], "TrnType": (["Credit", "Debit", "Int", "Div", "Fee", "SrvChg", "Dep", "ATM", "POS", "Xfer", "Check", "Payment", "Cash", "DirectDep", "DirectDebit", "RepeatPmt", "Hold", "Other"], "types of transactions. INT, ATM, and POS depend on the signage of the account."),
"ImageType": ["Statement", "Transaction", "Tax"], "ImageType": (["Statement", "Transaction", "Tax"], "what this image contains"),
"ImageRefType": ["Opaque", "URL", "FormURL"], "ImageRefType": (["Opaque", "URL", "FormURL"], "the type of reference to the image"),
"CheckSup": ["FrontOnly", "BackOnly", "FrontAndBack"], "CheckSup": (["FrontOnly", "BackOnly", "FrontAndBack"], "what portions of the check this image contains"),
"CorrectAction": ["Delete", "Replace"], "CorrectAction": (["Delete", "Replace"], "whether this transaction correction replaces or deletes the transaction matching its CORRECTFITID"),
"BalType": ["Dollar", "Percent", "Number"], "BalType": (["Dollar", "Percent", "Number"], "how this BAL's VALUE field should be interpreted"),
# InvStmt # InvStmt
"Inv401kSource": ["PreTax", "AfterTax", "Match", "ProfitSharing", "Rollover", "OtherVest", "OtherNonVest"], "Inv401kSource": (["PreTax", "AfterTax", "Match", "ProfitSharing", "Rollover", "OtherVest", "OtherNonVest"], "the source of money used for this security in a 401(k) account. Default if not present is OTHERNONVEST. The following cash source types are subject to vesting: MATCH, PROFITSHARING, and OTHERVEST."),
"SubAcctType": ["Cash", "Margin", "Short", "Other"], # used in fields named: SubAcctSec, HeldInAcct, SubAcctFund "SubAcctType": (["Cash", "Margin", "Short", "Other"], "the sub-account type for a source and/or destination of a transaction. Used in fields named SubAcctFrom, SubAcctTo, SubAcctSec, SubAcctFund, HeldInAcct."),
"BuyType": ["Buy", "BuyToCover"], "BuyType": (["Buy", "BuyToCover"], "types of purchases"),
"OptAction": ["Exercise", "Assign", "Expire"], "OptAction": (["Exercise", "Assign", "Expire"], "types of actions for options"),
"TferAction": ["In", "Out"], "TferAction": (["In", "Out"], "whether the transfer is into or out of this account"),
"PosType": ["Long", "Short"], "PosType": (["Long", "Short"], "position type"),
"Secured": ["Naked", "Covered"], "Secured": (["Naked", "Covered"], "how an option is secured"),
"Duration": ["Day", "GoodTilCancel", "Immediate"], "Duration": (["Day", "GoodTilCancel", "Immediate"], "how long the investment order is good for"),
"Restriction": ["AllOrNone", "MinUnits", "None"], "Restriction": (["AllOrNone", "MinUnits", "None"], "a special restriction on an investment order"),
"UnitType": ["Shares", "Currency"], "UnitType": (["Shares", "Currency"], "type of the UNITS value"),
"OptBuyType": ["BuyToOpen", "BuyToClose"], "OptBuyType": (["BuyToOpen", "BuyToClose"], "types of purchases for options"),
"SellType": ["Sell", "SellShort"], "SellType": (["Sell", "SellShort"], "types of sales"),
"LoanPmtFreq": ["Weekly", "Biweekly", "TwiceMonthly", "Monthly", "FourWeeks", "BiMonthly", "Quarterly", "Semiannually", "Annually", "Other"], "LoanPmtFreq": (["Weekly", "Biweekly", "TwiceMonthly", "Monthly", "FourWeeks", "BiMonthly", "Quarterly", "Semiannually", "Annually", "Other"], "the frequency of loan payments"),
"IncomeType": ["CGLong", "CGShort", "Div", "Interest", "Misc"], "IncomeType": (["CGLong", "CGShort", "Div", "Interest", "Misc"], "types of investment income"),
"SellReason": ["Call", "Sell", "Maturity"], "SellReason": (["Call", "Sell", "Maturity"], "the reason the sell of a debt security was generated: CALL (the debt was called), SELL (the debt was sold), MATURITY (the debt reached maturity)"),
"OptSellType": ["SellToClose", "SellToOpen"], "OptSellType": (["SellToClose", "SellToOpen"], "types of sales for options"),
"RelType": ["Spread", "Straddle", "None", "Other"], "RelType": (["Spread", "Straddle", "None", "Other"], "related option transaction types"),
# Prof # Prof
"CharType": ["AlphaOnly", "NumericOnly", "AlphaOrNumeric", "AlphaAndNumeric"], "CharType": (["AlphaOnly", "NumericOnly", "AlphaOrNumeric", "AlphaAndNumeric"], "types of characters allowed in password"),
"SyncMode": ["Full", "Lite"], "SyncMode": (["Full", "Lite"], "data synchronization mode supported (see OFX spec for more details)"),
"OfxSec": (["None", "Type 1"], "the type of application-level security required for the message set"),
# SecList # SecList
"DebtType": ["Coupon", "Zero"], "DebtType": (["Coupon", "Zero"], "debt type"),
"DebtClass": ["Treasury", "Municipal", "Corporate", "Other"], "DebtClass": (["Treasury", "Municipal", "Corporate", "Other"], "the class of debt"),
"CouponFreq": ["Monthly", "Quarterly", "Semiannual", "Annual", "Other"], "CouponFreq": (["Monthly", "Quarterly", "Semiannual", "Annual", "Other"], "when debt coupons mature"),
"CallType": ["Call", "Put", "Prefund", "Maturity"], "CallType": (["Call", "Put", "Prefund", "Maturity"], "type of next call (for a debt)"),
"AssetClass": ["DomesticBond", "IntlBond", "LargeStock", "SmallStock", "IntlStock", "MoneyMrkt", "Other"], "AssetClass": (["DomesticBond", "IntlBond", "LargeStock", "SmallStock", "IntlStock", "MoneyMrkt", "Other"], "type of asset classes"),
"MfType": ["OpenEnd", "CloseEnd", "Other"], "MfType": (["OpenEnd", "CloseEnd", "Other"], "types of mutual funds"),
"OptType": ["Put", "Call"], "OptType": (["Put", "Call"], "whether the option is a PUT or a CALL"),
"StockType": ["Common", "Preferred", "Convertible", "Other"], "StockType": (["Common", "Preferred", "Convertible", "Other"], "types of stock"),
"OfxSec": ["None", "Type 1"],
# Signup # Signup
"HolderType": ["Individual", "Joint", "Custodial", "Trust", "Other"], "HolderType": (["Individual", "Joint", "Custodial", "Trust", "Other"], "how the account is held"),
"AcctClassification": ["Personal", "Business", "Corporate", "Other"], "AcctClassification": (["Personal", "Business", "Corporate", "Other"], "the type of an account"),
"SvcStatus": ["Avail", "Pend", "Active"], "SvcStatus": (["Avail", "Pend", "Active"], "the status of the account: AVAIL = Available, but not yet requested, PEND = Requested, but not yet available, ACTIVE = In use"),
"UsProductType": ["401K", "403B", "IRA", "KEOGH", "Other", "SARSEP", "Simple", "Normal", "TDA", "Trust", "UGMA"], "UsProductType": (["401K", "403B", "IRA", "KEOGH", "Other", "SARSEP", "Simple", "Normal", "TDA", "Trust", "UGMA"], "type of investment account (in the US)"),
} }
header = """package ofxgo header = """package ofxgo
@ -70,6 +70,7 @@ import (
template = """ template = """
type {enumLower} uint type {enumLower} uint
// {enum}* constants represent {comment}
const ( const (
{constNames}) {constNames})
@ -136,22 +137,25 @@ with open("constants.go", 'w') as f:
for enum in enums: for enum in enums:
enumLower = enum[:1].lower() + enum[1:].replace(" ", "") enumLower = enum[:1].lower() + enum[1:].replace(" ", "")
firstValue = enum+enums[enum][0].replace(" ", "") firstValue = enum+enums[enum][0][0].replace(" ", "")
lastValue = enum+enums[enum][-1].replace(" ", "") lastValue = enum+enums[enum][0][-1].replace(" ", "")
comment = enums[enum][1]
constNames = "\t{firstValue} {enumLower} = 1 + iota\n".format( constNames = "\t{firstValue} {enumLower} = 1 + iota\n".format(
enum=enum, enum=enum,
firstValue=firstValue, firstValue=firstValue,
enumLower=enumLower) enumLower=enumLower)
for value in enums[enum][1:]: for value in enums[enum][0][1:]:
constNames += "\t{enum}{value}\n".format( constNames += "\t{enum}{value}\n".format(
enum=enum, enum=enum,
value=value.replace(" ", "")) value=value.replace(" ", ""))
upperValueString = "\", \"".join([s.upper() for s in enums[enum]]) upperValueString = "\", \"".join([s.upper() for s in enums[enum][0]])
f.write(template.format(enum=enum, f.write(template.format(enum=enum,
enumLower=enumLower, enumLower=enumLower,
comment=comment,
firstValue=firstValue, firstValue=firstValue,
lastValue=lastValue, lastValue=lastValue,
constNames=constNames, constNames=constNames,
@ -224,8 +228,8 @@ with open("constants_test.go", 'w') as f:
f.write(test_header) f.write(test_header)
for enum in enums: for enum in enums:
firstValueUpper = enums[enum][0].upper() firstValueUpper = enums[enum][0][0].upper()
lastValueUpper = enums[enum][-1].upper() lastValueUpper = enums[enum][0][-1].upper()
f.write(test_template.format(enum=enum, f.write(test_template.format(enum=enum,
firstValueUpper=firstValueUpper, firstValueUpper=firstValueUpper,
lastValueUpper=lastValueUpper)) lastValueUpper=lastValueUpper))