report show nature
Some checks failed
Generate check / check-changes (push) Successful in 4s
Generate check / check-generate (push) Has been skipped
Generate check / check-changes (pull_request) Successful in 4s
Quality / check-changes (pull_request) Successful in 3s
Generate check / check-generate (pull_request) Successful in 28s
Quality / tests (pull_request) Failing after 41s

This commit is contained in:
2025-11-24 16:03:28 +00:00
parent 8c784f3b74
commit c323047175
6 changed files with 155 additions and 32 deletions

View File

@@ -5,7 +5,9 @@ import (
"encoding/csv"
"fmt"
"io"
"log/slog"
"strings"
"sync"
"time"
"github.com/biter777/countries"
@@ -68,11 +70,13 @@ func (r Record) Nature() internal.Nature {
type RecordReader struct {
reader *csv.Reader
figi *internal.OpenFIGI
}
func NewRecordReader(r io.Reader) *RecordReader {
func NewRecordReader(r io.Reader, f *internal.OpenFIGI) *RecordReader {
return &RecordReader{
reader: csv.NewReader(r),
figi: f,
}
}
@@ -83,7 +87,7 @@ const (
LimitSell = "limit sell"
)
func (rr RecordReader) ReadRecord(_ context.Context) (internal.Record, error) {
func (rr RecordReader) ReadRecord(ctx context.Context) (internal.Record, error) {
for {
raw, err := rr.reader.Read()
if err != nil {
@@ -133,17 +137,38 @@ func (rr RecordReader) ReadRecord(_ context.Context) (internal.Record, error) {
}
return Record{
symbol: raw[2],
side: side,
quantity: qant,
price: price,
fees: conversionFee,
taxes: stampDutyTax.Add(frenchTxTax),
timestamp: ts,
symbol: raw[2],
side: side,
quantity: qant,
price: price,
fees: conversionFee,
taxes: stampDutyTax.Add(frenchTxTax),
timestamp: ts,
natureGetter: figiNatureGetter(ctx, rr.figi, raw[2]),
}, nil
}
}
func figiNatureGetter(ctx context.Context, of *internal.OpenFIGI, isin string) func() internal.Nature {
return sync.OnceValue(func() internal.Nature {
secType, err := of.SecurityTypeByISIN(ctx, isin)
if err != nil {
slog.Error("failed to get security type by ISIN", slog.Any("err", err), slog.String("isin", isin))
return internal.NatureUnknown
}
switch secType {
case "Common Stock":
return internal.NatureG01
case "ETP":
return internal.NatureG20
default:
slog.Error("got unsupported security type for ISIN", slog.String("isin", isin), slog.String("securityType", secType))
return internal.NatureUnknown
}
})
}
// 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.
func parseDecimal(s string) (decimal.Decimal, error) {