Skip to content

Commit

Permalink
fix: Add Id in QuoteAssets achannarasappa#245
Browse files Browse the repository at this point in the history
  • Loading branch information
tutilus committed Jul 31, 2024
1 parent d7d0b2a commit a6aaf41
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func updateHoldingWeights(assets []c.Asset, holdingSummary HoldingSummary) []c.A

func getHoldingFromAssetQuote(assetQuote c.AssetQuote, lotsBySymbol map[string]AggregatedLot, currencyRateByUse currency.CurrencyRateByUse) c.Holding {

if aggregatedLot, ok := lotsBySymbol[assetQuote.Symbol]; ok {
// fix #240: Use Asset Id in place of Symbol as unique id
if aggregatedLot, ok := lotsBySymbol[assetQuote.Id]; ok {
value := aggregatedLot.Quantity * assetQuote.QuotePrice.Price * currencyRateByUse.QuotePrice
cost := aggregatedLot.Cost * currencyRateByUse.PositionCost
totalChangeAmount := value - cost
Expand Down
3 changes: 3 additions & 0 deletions internal/asset/asset_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var fixtureAssetGroupQuote = c.AssetGroupQuote{
},
AssetQuotes: []c.AssetQuote{
{
Id: "TWKS",
Name: "ThoughtWorks",
Symbol: "TWKS",
Class: c.AssetClassStock,
Expand All @@ -37,6 +38,7 @@ var fixtureAssetGroupQuote = c.AssetGroupQuote{
},
},
{
Id: "MSFT",
Name: "Microsoft Inc",
Symbol: "MSFT",
Class: c.AssetClassStock,
Expand All @@ -52,6 +54,7 @@ var fixtureAssetGroupQuote = c.AssetGroupQuote{
},
},
{
Id: "SOL1-USD",
Name: "Solana USD",
Symbol: "SOL1-USD",
Class: c.AssetClassCryptocurrency,
Expand Down
2 changes: 2 additions & 0 deletions internal/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var _ = Describe("Asset", func() {
inputAssetGroupQuote := fixtureAssetGroupQuote
inputAssetGroupQuote.AssetQuotes = []c.AssetQuote{
{
Id: "TWKS",
Name: "ThoughtWorks",
Symbol: "TWKS",
Class: c.AssetClassStock,
Expand All @@ -110,6 +111,7 @@ var _ = Describe("Asset", func() {
QuoteExtended: c.QuoteExtended{FiftyTwoWeekHigh: 150, FiftyTwoWeekLow: 50, MarketCap: 1000000},
},
{
Id: "MSFT",
Name: "Microsoft Inc",
Symbol: "MSFT",
Class: c.AssetClassStock,
Expand Down
1 change: 1 addition & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const (

// AssetQuote represents a price quote and related attributes for a single security
type AssetQuote struct {
Id string
Name string
Symbol string
Class AssetClass
Expand Down
2 changes: 2 additions & 0 deletions internal/quote/coincap/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

// Quote represents a quote of a single security from the API response
type Quote struct {
Id string `json:"id"`
ShortName string `json:"name"`
Symbol string `json:"symbol"`
RegularMarketChangePercent string `json:"changePercent24Hr"`
Expand All @@ -32,6 +33,7 @@ func transformQuote(responseQuote Quote) c.AssetQuote {
volume, _ := strconv.ParseFloat(responseQuote.RegularMarketVolume, 64)

assetQuote := c.AssetQuote{
Id: strings.ToUpper(responseQuote.Id) + ".CC",
Name: responseQuote.ShortName,
Symbol: responseQuote.Symbol,
Class: c.AssetClassCryptocurrency,
Expand Down
1 change: 1 addition & 0 deletions internal/quote/coingecko/coingecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func transformResponseToAssetQuotes(responseQuotes *ResponseQuotes) []c.AssetQuo
for _, responseQuote := range *responseQuotes {

assetQuote := c.AssetQuote{
Id: strings.ToUpper(responseQuote.Id) + ".CG",
Name: responseQuote.Name,
Symbol: strings.ToUpper(responseQuote.Symbol),
Class: c.AssetClassCryptocurrency,
Expand Down
1 change: 1 addition & 0 deletions internal/quote/yahoo/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func transformResponseQuote(responseQuote ResponseQuote) c.AssetQuote {
isVariablePrecision := (assetClass == c.AssetClassCryptocurrency)

assetQuote := c.AssetQuote{
Id: responseQuote.Symbol,
Name: responseQuote.ShortName,
Symbol: responseQuote.Symbol,
Class: assetClass,
Expand Down

0 comments on commit a6aaf41

Please sign in to comment.