Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function GetPublicCompanies always throws the error index out of range [1] with length 1 #3

Open
ParthaI opened this issue Aug 16, 2023 · 1 comment

Comments

@ParthaI
Copy link

ParthaI commented Aug 16, 2023

Dear Team,

I was trying to list of all US public companies registered with the US Securities and Exchange Commission. We aimed to achieve this by using the API GetPublicCompanies API. Regrettably, this approach has consistently resulted in errors during our attempts.

Furthermore, I have made an attempt to troubleshoot the code locally by implementing certain modifications. Unfortunately, these adjustments did not yield the desired successful execution.

import (
	"context"
	"encoding/csv"
	"fmt"
	"net/http"

	"github.com/piquette/edgr/core"
)

func main() {
      headers :=  map[string]string{"User-Agent": "Steampipe/v0.x"}
	req, err := http.NewRequest("GET", "https://api.iextrading.com/1.0/ref-data/symbols?format=csv", nil)
	if err != nil {
		return []core.Company{}, err
	}

	for k, v := range headers {
		req.Header.Set(k, v)
	}

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return []core.Company{}, err
	}
	defer resp.Body.Close()

	r := csv.NewReader(resp.Body)
	r.FieldsPerRecord = -1
	table, _ := r.ReadAll()
	result := []core.Company{}
	for _, row := range table {
		if len(row) < 2 {
			fmt.Sprint("ROW =====>>>>>", row)
			continue
		}
		sym := row[0]
		nme := row[1]
		if len(sym) > 5 || nme == "" {
			continue
		}
		result = append(result, core.Company{
			Symbol: sym,
			Name:   nme,
		})
	}
}

Could you please check it out and let us know I am doing anything wrong or it is a bug from SDK side?

Thanks!

@ParthaI
Copy link
Author

ParthaI commented Nov 16, 2023

Dear team, Is there any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant