func GetTradingAccount(tx store.Tx, userid int64, securityid int64) (*models.Account, error) {
	var tradingAccount models.Account
	var account models.Account
	user, err := tx.GetUser(userid)
	if err != nil {
		return nil, err
	}
	tradingAccount.UserId = userid
	tradingAccount.Type = models.Trading
	tradingAccount.Name = "Trading"
	tradingAccount.SecurityId = user.DefaultCurrency
	tradingAccount.ParentAccountId = -1
	ta, err := GetCreateAccount(tx, tradingAccount)
	if err != nil {
		return nil, err
	}
	security, err := tx.GetSecurity(securityid, userid)
	if err != nil {
		return nil, err
	}
	account.UserId = userid
	account.Name = security.Name
	account.ParentAccountId = ta.AccountId
	account.SecurityId = securityid
	account.Type = models.Trading
	a, err := GetCreateAccount(tx, account)
	if err != nil {
		return nil, err
	}
	return a, nil
}
Get (and attempt to create if it doesn't exist) the security/currency
trading account for the supplied security/currency
package handlers
import (
	"errors"
	"github.com/aclindsa/moneygo/internal/models"
	"github.com/aclindsa/moneygo/internal/store"
	"log"
	"net/http"
)
func GetCreateAccount(tx store.Tx, a models.Account) (*models.Account, error) {
	var account models.Account
	accounts, err := tx.FindMatchingAccounts(&a)
	if err != nil {
		return nil, err
	}
	if len(*accounts) > 0 {
		account = *(*accounts)[0]
	} else {
		account.UserId = a.UserId
		account.SecurityId = a.SecurityId
		account.Type = a.Type
		account.Name = a.Name
		account.ParentAccountId = a.ParentAccountId
		err = tx.InsertAccount(&account)
		if err != nil {
			return nil, err
		}
	}
	return &account, nil
}