Increase max page results for coingecko. Closes #47

pull/58/head
Miguel Mota 4 years ago
parent dbe32db051
commit 6fafc47a81

@ -616,7 +616,7 @@ Frequently asked questions:
- A: The default configuration file is located under `~/.config/cointop/config.toml` - 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? - Q: What format is the configuration file in?

@ -21,14 +21,18 @@ var ErrNotFound = errors.New("Not found")
// Service service // Service service
type Service struct { type Service struct {
client *gecko.Client client *gecko.Client
maxResultsPerPage int
maxPages int
} }
// NewCoinGecko new service // NewCoinGecko new service
func NewCoinGecko() *Service { func NewCoinGecko() *Service {
client := gecko.NewClient(nil) client := gecko.NewClient(nil)
return &Service{ 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) { func (s *Service) getLimitedCoinData(convert string, offset int) ([]apitypes.Coin, error) {
var ret []apitypes.Coin var ret []apitypes.Coin
ids := []string{} ids := []string{}
perPage := 250
page := offset page := offset
sparkline := false sparkline := false
pcp := geckoTypes.PriceChangePercentageObject pcp := geckoTypes.PriceChangePercentageObject
@ -54,7 +57,7 @@ func (s *Service) getLimitedCoinData(convert string, offset int) ([]apitypes.Coi
if convertTo == "" { if convertTo == "" {
convertTo = "usd" 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 { if err != nil {
return nil, err 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 // GetAllCoinData gets all coin data. Need to paginate through all pages
func (s *Service) GetAllCoinData(convert string, ch chan []apitypes.Coin) error { func (s *Service) GetAllCoinData(convert string, ch chan []apitypes.Coin) error {
go func() { go func() {
maxPages := 5
defer close(ch) defer close(ch)
for i := 0; i < maxPages; i++ {
for i := 0; i < s.maxPages; i++ {
if i > 0 { if i > 0 {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
coins, err := s.getLimitedCoinData(convert, i) coins, err := s.getLimitedCoinData(convert, i)
if err != nil { if err != nil {
return return
} }
ch <- coins ch <- coins
} }
}() }()

Loading…
Cancel
Save