renamed direction to side
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package internal
|
||||
|
||||
type Direction uint
|
||||
|
||||
const (
|
||||
DirectionUnknown Direction = 0
|
||||
DirectionBuy Direction = 1
|
||||
DirectionSell Direction = 2
|
||||
)
|
||||
|
||||
func (d Direction) String() string {
|
||||
switch d {
|
||||
case 1:
|
||||
return "buy"
|
||||
case 2:
|
||||
return "sell"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func (d Direction) IsBuy() bool {
|
||||
return d == DirectionBuy
|
||||
}
|
||||
|
||||
func (d Direction) IsSell() bool {
|
||||
return d == DirectionSell
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package internal
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDirection_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
d Direction
|
||||
want string
|
||||
}{
|
||||
{"buy", DirectionBuy, "buy"},
|
||||
{"sell", DirectionSell, "sell"},
|
||||
{"unknown", DirectionUnknown, "unknown"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.d.String(); got != tt.want {
|
||||
t.Errorf("want Direction.String() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirection_IsBuy(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
d Direction
|
||||
want bool
|
||||
}{
|
||||
{"buy", DirectionBuy, true},
|
||||
{"sell", DirectionSell, false},
|
||||
{"unknown", DirectionUnknown, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.d.IsBuy(); got != tt.want {
|
||||
t.Errorf("want Direction.IsBuy() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirection_IsSell(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
d Direction
|
||||
want bool
|
||||
}{
|
||||
{"buy", DirectionBuy, false},
|
||||
{"sell", DirectionSell, true},
|
||||
{"unknown", DirectionUnknown, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.d.IsSell(); got != tt.want {
|
||||
t.Errorf("want Direction.IsSell() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ type Record interface {
|
||||
Symbol() string
|
||||
Price() *big.Float
|
||||
Quantity() *big.Float
|
||||
Direction() Direction
|
||||
Side() Side
|
||||
Timestamp() time.Time
|
||||
}
|
||||
|
||||
|
||||
28
internal/side.go
Normal file
28
internal/side.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package internal
|
||||
|
||||
type Side uint
|
||||
|
||||
const (
|
||||
SideUnknown Side = iota
|
||||
SideBuy
|
||||
SideSell
|
||||
)
|
||||
|
||||
func (d Side) String() string {
|
||||
switch d {
|
||||
case SideBuy:
|
||||
return "buy"
|
||||
case SideSell:
|
||||
return "sell"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func (d Side) IsBuy() bool {
|
||||
return d == SideBuy
|
||||
}
|
||||
|
||||
func (d Side) IsSell() bool {
|
||||
return d == SideSell
|
||||
}
|
||||
60
internal/side_test.go
Normal file
60
internal/side_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package internal
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSide_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
side Side
|
||||
want string
|
||||
}{
|
||||
{"buy", SideBuy, "buy"},
|
||||
{"sell", SideSell, "sell"},
|
||||
{"unknown", SideUnknown, "unknown"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.side.String(); got != tt.want {
|
||||
t.Errorf("want Side.String() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSide_IsBuy(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
side Side
|
||||
want bool
|
||||
}{
|
||||
{"buy", SideBuy, true},
|
||||
{"sell", SideSell, false},
|
||||
{"unknown", SideUnknown, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.side.IsBuy(); got != tt.want {
|
||||
t.Errorf("want Side.IsBuy() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSide_IsSell(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
side Side
|
||||
want bool
|
||||
}{
|
||||
{"buy", SideBuy, false},
|
||||
{"sell", SideSell, true},
|
||||
{"unknown", SideUnknown, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.side.IsSell(); got != tt.want {
|
||||
t.Errorf("want Side.IsSell() to be %v but got %v", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user