23
23
ctx = context .Background ()
24
24
frequency * int
25
25
pages * int
26
+ currency * string
27
+ order * string
26
28
expiry * int
27
29
hostname * string
28
30
password * string
@@ -45,13 +47,15 @@ var (
45
47
)
46
48
47
49
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"
49
51
CoinGeckoCoin = "https://api.coingecko.com/api/v3/coins/%s"
50
52
)
51
53
52
54
func init () {
53
55
frequency = flag .Int ("frequency" , 1 , "seconds between updates" )
54
56
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" )
55
59
expiry = flag .Int ("expiry" , 60 , "number of seconds to keep entries in the cache" )
56
60
hostname = flag .String ("hostname" , "localhost:6379" , "connection address for redis" )
57
61
password = flag .String ("password" , "" , "redis password" )
@@ -125,7 +129,7 @@ func gather(rdb *redis.Client) {
125
129
func GetMarketData (page int ) ([]MarketInfo , error ) {
126
130
var prices []MarketInfo
127
131
128
- req , err := http .NewRequest ("GET" , fmt .Sprintf (CoinGeckoMarkets , page ), nil )
132
+ req , err := http .NewRequest ("GET" , fmt .Sprintf (CoinGeckoMarkets , * currency , * order , page ), nil )
129
133
if err != nil {
130
134
return prices , err
131
135
}
@@ -200,7 +204,7 @@ func GetCoinData(id string) (MarketInfo, error) {
200
204
Name : coinPrice .Name ,
201
205
Image : coinPrice .Image .Thumb ,
202
206
CurrentPrice : float64 (coinPrice .MarketData .CurrentPrice .Usd ),
203
- MarketCap : int64 (coinPrice .MarketData .MarketCap .Usd ),
207
+ MarketCap : float64 (coinPrice .MarketData .MarketCap .Usd ),
204
208
MarketCapRank : coinPrice .MarketCapRank ,
205
209
FullyDilutedValuation : float64 (coinPrice .MarketData .FullyDilutedValuation .Usd ),
206
210
TotalVolume : float64 (coinPrice .MarketData .TotalVolume .Usd ),
0 commit comments