Skip to content

Commit

Permalink
fix issue with new dividend naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
gerbenjacobs committed Jun 23, 2023
1 parent fcaddd4 commit 9c92724
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions trading212/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ func Aggregate(splits []fin.Splits, events []TradeEvent) ([]fin.Aggregate, fin.T
var totals fin.Totals
for _, e := range events {
// handle deposits
if e.Action == ActionDeposit {
if e.Action == "Deposit" {
totals.Deposits += e.Deposit
totals.DepositFees += e.DepositFee
continue
}

// handle interest
if e.Action == ActionInterest {
if e.Action == "Interest on cash" {
totals.Interest += e.Total
continue
}
Expand Down
4 changes: 2 additions & 2 deletions trading212/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestAggregate(t *testing.T) {
{
name: "Test with a split",
events: []TradeEvent{
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2021, 9, 27, 13, 19, 13, 0, time.UTC)}, TickerSymbol: "ABEC", ShareCount: 0.005, SharePrice: 2000.00, Total: 10.00, ID: "EOF1"},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2022, 9, 27, 13, 19, 13, 0, time.UTC)}, TickerSymbol: "ABEC", ShareCount: 0.125, SharePrice: 80.00, Total: 10.00, ID: "EOF2"},
{Action: "Market buy", Time: DateTime{Time: time.Date(2021, 9, 27, 13, 19, 13, 0, time.UTC)}, TickerSymbol: "ABEC", ShareCount: 0.005, SharePrice: 2000.00, Total: 10.00, ID: "EOF1"},
{Action: "Market buy", Time: DateTime{Time: time.Date(2022, 9, 27, 13, 19, 13, 0, time.UTC)}, TickerSymbol: "ABEC", ShareCount: 0.125, SharePrice: 80.00, Total: 10.00, ID: "EOF2"},
},
want: []fin.Aggregate{
{Symbol: "ABEC", ShareCount: 0.225, AvgPrice: 88.88, ShareCost: 20, ShareCostLocal: 20, ShareResult: 0, TotalDividend: 0, Fees: 0, Final: 0, LastUpdate: time.Date(2022, 9, 27, 13, 19, 13, 0, time.UTC)},
Expand Down
20 changes: 10 additions & 10 deletions trading212/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
// defaultTestDataEvents is a list of TradeEvents that matches testdata/tradign212.csv
// this can be used by several tests
var defaultTestDataEvents = []TradeEvent{
{Action: ActionDeposit, Time: DateTime{Time: time.Date(2021, 8, 9, 15, 25, 29, 0, time.UTC)}, Deposit: 1000, DepositFee: 0, Total: 1000, Notes: "Transaction ID: xxx", ID: "d0ca160f-f407-4b9b-bb36-xxx"},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US30303M1027", TickerSymbol: "FB", TickerName: "Meta Platforms", ShareCount: 0.0863914000, SharePrice: 362, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 26.67, ID: "EOF1", FXFee: 0.04},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US88160R1014", TickerSymbol: "TSLA", TickerName: "Tesla", ShareCount: 0.0766547000, SharePrice: 713.93, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 46.67, ID: "EOF2", FXFee: 0.07},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 288.53, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 66.68, ID: "EOF3", FXFee: 0.10},
{Action: ActionMarketSell, Time: DateTime{Time: time.Date(2021, 8, 30, 13, 30, 3, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 301.14, ShareCurrency: "USD", ExchangeRate: "1.17951", Result: 2.61, Total: 69.09, ID: "EOF4", FXFee: 0.10},
{Action: ActionDeposit, Time: DateTime{Time: time.Date(2021, 9, 7, 13, 43, 10, 0, time.UTC)}, Deposit: 1001.4, DepositFee: 1.40, Total: 1000, Notes: "Transaction ID: xxx", ID: "3e8f5274-1c62-46d6-baf4-xxx"},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2021, 9, 27, 13, 19, 13, 0, time.UTC)}, ISIN: "US02079K1079", TickerSymbol: "ABEC", TickerName: "Google", ShareCount: 0.0041253700, SharePrice: 2424.00, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 10.00, ID: "EOF5"},
{Action: ActionDividend, Time: DateTime{Time: time.Date(2021, 9, 30, 11, 15, 32, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 0.48, ShareCurrency: "USD", ExchangeRate: "Not available", Total: 0.11, Tax: 0.02, TaxCurrency: "USD"},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2022, 3, 7, 16, 10, 26, 0, time.UTC)}, ISIN: "FR0000120578", TickerSymbol: "SAN", TickerName: "Sanofi", ShareCount: 0.1117960000, SharePrice: 89.18, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 10.00, ID: "EOF6", FRFee: 0.03},
{Action: ActionMarketBuy, Time: DateTime{Time: time.Date(2022, 7, 29, 14, 28, 17, 0, time.UTC)}, ISIN: "US02079K1079", TickerSymbol: "ABEC", TickerName: "Alphabet (Class C)", ShareCount: 2.2887315000, SharePrice: 113.60, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 260.00, ID: "EOF7"},
{Action: "Deposit", Time: DateTime{Time: time.Date(2021, 8, 9, 15, 25, 29, 0, time.UTC)}, Deposit: 1000, DepositFee: 0, Total: 1000, Notes: "Transaction ID: xxx", ID: "d0ca160f-f407-4b9b-bb36-xxx"},
{Action: "Market buy", Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US30303M1027", TickerSymbol: "FB", TickerName: "Meta Platforms", ShareCount: 0.0863914000, SharePrice: 362, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 26.67, ID: "EOF1", FXFee: 0.04},
{Action: "Market buy", Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US88160R1014", TickerSymbol: "TSLA", TickerName: "Tesla", ShareCount: 0.0766547000, SharePrice: 713.93, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 46.67, ID: "EOF2", FXFee: 0.07},
{Action: "Market buy", Time: DateTime{Time: time.Date(2021, 8, 9, 18, 31, 41, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 288.53, ShareCurrency: "USD", ExchangeRate: "1.17437", Total: 66.68, ID: "EOF3", FXFee: 0.10},
{Action: "Market sell", Time: DateTime{Time: time.Date(2021, 8, 30, 13, 30, 3, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 301.14, ShareCurrency: "USD", ExchangeRate: "1.17951", Result: 2.61, Total: 69.09, ID: "EOF4", FXFee: 0.10},
{Action: "Deposit", Time: DateTime{Time: time.Date(2021, 9, 7, 13, 43, 10, 0, time.UTC)}, Deposit: 1001.4, DepositFee: 1.40, Total: 1000, Notes: "Transaction ID: xxx", ID: "3e8f5274-1c62-46d6-baf4-xxx"},
{Action: "Market buy", Time: DateTime{Time: time.Date(2021, 9, 27, 13, 19, 13, 0, time.UTC)}, ISIN: "US02079K1079", TickerSymbol: "ABEC", TickerName: "Google", ShareCount: 0.0041253700, SharePrice: 2424.00, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 10.00, ID: "EOF5"},
{Action: "Dividend (Ordinary)", Time: DateTime{Time: time.Date(2021, 9, 30, 11, 15, 32, 0, time.UTC)}, ISIN: "US5949181045", TickerSymbol: "MSFT", TickerName: "Microsoft", ShareCount: 0.2709950000, SharePrice: 0.48, ShareCurrency: "USD", ExchangeRate: "Not available", Total: 0.11, Tax: 0.02, TaxCurrency: "USD"},
{Action: "Market buy", Time: DateTime{Time: time.Date(2022, 3, 7, 16, 10, 26, 0, time.UTC)}, ISIN: "FR0000120578", TickerSymbol: "SAN", TickerName: "Sanofi", ShareCount: 0.1117960000, SharePrice: 89.18, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 10.00, ID: "EOF6", FRFee: 0.03},
{Action: "Market buy", Time: DateTime{Time: time.Date(2022, 7, 29, 14, 28, 17, 0, time.UTC)}, ISIN: "US02079K1079", TickerSymbol: "ABEC", TickerName: "Alphabet (Class C)", ShareCount: 2.2887315000, SharePrice: 113.60, ShareCurrency: "EUR", ExchangeRate: "1.00000", Total: 260.00, ID: "EOF7"},
}

func TestCollect(t *testing.T) {
Expand Down
21 changes: 4 additions & 17 deletions trading212/export.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
package trading212

import (
"strings"
"time"
)

const format = "2006-01-02 15:04:05"

const (
ActionDeposit = "Deposit"
ActionMarketBuy = "Market buy"
ActionMarketSell = "Market sell"
ActionDividend = "Dividend (Ordinary)"
ActionDividendBonus = "Dividend (Bonus)"
ActionDividendROC = "Dividend (Return of capital)"
ActionLimitBuy = "Limit buy"
ActionLimitSell = "Limit sell"
ActionStopBuy = "Stop buy"
ActionStopSell = "Stop sell"
ActionInterest = "Interest on cash"
)

func (e *TradeEvent) IsBuying() bool {
return e.Action == ActionMarketBuy || e.Action == ActionLimitBuy || e.Action == ActionStopBuy
return strings.Contains(e.Action, "buy")
}

func (e *TradeEvent) IsSelling() bool {
return e.Action == ActionMarketSell || e.Action == ActionLimitSell || e.Action == ActionStopSell
return strings.Contains(e.Action, "sell")
}

func (e *TradeEvent) IsDividend() bool {
return e.Action == ActionDividend || e.Action == ActionDividendBonus || e.Action == ActionDividendROC
return strings.Contains(e.Action, "Dividend")
}

func (e *TradeEvent) Fees() float64 {
Expand Down

0 comments on commit 9c92724

Please sign in to comment.