Skip to content

Commit 797cb51

Browse files
authored
chore: add order flag (#9)
add currency flag change marketcap to flat64 to support pages beyond 35
1 parent d44ca19 commit 797cb51

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type MarketInfo struct {
99
Name string `json:"name"`
1010
Image string `json:"image"`
1111
CurrentPrice float64 `json:"current_price"`
12-
MarketCap int64 `json:"market_cap"`
12+
MarketCap float64 `json:"market_cap"`
1313
MarketCapRank int `json:"market_cap_rank"`
1414
FullyDilutedValuation float64 `json:"fully_diluted_valuation"`
1515
TotalVolume float64 `json:"total_volume"`

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var (
2323
ctx = context.Background()
2424
frequency *int
2525
pages *int
26+
currency *string
27+
order *string
2628
expiry *int
2729
hostname *string
2830
password *string
@@ -45,13 +47,15 @@ var (
4547
)
4648

4749
const (
48-
CoinGeckoMarkets = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&page=%d"
50+
CoinGeckoMarkets = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=%s&order=%s&page=%d"
4951
CoinGeckoCoin = "https://api.coingecko.com/api/v3/coins/%s"
5052
)
5153

5254
func init() {
5355
frequency = flag.Int("frequency", 1, "seconds between updates")
5456
pages = flag.Int("pages", 1, "number of pages (100 coin each) to pull from")
57+
currency = flag.String("currency", "usd", "currency to use")
58+
order = flag.String("order", "market_cap_desc", "sort key: market_cap_desc, gecko_desc, gecko_asc, market_cap_asc, market_cap_desc, volume_asc, volume_desc, id_asc, id_desc")
5559
expiry = flag.Int("expiry", 60, "number of seconds to keep entries in the cache")
5660
hostname = flag.String("hostname", "localhost:6379", "connection address for redis")
5761
password = flag.String("password", "", "redis password")
@@ -125,7 +129,7 @@ func gather(rdb *redis.Client) {
125129
func GetMarketData(page int) ([]MarketInfo, error) {
126130
var prices []MarketInfo
127131

128-
req, err := http.NewRequest("GET", fmt.Sprintf(CoinGeckoMarkets, page), nil)
132+
req, err := http.NewRequest("GET", fmt.Sprintf(CoinGeckoMarkets, *currency, *order, page), nil)
129133
if err != nil {
130134
return prices, err
131135
}
@@ -200,7 +204,7 @@ func GetCoinData(id string) (MarketInfo, error) {
200204
Name: coinPrice.Name,
201205
Image: coinPrice.Image.Thumb,
202206
CurrentPrice: float64(coinPrice.MarketData.CurrentPrice.Usd),
203-
MarketCap: int64(coinPrice.MarketData.MarketCap.Usd),
207+
MarketCap: float64(coinPrice.MarketData.MarketCap.Usd),
204208
MarketCapRank: coinPrice.MarketCapRank,
205209
FullyDilutedValuation: float64(coinPrice.MarketData.FullyDilutedValuation.Usd),
206210
TotalVolume: float64(coinPrice.MarketData.TotalVolume.Usd),

0 commit comments

Comments
 (0)