rename side to kind

This commit is contained in:
2026-05-16 14:21:14 +01:00
parent d371aca767
commit 5cdccfcdb1
9 changed files with 146 additions and 142 deletions

View File

@@ -18,7 +18,7 @@ import (
type Record struct {
symbol string
timestamp time.Time
side internal.Side
side internal.Kind
quantity decimal.Decimal
price decimal.Decimal
fees decimal.Decimal
@@ -44,7 +44,7 @@ func (r Record) AssetCountry() int64 {
return int64(countries.ByName(r.Symbol()[:2]).Info().Code)
}
func (r Record) Side() internal.Side {
func (r Record) Kind() internal.Kind {
return r.side
}
@@ -81,10 +81,12 @@ func NewRecordReader(r io.Reader, f *internal.OpenFIGI) *RecordReader {
}
const (
MarketBuy = "market buy"
MarketSell = "market sell"
LimitBuy = "limit buy"
LimitSell = "limit sell"
MarketBuy = "market buy"
MarketSell = "market sell"
LimitBuy = "limit buy"
LimitSell = "limit sell"
StockSplitOpen = "Stock split open"
StockSplitClose = "Stock split close"
)
func (rr RecordReader) ReadRecord(ctx context.Context) (internal.Record, error) {
@@ -94,13 +96,16 @@ func (rr RecordReader) ReadRecord(ctx context.Context) (internal.Record, error)
return Record{}, fmt.Errorf("read record: %w", err)
}
var side internal.Side
var side internal.Kind
switch strings.ToLower(raw[0]) {
case MarketBuy, LimitBuy:
side = internal.SideBuy
side = internal.KindBuy
case MarketSell, LimitSell:
side = internal.SideSell
case "action", "stock split open", "stock split close":
side = internal.KindSell
case StockSplitOpen, StockSplitClose:
// TODO: emit a special event that triggers a readjustment of unsold stock
continue
case "action": // TODO: this is the header, there's probably a better way to handle this
continue
default:
return Record{}, fmt.Errorf("parse record type: %s", raw[0])

View File

@@ -30,7 +30,7 @@ func TestRecordReader_ReadRecord(t *testing.T) {
r: bytes.NewBufferString(`Market buy,2025-07-03 10:44:29,XX1234567890,ABXY,"Aspargus Broccoli",EOF987654321,2.4387014200,7.3690000000,USD,1.17995999,,"EUR",15.25,"EUR",0.25,"EUR",0.02,"EUR",,`),
want: Record{
symbol: "XX1234567890",
side: internal.SideBuy,
side: internal.KindBuy,
quantity: ShouldParseDecimal(t, "2.4387014200"),
price: ShouldParseDecimal(t, "7.3690000000"),
timestamp: time.Date(2025, 7, 3, 10, 44, 29, 0, time.UTC),
@@ -44,7 +44,7 @@ func TestRecordReader_ReadRecord(t *testing.T) {
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:30,XX1234567890,ABXY,"Aspargus Broccoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",0.1,"EUR"`),
want: Record{
symbol: "XX1234567890",
side: internal.SideSell,
side: internal.KindSell,
quantity: ShouldParseDecimal(t, "2.4387014200"),
price: ShouldParseDecimal(t, "7.9999999999"),
timestamp: time.Date(2025, 8, 4, 11, 45, 30, 0, time.UTC),
@@ -123,8 +123,8 @@ func TestRecordReader_ReadRecord(t *testing.T) {
t.Fatalf("want symbol %v but got %v", tt.want.symbol, got.Symbol())
}
if got.Side() != tt.want.side {
t.Fatalf("want side %v but got %v", tt.want.side, got.Side())
if got.Kind() != tt.want.side {
t.Fatalf("want side %v but got %v", tt.want.side, got.Kind())
}
if got.Price().Cmp(tt.want.price) != 0 {