renamed direction to side

This commit is contained in:
2025-11-10 14:04:18 +00:00
parent 4686e36501
commit dca43fe014
7 changed files with 102 additions and 102 deletions

View File

@@ -13,7 +13,7 @@ import (
type Record struct {
symbol string
direction internal.Direction
side internal.Side
quantity *big.Float
price *big.Float
timestamp time.Time
@@ -23,8 +23,8 @@ func (r Record) Symbol() string {
return r.symbol
}
func (r Record) Direction() internal.Direction {
return r.direction
func (r Record) Side() internal.Side {
return r.side
}
func (r Record) Quantity() *big.Float {
@@ -63,12 +63,12 @@ func (rr RecordReader) ReadRecord() (Record, error) {
return Record{}, fmt.Errorf("read record: %w", err)
}
var dir internal.Direction
var side internal.Side
switch strings.ToLower(raw[0]) {
case MarketBuy, LimitBuy:
dir = internal.DirectionBuy
side = internal.SideBuy
case MarketSell, LimitSell:
dir = internal.DirectionSell
side = internal.SideSell
case "action", "stock split open", "stock split close":
continue
default:
@@ -92,7 +92,7 @@ func (rr RecordReader) ReadRecord() (Record, error) {
return Record{
symbol: raw[2],
direction: dir,
side: side,
quantity: qant,
price: price,
timestamp: ts,

View File

@@ -28,7 +28,7 @@ func TestRecordReader_ReadRecord(t *testing.T) {
r: bytes.NewBufferString(`Market buy,2025-07-03 10:44:29,SYM123456ABXY,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.3690000000,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
want: Record{
symbol: "SYM123456ABXY",
direction: internal.DirectionBuy,
side: internal.SideBuy,
quantity: ShouldParseDecimal(t, "2.4387014200"),
price: ShouldParseDecimal(t, "7.3690000000"),
timestamp: time.Date(2025, 7, 3, 10, 44, 29, 0, time.UTC),
@@ -40,7 +40,7 @@ func TestRecordReader_ReadRecord(t *testing.T) {
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:30,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
want: Record{
symbol: "IE000GA3D489",
direction: internal.DirectionSell,
side: internal.SideSell,
quantity: ShouldParseDecimal(t, "2.4387014200"),
price: ShouldParseDecimal(t, "7.9999999999"),
timestamp: time.Date(2025, 8, 4, 11, 45, 30, 0, time.UTC),
@@ -48,13 +48,13 @@ func TestRecordReader_ReadRecord(t *testing.T) {
wantErr: false,
},
{
name: "malformed direction",
name: "malformed side",
r: bytes.NewBufferString(`Aljksdaf Balsjdkf,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
want: Record{},
wantErr: true,
},
{
name: "empty direction",
name: "empty side",
r: bytes.NewBufferString(`,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,0x1234,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
want: Record{},
wantErr: true,
@@ -115,8 +115,8 @@ func TestRecordReader_ReadRecord(t *testing.T) {
t.Fatalf("want symbol %v but got %v", tt.want.symbol, got.symbol)
}
if got.direction != tt.want.direction {
t.Fatalf("want direction %v but got %v", tt.want.direction, got.direction)
if got.side != tt.want.side {
t.Fatalf("want side %v but got %v", tt.want.side, got.side)
}
if got.price.Cmp(tt.want.price) != 0 {