diff --git a/README.md b/README.md index 5789e76..f158231 100644 --- a/README.md +++ b/README.md @@ -616,7 +616,7 @@ Frequently asked questions: - A: The default configuration file is located under `~/.config/cointop/config.toml` - Note: Previous version of cointop used `~/.cointop/config` or `~/.cointop/config.toml` as the default config filepath. Cointop will use those config filepaths respectively if they exist. + Note: Previous versions of cointop used `~/.cointop/config` or `~/.cointop/config.toml` as the default config filepath. Cointop will use those config filepaths respectively if they exist. - Q: What format is the configuration file in? diff --git a/cointop/common/api/impl/coingecko/coingecko.go b/cointop/common/api/impl/coingecko/coingecko.go index e8b3f83..0ae41ca 100644 --- a/cointop/common/api/impl/coingecko/coingecko.go +++ b/cointop/common/api/impl/coingecko/coingecko.go @@ -21,14 +21,18 @@ var ErrNotFound = errors.New("Not found") // Service service type Service struct { - client *gecko.Client + client *gecko.Client + maxResultsPerPage int + maxPages int } // NewCoinGecko new service func NewCoinGecko() *Service { client := gecko.NewClient(nil) return &Service{ - client: client, + client: client, + maxResultsPerPage: 250, + maxPages: 20, } } @@ -44,7 +48,6 @@ func (s *Service) Ping() error { func (s *Service) getLimitedCoinData(convert string, offset int) ([]apitypes.Coin, error) { var ret []apitypes.Coin ids := []string{} - perPage := 250 page := offset sparkline := false pcp := geckoTypes.PriceChangePercentageObject @@ -54,7 +57,7 @@ func (s *Service) getLimitedCoinData(convert string, offset int) ([]apitypes.Coi if convertTo == "" { convertTo = "usd" } - list, err := s.client.CoinsMarket(convertTo, ids, order, perPage, page, sparkline, priceChangePercentage) + list, err := s.client.CoinsMarket(convertTo, ids, order, s.maxResultsPerPage, page, sparkline, priceChangePercentage) if err != nil { return nil, err } @@ -114,16 +117,18 @@ func (s *Service) getLimitedCoinData(convert string, offset int) ([]apitypes.Coi // GetAllCoinData gets all coin data. Need to paginate through all pages func (s *Service) GetAllCoinData(convert string, ch chan []apitypes.Coin) error { go func() { - maxPages := 5 defer close(ch) - for i := 0; i < maxPages; i++ { + + for i := 0; i < s.maxPages; i++ { if i > 0 { time.Sleep(1 * time.Second) } + coins, err := s.getLimitedCoinData(convert, i) if err != nil { return } + ch <- coins } }()