Compare commits
2 Commits
93f1dab3d2
...
70466b7886
| Author | SHA1 | Date | |
|---|---|---|---|
| 70466b7886 | |||
| bd101ce46a |
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/nmoniz/any2anexoj/internal"
|
"github.com/nmoniz/any2anexoj/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNature_StringUnknow(t *testing.T) {
|
func TestNature_String(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
nature internal.Nature
|
nature internal.Nature
|
||||||
@@ -17,12 +17,12 @@ func TestNature_StringUnknow(t *testing.T) {
|
|||||||
want: "unknown",
|
want: "unknown",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "return unknown",
|
name: "return G01",
|
||||||
nature: internal.NatureG01,
|
nature: internal.NatureG01,
|
||||||
want: "G01",
|
want: "G01",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "return unknown",
|
name: "return G20",
|
||||||
nature: internal.NatureG20,
|
nature: internal.NatureG20,
|
||||||
want: "G20",
|
want: "G20",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestOpenFIGI_SecurityTypeByISIN(t *testing.T) {
|
|||||||
want: "Common Stock",
|
want: "Common Stock",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bas status code",
|
name: "bad status code",
|
||||||
client: NewTestClient(t, func(req *http.Request) (*http.Response, error) {
|
client: NewTestClient(t, func(req *http.Request) (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
Status: http.StatusText(http.StatusTooManyRequests),
|
Status: http.StatusText(http.StatusTooManyRequests),
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func processRecord(ctx context.Context, q *FillerQueue, rec Record, writer Repor
|
|||||||
SellValue: sellValue,
|
SellValue: sellValue,
|
||||||
SellTimestamp: rec.Timestamp(),
|
SellTimestamp: rec.Timestamp(),
|
||||||
Fees: buy.Fees().Add(rec.Fees()),
|
Fees: buy.Fees().Add(rec.Fees()),
|
||||||
Taxes: buy.Taxes().Add(rec.Fees()),
|
Taxes: buy.Taxes().Add(rec.Taxes()),
|
||||||
Nature: buy.Nature(),
|
Nature: buy.Nature(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -121,17 +121,17 @@ func (rr RecordReader) ReadRecord(ctx context.Context) (internal.Record, error)
|
|||||||
return Record{}, fmt.Errorf("parse record timestamp: %w", err)
|
return Record{}, fmt.Errorf("parse record timestamp: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conversionFee, err := parseOptinalDecimal(raw[16])
|
conversionFee, err := parseOptionalDecimal(raw[16])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Record{}, fmt.Errorf("parse record conversion fee: %w", err)
|
return Record{}, fmt.Errorf("parse record conversion fee: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stampDutyTax, err := parseOptinalDecimal(raw[14])
|
stampDutyTax, err := parseOptionalDecimal(raw[14])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Record{}, fmt.Errorf("parse record stamp duty tax: %w", err)
|
return Record{}, fmt.Errorf("parse record stamp duty tax: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
frenchTxTax, err := parseOptinalDecimal(raw[18])
|
frenchTxTax, err := parseOptionalDecimal(raw[18])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Record{}, fmt.Errorf("parse record french transaction tax: %w", err)
|
return Record{}, fmt.Errorf("parse record french transaction tax: %w", err)
|
||||||
}
|
}
|
||||||
@@ -170,15 +170,15 @@ func figiNatureGetter(ctx context.Context, of *internal.OpenFIGI, isin string) f
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseFloat attempts to parse a string using a standard precision and rounding mode.
|
// parseFloat attempts to parse a string using a standard precision and rounding mode.
|
||||||
// Using this function helps avoid issues around converting values due to sligh parameter changes.
|
// Using this function helps avoid issues around converting values due to minor parameter changes.
|
||||||
func parseDecimal(s string) (decimal.Decimal, error) {
|
func parseDecimal(s string) (decimal.Decimal, error) {
|
||||||
return decimal.NewFromString(s)
|
return decimal.NewFromString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseOptinalDecimal behaves the same as parseDecimal but returns 0 when len(s) is 0 instead of
|
// parseOptionalDecimal behaves the same as parseDecimal but returns 0 when len(s) is 0 instead of
|
||||||
// error.
|
// error.
|
||||||
// Using this function helps avoid issues around converting values due to sligh parameter changes.
|
// Using this function helps avoid issues around converting values due to minor parameter changes.
|
||||||
func parseOptinalDecimal(s string) (decimal.Decimal, error) {
|
func parseOptionalDecimal(s string) (decimal.Decimal, error) {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return decimal.Decimal{}, nil
|
return decimal.Decimal{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user