add new Nature method to Record interface

This commit is contained in:
2025-11-20 19:26:08 +00:00
parent 1106705eb2
commit b4b12ad625
4 changed files with 104 additions and 0 deletions

View File

@@ -220,6 +220,44 @@ func (c *MockRecordFeesCall) DoAndReturn(f func() decimal.Decimal) *MockRecordFe
return c return c
} }
// Nature mocks base method.
func (m *MockRecord) Nature() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Nature")
ret0, _ := ret[0].(string)
return ret0
}
// Nature indicates an expected call of Nature.
func (mr *MockRecordMockRecorder) Nature() *MockRecordNatureCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nature", reflect.TypeOf((*MockRecord)(nil).Nature))
return &MockRecordNatureCall{Call: call}
}
// MockRecordNatureCall wrap *gomock.Call
type MockRecordNatureCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockRecordNatureCall) Return(arg0 string) *MockRecordNatureCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockRecordNatureCall) Do(f func() string) *MockRecordNatureCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockRecordNatureCall) DoAndReturn(f func() string) *MockRecordNatureCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// Price mocks base method. // Price mocks base method.
func (m *MockRecord) Price() decimal.Decimal { func (m *MockRecord) Price() decimal.Decimal {
m.ctrl.T.Helper() m.ctrl.T.Helper()

60
internal/open_figi.go Normal file
View File

@@ -0,0 +1,60 @@
package internal
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type OpenFIGI struct {
client http.Client
cache map[string]string
}
func NewOpenFIGI() *OpenFIGI {
return &OpenFIGI{
client: http.Client{
Timeout: 5 * time.Second,
},
}
}
func (of *OpenFIGI) Category(ctx context.Context, isin, ticker string) (string, error) {
rawBody, err := json.Marshal(mappingRequestBody{
IdType: "ID_ISIN",
IdValue: isin,
})
if err != nil {
return "", fmt.Errorf("marshal mapping request body: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.openfigi.com/v3/mapping", bytes.NewBuffer(rawBody))
if err != nil {
return "", fmt.Errorf("create mapping request: %w", err)
}
res, err := of.client.Do(req)
if err != nil {
return "", fmt.Errorf("make mapping request: %w", err)
}
defer res.Body.Close()
var resBody mappingResponseBody
err = json.NewDecoder(res.Body).Decode(&resBody)
if err != nil {
return "", fmt.Errorf("unmarshal response: %w", err)
}
return "", nil
}
type mappingRequestBody struct {
IdType string `json:"idType"`
IdValue string `json:"idValue"`
}
type mappingResponseBody struct{}

View File

@@ -12,6 +12,7 @@ import (
type Record interface { type Record interface {
Symbol() string Symbol() string
Nature() string
BrokerCountry() int64 BrokerCountry() int64
AssetCountry() int64 AssetCountry() int64
Side() Side Side() Side
@@ -29,6 +30,7 @@ type RecordReader interface {
type ReportItem struct { type ReportItem struct {
Symbol string Symbol string
Nature string
BrokerCountry int64 BrokerCountry int64
AssetCountry int64 AssetCountry int64
BuyValue decimal.Decimal BuyValue decimal.Decimal

View File

@@ -27,6 +27,10 @@ func (r Record) Symbol() string {
return r.symbol return r.symbol
} }
func (r Record) Nature() string {
return "" // TODO: implement this
}
func (r Record) BrokerCountry() int64 { func (r Record) BrokerCountry() int64 {
return int64(Country) return int64(Country)
} }