This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglief.go
189 lines (181 loc) · 6.15 KB
/
glief.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package glieflookup
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
validations "github.com/robfordww/finident"
)
type GLIEF struct {
Meta struct {
GoldenCopy struct {
PublishDate time.Time `json:"publishDate"`
} `json:"goldenCopy"`
Pagination struct {
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
From int `json:"from"`
To int `json:"to"`
Total int `json:"total"`
LastPage int `json:"lastPage"`
} `json:"pagination"`
} `json:"meta"`
Links struct {
First string `json:"first"`
Last string `json:"last"`
} `json:"links"`
Data []struct {
Type string `json:"type"`
ID string `json:"id"`
Attributes struct {
Lei string `json:"lei"`
Entity struct {
LegalName struct {
Name string `json:"name"`
Language string `json:"language"`
} `json:"legalName"`
OtherNames []interface{} `json:"otherNames"`
TransliteratedOtherNames []interface{} `json:"transliteratedOtherNames"`
LegalAddress struct {
Language string `json:"language"`
AddressLines []string `json:"addressLines"`
AddressNumber interface{} `json:"addressNumber"`
AddressNumberWithinBuilding interface{} `json:"addressNumberWithinBuilding"`
MailRouting interface{} `json:"mailRouting"`
City string `json:"city"`
Region string `json:"region"`
Country string `json:"country"`
PostalCode string `json:"postalCode"`
} `json:"legalAddress"`
HeadquartersAddress struct {
Language string `json:"language"`
AddressLines []string `json:"addressLines"`
AddressNumber interface{} `json:"addressNumber"`
AddressNumberWithinBuilding interface{} `json:"addressNumberWithinBuilding"`
MailRouting interface{} `json:"mailRouting"`
City string `json:"city"`
Region string `json:"region"`
Country string `json:"country"`
PostalCode string `json:"postalCode"`
} `json:"headquartersAddress"`
RegisteredAt struct {
ID string `json:"id"`
Other interface{} `json:"other"`
} `json:"registeredAt"`
RegisteredAs interface{} `json:"registeredAs"`
Jurisdiction string `json:"jurisdiction"`
Category interface{} `json:"category"`
LegalForm struct {
ID string `json:"id"`
Other string `json:"other"`
} `json:"legalForm"`
AssociatedEntity struct {
Lei interface{} `json:"lei"`
Name interface{} `json:"name"`
} `json:"associatedEntity"`
Status string `json:"status"`
Expiration struct {
Date interface{} `json:"date"`
Reason interface{} `json:"reason"`
} `json:"expiration"`
SuccessorEntity struct {
Lei interface{} `json:"lei"`
Name interface{} `json:"name"`
} `json:"successorEntity"`
OtherAddresses []interface{} `json:"otherAddresses"`
} `json:"entity"`
Registration struct {
InitialRegistrationDate time.Time `json:"initialRegistrationDate"`
LastUpdateDate time.Time `json:"lastUpdateDate"`
Status string `json:"status"`
NextRenewalDate time.Time `json:"nextRenewalDate"`
ManagingLou string `json:"managingLou"`
CorroborationLevel string `json:"corroborationLevel"`
ValidatedAt struct {
ID string `json:"id"`
Other interface{} `json:"other"`
} `json:"validatedAt"`
ValidatedAs interface{} `json:"validatedAs"`
OtherValidationAuthorities []interface{} `json:"otherValidationAuthorities"`
} `json:"registration"`
Bic interface{} `json:"bic"`
} `json:"attributes"`
Relationships struct {
ManagingLou struct {
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"managing-lou"`
LeiIssuer struct {
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"lei-issuer"`
FieldModifications struct {
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"field-modifications"`
DirectParent struct {
Links struct {
ReportingException string `json:"reporting-exception"`
} `json:"links"`
} `json:"direct-parent"`
UltimateParent struct {
Links struct {
ReportingException string `json:"reporting-exception"`
} `json:"links"`
} `json:"ultimate-parent"`
DirectChildren struct {
Links struct {
RelationshipRecords string `json:"relationship-records"`
Related string `json:"related"`
} `json:"links"`
} `json:"direct-children"`
UltimateChildren struct {
Links struct {
RelationshipRecords string `json:"relationship-records"`
Related string `json:"related"`
} `json:"links"`
} `json:"ultimate-children"`
Isins struct {
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"isins"`
} `json:"relationships"`
Links struct {
Self string `json:"self"`
} `json:"links"`
} `json:"data"`
}
var gliefAPIURI = "https://api.gleif.org/api/v1/lei-records?filter[isin]=%v"
func lookup_LEI(inISIN string) (string, error) {
var e error
isinOK, err := validations.ValidateISIN(inISIN)
if err == nil {
//log.Printf("%q is Valid %v", inISIN, isinOK)
if isinOK {
uri := fmt.Sprintf(gliefAPIURI, inISIN)
//log.Printf("URI=[%q]", uri)
resp, err := http.Get(uri)
if err != nil {
fmt.Println("No response from request")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) // response body is []byte
//fmt.Println(string(body))
var result GLIEF
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to go struct pointer
fmt.Println("Can not unmarshal JSON")
}
//fmt.Printf("result: %v\n", result)
//spew.Dump(result)
return result.Data[0].Attributes.Lei, nil
}
} else {
return "", err
}
return "", e
}