这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@ParthaI

Description

@ParthaI

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions