Skip to content

Commit

Permalink
feat: added fixed cost to lots
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed May 31, 2021
1 parent 31feadd commit 2eaf299
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/position/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
13 changes: 13 additions & 0 deletions internal/position/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2eaf299

Please sign in to comment.