This commit is contained in:
@@ -17,6 +17,8 @@ type Record struct {
|
|||||||
quantity *big.Float
|
quantity *big.Float
|
||||||
price *big.Float
|
price *big.Float
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
|
fees *big.Float
|
||||||
|
taxes *big.Float
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Record) Symbol() string {
|
func (r Record) Symbol() string {
|
||||||
@@ -40,11 +42,11 @@ func (r Record) Timestamp() time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Record) Fees() *big.Float {
|
func (r Record) Fees() *big.Float {
|
||||||
return new(big.Float) // FIX:
|
return r.fees
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Record) Taxes() *big.Float {
|
func (r Record) Taxes() *big.Float {
|
||||||
return new(big.Float) // FIX:
|
return r.taxes
|
||||||
}
|
}
|
||||||
|
|
||||||
type RecordReader struct {
|
type RecordReader struct {
|
||||||
@@ -98,12 +100,29 @@ func (rr RecordReader) ReadRecord() (internal.Record, error) {
|
|||||||
return Record{}, fmt.Errorf("parse record timestamp: %w", err)
|
return Record{}, fmt.Errorf("parse record timestamp: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertionFee, err := parseOptinalDecimal(raw[16])
|
||||||
|
if err != nil {
|
||||||
|
return Record{}, fmt.Errorf("parse record convertion fee: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stampDutyTax, err := parseOptinalDecimal(raw[14])
|
||||||
|
if err != nil {
|
||||||
|
return Record{}, fmt.Errorf("parse record stamp duty tax: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
frenchTxTax, err := parseOptinalDecimal(raw[18])
|
||||||
|
if err != nil {
|
||||||
|
return Record{}, fmt.Errorf("parse record french transaction tax: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return Record{
|
return Record{
|
||||||
symbol: raw[2],
|
symbol: raw[2],
|
||||||
side: side,
|
side: side,
|
||||||
quantity: qant,
|
quantity: qant,
|
||||||
price: price,
|
price: price,
|
||||||
timestamp: ts,
|
timestamp: ts,
|
||||||
|
fees: convertionFee,
|
||||||
|
taxes: new(big.Float).Add(stampDutyTax, frenchTxTax),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,3 +133,14 @@ func parseDecimal(s string) (*big.Float, error) {
|
|||||||
f, _, err := big.ParseFloat(s, 10, 128, big.ToZero)
|
f, _, err := big.ParseFloat(s, 10, 128, big.ToZero)
|
||||||
return f, err
|
return f, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseOptinalDecimal behaves the same as parseDecimal but returns 0 when len(s) is 0 instead of
|
||||||
|
// error.
|
||||||
|
// Using this function helps avoid issues around converting values due to sligh parameter changes.
|
||||||
|
func parseOptinalDecimal(s string) (*big.Float, error) {
|
||||||
|
if len(s) == 0 {
|
||||||
|
return new(big.Float), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseDecimal(s)
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,75 +24,69 @@ func TestRecordReader_ReadRecord(t *testing.T) {
|
|||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "well formed buy",
|
name: "well-formed buy",
|
||||||
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",,`),
|
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.25,"EUR",0.02,"EUR",,`),
|
||||||
want: Record{
|
want: Record{
|
||||||
symbol: "SYM123456ABXY",
|
symbol: "SYM123456ABXY",
|
||||||
side: internal.SideBuy,
|
side: internal.SideBuy,
|
||||||
quantity: ShouldParseDecimal(t, "2.4387014200"),
|
quantity: ShouldParseDecimal(t, "2.4387014200"),
|
||||||
price: ShouldParseDecimal(t, "7.3690000000"),
|
price: ShouldParseDecimal(t, "7.3690000000"),
|
||||||
timestamp: time.Date(2025, 7, 3, 10, 44, 29, 0, time.UTC),
|
timestamp: time.Date(2025, 7, 3, 10, 44, 29, 0, time.UTC),
|
||||||
|
fees: ShouldParseDecimal(t, "0.02"),
|
||||||
|
taxes: ShouldParseDecimal(t, "0.25"),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "well formed sell",
|
name: "well-formed sell",
|
||||||
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",,`),
|
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",0.1,"EUR"`),
|
||||||
want: Record{
|
want: Record{
|
||||||
symbol: "IE000GA3D489",
|
symbol: "IE000GA3D489",
|
||||||
side: internal.SideSell,
|
side: internal.SideSell,
|
||||||
quantity: ShouldParseDecimal(t, "2.4387014200"),
|
quantity: ShouldParseDecimal(t, "2.4387014200"),
|
||||||
price: ShouldParseDecimal(t, "7.9999999999"),
|
price: ShouldParseDecimal(t, "7.9999999999"),
|
||||||
timestamp: time.Date(2025, 8, 4, 11, 45, 30, 0, time.UTC),
|
timestamp: time.Date(2025, 8, 4, 11, 45, 30, 0, time.UTC),
|
||||||
|
fees: ShouldParseDecimal(t, "0.02"),
|
||||||
|
taxes: ShouldParseDecimal(t, "0.1"),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed side",
|
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",,`),
|
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,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty side",
|
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",,`),
|
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,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed qantity",
|
name: "malformed qantity",
|
||||||
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,0x1234,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,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,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty qantity",
|
name: "empty qantity",
|
||||||
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
||||||
want: Record{},
|
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed price",
|
name: "malformed price",
|
||||||
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,0b101010,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,0b101010,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
||||||
want: Record{},
|
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty price",
|
name: "empty price",
|
||||||
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,2025-08-04 11:45:39,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
||||||
want: Record{},
|
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed timestamp",
|
name: "malformed timestamp",
|
||||||
r: bytes.NewBufferString(`Market sell,2006-01-02T15:04:05Z07:00,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,2006-01-02T15:04:05Z07:00,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
||||||
want: Record{},
|
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty timestamp",
|
name: "empty timestamp",
|
||||||
r: bytes.NewBufferString(`Market sell,,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
r: bytes.NewBufferString(`Market sell,,IE000GA3D489,ABXY,"Aspargus Brocoli",EOF987654321,2.4387014200,7.9999999999,USD,1.17995999,,"EUR",15.25,"EUR",,,0.02,"EUR",,`),
|
||||||
want: Record{},
|
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -130,6 +124,14 @@ func TestRecordReader_ReadRecord(t *testing.T) {
|
|||||||
if !got.Timestamp().Equal(tt.want.timestamp) {
|
if !got.Timestamp().Equal(tt.want.timestamp) {
|
||||||
t.Fatalf("want timestamp %v but got %v", tt.want.timestamp, got.Timestamp())
|
t.Fatalf("want timestamp %v but got %v", tt.want.timestamp, got.Timestamp())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if got.Fees().Cmp(tt.want.fees) != 0 {
|
||||||
|
t.Fatalf("want fees %v but got %v", tt.want.fees, got.Fees())
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.Taxes().Cmp(tt.want.taxes) != 0 {
|
||||||
|
t.Fatalf("want taxes %v but got %v", tt.want.taxes, got.Taxes())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user