Report includes the type/nature of row #17
@@ -220,6 +220,44 @@ func (c *MockRecordFeesCall) DoAndReturn(f func() decimal.Decimal) *MockRecordFe
|
||||
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.
|
||||
func (m *MockRecord) Price() decimal.Decimal {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
60
internal/open_figi.go
Normal file
60
internal/open_figi.go
Normal 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{}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
type Record interface {
|
||||
Symbol() string
|
||||
Nature() string
|
||||
BrokerCountry() int64
|
||||
AssetCountry() int64
|
||||
Side() Side
|
||||
@@ -29,6 +30,7 @@ type RecordReader interface {
|
||||
|
||||
type ReportItem struct {
|
||||
Symbol string
|
||||
Nature string
|
||||
BrokerCountry int64
|
||||
AssetCountry int64
|
||||
BuyValue decimal.Decimal
|
||||
|
||||
@@ -27,6 +27,10 @@ func (r Record) Symbol() string {
|
||||
return r.symbol
|
||||
}
|
||||
|
||||
func (r Record) Nature() string {
|
||||
return "" // TODO: implement this
|
||||
}
|
||||
|
||||
func (r Record) BrokerCountry() int64 {
|
||||
return int64(Country)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user