Skip to content

Commit

Permalink
refactor: renamed currency conversion code field names
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Aug 21, 2021
1 parent bb3804c commit 85d2ce2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/adapter/yahoo/yahoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func transformResponseQuote(responseQuote ResponseQuote) c.AssetQuote {
Symbol: responseQuote.Symbol,
Class: assetClass,
Currency: c.Currency{
Code: responseQuote.Currency,
FromCurrencyCode: responseQuote.Currency,
},
QuotePrice: c.QuotePrice{
Price: responseQuote.RegularMarketPrice,
Expand Down
15 changes: 6 additions & 9 deletions internal/asset/asset.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package asset

import (
q "github.com/achannarasappa/ticker/internal/adapter/yahoo"
c "github.com/achannarasappa/ticker/internal/common"
"github.com/achannarasappa/ticker/internal/currency"
)
Expand All @@ -21,18 +20,15 @@ type HoldingSummary struct {
DayChange c.HoldingChange
}

func GetAssets(dep c.Dependencies, ctx c.Context) ([]c.Asset, HoldingSummary) {
func GetAssets(ctx c.Context, assetQuotes []c.AssetQuote) ([]c.Asset, HoldingSummary) {

var holdingSummary HoldingSummary
assets := getAssetsFixed(ctx)
symbols := getSymbols(ctx.Config)
assetQuotes := q.GetAssetQuotes(*dep.HttpClient, symbols)
lotsBySymbol := getLots(ctx.Config.Lots)

for i, assetQuote := range assetQuotes {

currencyRateByUse := currency.GetCurrencyRateFromContext(ctx, assetQuote.Currency.Code)
currencyCode := currencyRateByUse.ToCurrencyCode
currencyRateByUse := currency.GetCurrencyRateFromContext(ctx, assetQuote.Currency.FromCurrencyCode)

holding := getHolding(assetQuote, lotsBySymbol)
holdingSummary = addHoldingToHoldingSummary(holdingSummary, holding, currencyRateByUse)
Expand All @@ -42,8 +38,8 @@ func GetAssets(dep c.Dependencies, ctx c.Context) ([]c.Asset, HoldingSummary) {
Symbol: assetQuote.Symbol,
Class: assetQuote.Class,
Currency: c.Currency{
Code: assetQuote.Currency.Code,
CodeConverted: currencyCode,
FromCurrencyCode: assetQuote.Currency.FromCurrencyCode,
ToCurrencyCode: currencyRateByUse.ToCurrencyCode,
},
Holding: convertAssetHoldingCurrency(currencyRateByUse, holding),
QuotePrice: convertAssetQuotePriceCurrency(currencyRateByUse, assetQuote.QuotePrice),
Expand Down Expand Up @@ -133,7 +129,8 @@ func getHolding(assetQuote c.AssetQuote, lotsBySymbol map[string]AggregatedLot)

}

func getSymbols(config c.Config) []string {
// GetSymbols retrieves a unique slice of symbols from the watchlist and lots sections of the config
func GetSymbols(config c.Config) []string {

symbols := make(map[string]bool)
symbolsUnique := make([]string, 0)
Expand Down
6 changes: 3 additions & 3 deletions internal/asset/assetFixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func getAssetsFixed(ctx c.Context) []c.Asset {
return []c.Asset{}
}

// Add currency convert
// TODO: Add currency convert
assetsFixed := make([]c.Asset, 0)

for _, configHolding := range ctx.Config.Holdings {
Expand All @@ -43,8 +43,8 @@ func getAssetsFixed(ctx c.Context) []c.Asset {
Symbol: configHolding.Symbol,
Class: getAssetFixedClass(configHolding.Class),
Currency: c.Currency{
Code: configHolding.Currency,
CodeConverted: currencyCode,
FromCurrencyCode: configHolding.Currency,
ToCurrencyCode: currencyCode,
},
Holding: c.Holding{
Value: value,
Expand Down
4 changes: 2 additions & 2 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ type Holding struct {
// Currency is the original and converted currency if applicable
type Currency struct {
// Code is the original currency code of the asset
Code string
FromCurrencyCode string
// CodeConverted is the currency code that pricing and values have been converted into
CodeConverted string
ToCurrencyCode string
}

type QuotePrice struct {
Expand Down

0 comments on commit 85d2ce2

Please sign in to comment.