From 2eaf29908b8db5bd2cf4f68cbd57e0116376777a Mon Sep 17 00:00:00 2001 From: Ani Channarasappa Date: Mon, 31 May 2021 19:48:32 -0400 Subject: [PATCH] feat: added fixed cost to lots --- README.md | 1 + internal/common/common.go | 7 ++++--- internal/position/position.go | 2 +- internal/position/position_test.go | 13 +++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b25789b..08a829e 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ lots: - symbol: "ARKW" quantity: 20.0 unit_cost: 145.35 + fixed_cost: 7.00 # e.g. brokerage commission fee ``` * Symbols not on the watchlist that exists in `lots` will automatically be watched diff --git a/internal/common/common.go b/internal/common/common.go index 348cab2..cf83f6f 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -47,9 +47,10 @@ type Dependencies struct { } type Lot struct { - Symbol string `yaml:"symbol"` - UnitCost float64 `yaml:"unit_cost"` - Quantity float64 `yaml:"quantity"` + Symbol string `yaml:"symbol"` + UnitCost float64 `yaml:"unit_cost"` + Quantity float64 `yaml:"quantity"` + FixedCost float64 `yaml:"fixed_cost"` } type CurrencyRates map[string]CurrencyRate diff --git a/internal/position/position.go b/internal/position/position.go index f6a7f80..6f8e078 100644 --- a/internal/position/position.go +++ b/internal/position/position.go @@ -63,7 +63,7 @@ func GetLots(lots []c.Lot) map[string]AggregatedLot { aggregatedLots[lot.Symbol] = AggregatedLot{ Symbol: lot.Symbol, - Cost: lot.UnitCost * lot.Quantity, + Cost: (lot.UnitCost * lot.Quantity) + lot.FixedCost, Quantity: lot.Quantity, OrderIndex: i, } diff --git a/internal/position/position_test.go b/internal/position/position_test.go index 74904e7..a11d591 100644 --- a/internal/position/position_test.go +++ b/internal/position/position_test.go @@ -34,6 +34,19 @@ var _ = Describe("Position", func() { Expect(output).To(Equal(expected)) }) }) + + When("there is a fixed cost (e.g. commission or fee)", func() { + It("should add the fixed cost onto the total cost", func() { + input := []c.Lot{ + {Symbol: "F", UnitCost: 10.00, Quantity: 10, FixedCost: 7.00}, + } + output := GetLots(input) + expected := map[string]AggregatedLot{ + "F": {Symbol: "F", Cost: 107, Quantity: 10, OrderIndex: 0}, + } + Expect(output).To(Equal(expected)) + }) + }) }) Describe("GetSymbols", func() {