edgr icon indicating copy to clipboard operation
edgr copied to clipboard

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

Open ParthaI opened this issue 2 years ago • 1 comments

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 avatar Aug 16 '23 10:08 ParthaI

Dear team, Is there any update on this issue?

ParthaI avatar Nov 16 '23 10:11 ParthaI