11package asset
22
33import (
4+ "strings"
5+
46 c "github.com/achannarasappa/ticker/v4/internal/common"
57)
68
@@ -26,8 +28,21 @@ func GetAssets(ctx c.Context, assetGroupQuote c.AssetGroupQuote) ([]c.Asset, Hol
2628 var holdingSummary HoldingSummary
2729 assets := make ([]c.Asset , 0 )
2830 holdingsBySymbol := getLots (assetGroupQuote .AssetGroup .ConfigAssetGroup .Holdings )
31+ orderIndex := make (map [string ]int )
32+
33+ for i , symbol := range assetGroupQuote .AssetGroup .ConfigAssetGroup .Watchlist {
34+ if _ , exists := orderIndex [symbol ]; ! exists {
35+ orderIndex [strings .ToLower (symbol )] = i
36+ }
37+ }
38+
39+ for i , symbol := range assetGroupQuote .AssetGroup .ConfigAssetGroup .Holdings {
40+ if _ , exists := orderIndex [symbol .Symbol ]; ! exists {
41+ orderIndex [strings .ToLower (symbol .Symbol )] = i + len (assetGroupQuote .AssetGroup .ConfigAssetGroup .Watchlist ) - 1
42+ }
43+ }
2944
30- for i , assetQuote := range assetGroupQuote .AssetQuotes {
45+ for _ , assetQuote := range assetGroupQuote .AssetQuotes {
3146
3247 currencyRateByUse := getCurrencyRateByUse (ctx , assetQuote .Currency .FromCurrencyCode , assetQuote .Currency .ToCurrencyCode , assetQuote .Currency .Rate )
3348
@@ -50,7 +65,7 @@ func GetAssets(ctx c.Context, assetGroupQuote c.AssetGroupQuote) ([]c.Asset, Hol
5065 Exchange : assetQuote .Exchange ,
5166 Meta : c.Meta {
5267 IsVariablePrecision : assetQuote .Meta .IsVariablePrecision ,
53- OrderIndex : i ,
68+ OrderIndex : orderIndex [ strings . ToLower ( assetQuote . Symbol )] ,
5469 },
5570 })
5671
0 commit comments