From e38c49a556414886d829466316c2e009c6d85b13 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Thu, 21 Sep 2017 21:00:30 -0400 Subject: [PATCH] Use default currency for top-level 'Trading' account Also add missing transaction.Rollback() calls on early returns in GetAccountTransactions() --- accounts.go | 7 ++++++- transactions.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/accounts.go b/accounts.go index 920c1d9..54760f1 100644 --- a/accounts.go +++ b/accounts.go @@ -189,10 +189,15 @@ func GetTradingAccount(transaction *gorp.Transaction, userid int64, securityid i var tradingAccount Account var account Account + user, err := GetUserTx(transaction, userid) + if err != nil { + return nil, err + } + tradingAccount.UserId = userid tradingAccount.Type = Trading tradingAccount.Name = "Trading" - tradingAccount.SecurityId = 840 /*USD*/ //FIXME SecurityId shouldn't matter for top-level trading account, but maybe we should grab the user's default + tradingAccount.SecurityId = user.DefaultCurrency tradingAccount.ParentAccountId = -1 // Find/create the top-level trading account diff --git a/transactions.go b/transactions.go index 54649dc..cc448c7 100644 --- a/transactions.go +++ b/transactions.go @@ -834,11 +834,13 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6 } atl.TotalTransactions = count - security, err := GetSecurity(atl.Account.SecurityId, user.UserId) + security, err := GetSecurityTx(transaction, atl.Account.SecurityId, user.UserId) if err != nil { + transaction.Rollback() return nil, err } if security == nil { + transaction.Rollback() return nil, errors.New("Security not found") }