Skip to content

Commit

Permalink
Add CoinGecko API support
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed May 13, 2019
1 parent 71d9620 commit 6361b22
Show file tree
Hide file tree
Showing 36 changed files with 3,607 additions and 158 deletions.
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ You can then configure the actions you want for each key:
```toml
currency = "USD"
defaultView = ""
api = "coingecko"

[shortcuts]
"$" = "last_page"
Expand Down Expand Up @@ -502,12 +503,34 @@ Frequently asked questions:

- Q: Where is the data from?

- A: Currently the data is from [CoinMarketCap](https://coinmarketcap.com/).
- A: By default, the data is from [CoinGecko](https://www.coingecko.com/). Data from [CoinMarketCap](https://coinmarketcap.com/) is another option.

- Q: What APIs does it support?

- A: APIs currently supported are [CoinMarketCap](https://coinmarketcap.com/) and [CoinGecko](https://www.coingecko.com/).

- Q: What coins does this support?

- A: This supports any coin supported by the API being used to fetch coin information.

- Q: How do I set the API to use?

- A: You can use the `--api` flag, eg. `--api coingecko`. You can also set the API choice in the config file.

```toml
api = "coingecko"
```

Options are: `coinmarketcap`, `coingecko`

- Q: Where is the config file located?

- A: The default configuration file is located under `~/.cointop/config`

- Q: What format is the configuration file in?

- A: The configuration file is in [TOML](https://en.wikipedia.org/wiki/TOML) format.

- Q: Will you be supporting more coin API's in the future?

- A: Yes supporting more coin APIs is planned.
Expand Down Expand Up @@ -558,14 +581,6 @@ Frequently asked questions:
export PATH=$PATH:$GOPATH/bin
```

- Q: Where is the config file located?

- A: The default configuration file is located under `~/.cointop/config`

- Q: What format is the configuration file in?

- A: The configuration file is in [TOML](https://en.wikipedia.org/wiki/TOML) format.

- Q: How do I search?

- A: The default key to open search is <kbd>/</kbd>. Type the search query after the `/` in the field and hit <kbd>Enter</kbd>.
Expand Down Expand Up @@ -680,6 +695,8 @@ Frequently asked questions:

The supported crypto currencies for conversion are `BTC` and `ETH`.

Please note that some APIs may have limited support for certain conversion formats.

- Q: How do I save the selected currency to convert to?

- A: Press <kbd>ctrl</kbd>+<kbd>s</kbd> to save the selected currency to convert to.
Expand Down
4 changes: 3 additions & 1 deletion cmd/cointop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
// Run ...
func Run() {
var v, ver, test, clean, reset bool
var config, cmcAPIKey string
var config, cmcAPIKey, apiChoice string
flag.BoolVar(&v, "v", false, "Version")
flag.BoolVar(&ver, "version", false, "Version")
flag.BoolVar(&test, "test", false, "Run test")
flag.BoolVar(&clean, "clean", false, "Clean cache")
flag.BoolVar(&reset, "reset", false, "Reset config")
flag.StringVar(&config, "config", "", "Config filepath")
flag.StringVar(&cmcAPIKey, "coinmarketcap-api-key", "", "CoinMarketCap API key")
flag.StringVar(&apiChoice, "api", cointop.CoinMarketCap, "API choice")
flag.Parse()
if v || ver {
fmt.Printf("cointop v%s", cointop.Version())
Expand All @@ -31,6 +32,7 @@ func Run() {
cointop.NewCointop(&cointop.Config{
ConfigFilepath: config,
CoinMarketCapAPIKey: cmcAPIKey,
APIChoice: apiChoice,
}).Run()
}
}
Expand Down
7 changes: 7 additions & 0 deletions cointop/api/coingecko/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Lai Weng Han

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions cointop/api/coingecko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a fork
13 changes: 13 additions & 0 deletions cointop/api/coingecko/format/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package format

import "strconv"

// Bool2String boolean to string
func Bool2String(b bool) string {
return strconv.FormatBool(b)
}

// Int2String Integer to string
func Int2String(i int) string {
return strconv.Itoa(i)
}
259 changes: 259 additions & 0 deletions cointop/api/coingecko/v3/types/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
package types

// OrderType

// OrderType in CoinGecko
type OrderType struct {
MarketCapDesc string
MarketCapAsc string
GeckoDesc string
GeckoAsc string
VolumeAsc string
VolumeDesc string
}

// OrderTypeObject for certain order
var OrderTypeObject = &OrderType{
MarketCapDesc: "market_cap_desc",
MarketCapAsc: "market_cap_asc",
GeckoDesc: "gecko_desc",
GeckoAsc: "gecko_asc",
VolumeAsc: "volume_asc",
VolumeDesc: "volume_desc",
}

// PriceChangePercentage

// PriceChangePercentage in different amount of time
type PriceChangePercentage struct {
PCP1h string
PCP24h string
PCP7d string
PCP14d string
PCP30d string
PCP200d string
PCP1y string
}

// PriceChangePercentageObject for different amount of time
var PriceChangePercentageObject = &PriceChangePercentage{
PCP1h: "1h",
PCP24h: "24h",
PCP7d: "7d",
PCP14d: "14d",
PCP30d: "30d",
PCP200d: "200d",
PCP1y: "1y",
}

// SHARED
// coinBaseStruct [private]
type coinBaseStruct struct {
ID string `json:"id"`
Symbol string `json:"symbol"`
Name string `json:"name"`
}

// AllCurrencies map all currencies (USD, BTC) to float64
type AllCurrencies map[string]float64

// LocalizationItem map all locale (en, zh) into respective string
type LocalizationItem map[string]string

// TYPES

// DescriptionItem map all description (in locale) into respective string
type DescriptionItem map[string]string

// LinksItem map all links
type LinksItem map[string]interface{}

// ChartItem ...
type ChartItem [2]float32

// MarketDataItem map all market data item
type MarketDataItem struct {
CurrentPrice AllCurrencies `json:"current_price"`
ROI *ROIItem `json:"roi"`
ATH AllCurrencies `json:"ath"`
ATHChangePercentage AllCurrencies `json:"ath_change_percentage"`
ATHDate map[string]string `json:"ath_date"`
MarketCap AllCurrencies `json:"market_cap"`
MarketCapRank uint16 `json:"market_cap_rank"`
TotalVolume AllCurrencies `json:"total_volume"`
High24 AllCurrencies `json:"high_24h"`
Low24 AllCurrencies `json:"low_24h"`
PriceChange24h float64 `json:"price_change_24h"`
PriceChangePercentage24h float64 `json:"price_change_percentage_24h"`
PriceChangePercentage7d float64 `json:"price_change_percentage_7d"`
PriceChangePercentage14d float64 `json:"price_change_percentage_14d"`
PriceChangePercentage30d float64 `json:"price_change_percentage_30d"`
PriceChangePercentage60d float64 `json:"price_change_percentage_60d"`
PriceChangePercentage200d float64 `json:"price_change_percentage_200d"`
PriceChangePercentage1y float64 `json:"price_change_percentage_1y"`
MarketCapChange24h float64 `json:"market_cap_change_24h"`
MarketCapChangePercentage24h float64 `json:"market_cap_change_percentage_24h"`
PriceChange24hInCurrency AllCurrencies `json:"price_change_24h_in_currency"`
PriceChangePercentage1hInCurrency AllCurrencies `json:"price_change_percentage_1h_in_currency"`
PriceChangePercentage24hInCurrency AllCurrencies `json:"price_change_percentage_24h_in_currency"`
PriceChangePercentage7dInCurrency AllCurrencies `json:"price_change_percentage_7d_in_currency"`
PriceChangePercentage14dInCurrency AllCurrencies `json:"price_change_percentage_14d_in_currency"`
PriceChangePercentage30dInCurrency AllCurrencies `json:"price_change_percentage_30d_in_currency"`
PriceChangePercentage60dInCurrency AllCurrencies `json:"price_change_percentage_60d_in_currency"`
PriceChangePercentage200dInCurrency AllCurrencies `json:"price_change_percentage_200d_in_currency"`
PriceChangePercentage1yInCurrency AllCurrencies `json:"price_change_percentage_1y_in_currency"`
MarketCapChange24hInCurrency AllCurrencies `json:"market_cap_change_24h_in_currency"`
MarketCapChangePercentage24hInCurrency AllCurrencies `json:"market_cap_change_percentage_24h_in_currency"`
TotalSupply *float64 `json:"total_supply"`
CirculatingSupply float64 `json:"circulating_supply"`
Sparkline *SparklineItem `json:"sparkline_7d"`
LastUpdated string `json:"last_updated"`
}

// CommunityDataItem map all community data item
type CommunityDataItem struct {
FacebookLikes *uint `json:"facebook_likes"`
TwitterFollowers *uint `json:"twitter_followers"`
RedditAveragePosts48h *float64 `json:"reddit_average_posts_48h"`
RedditAverageComments48h *float64 `json:"reddit_average_comments_48h"`
RedditSubscribers *uint `json:"reddit_subscribers"`
RedditAccountsActive48h *interface{} `json:"reddit_accounts_active_48h"`
TelegramChannelUserCount *uint `json:"telegram_channel_user_count"`
}

// DeveloperDataItem map all developer data item
type DeveloperDataItem struct {
Forks *uint `json:"forks"`
Stars *uint `json:"stars"`
Subscribers *uint `json:"subscribers"`
TotalIssues *uint `json:"total_issues"`
ClosedIssues *uint `json:"closed_issues"`
PRMerged *uint `json:"pull_requests_merged"`
PRContributors *uint `json:"pull_request_contributors"`
CommitsCount4Weeks *uint `json:"commit_count_4_weeks"`
}

// PublicInterestItem map all public interest item
type PublicInterestItem struct {
AlexaRank uint `json:"alexa_rank"`
BingMatches uint `json:"bing_matches"`
}

// ImageItem struct for all sizes of image
type ImageItem struct {
Thumb string `json:"thumb"`
Small string `json:"small"`
Large string `json:"large"`
}

// ROIItem ROI Item
type ROIItem struct {
Times float64 `json:"times"`
Currency string `json:"currency"`
Percentage float64 `json:"percentage"`
}

// SparklineItem for sparkline
type SparklineItem struct {
Price []float64 `json:"price"`
}

// TickerItem for ticker
type TickerItem struct {
Base string `json:"base"`
Target string `json:"target"`
Market struct {
Name string `json:"name"`
Identifier string `json:"identifier"`
TradingIncentive bool `json:"has_trading_incentive"`
} `json:"market"`
Last float64 `json:"last"`
ConvertedLast map[string]float64 `json:"converted_last"`
Volume float64 `json:"volume"`
ConvertedVolume map[string]float64 `json:"converted_volume"`
Timestamp string `json:"timestamp"`
IsAnomaly bool `json:"is_anomaly"`
IsStale bool `json:"is_stale"`
CoinID string `json:"coin_id"`
}

// StatusUpdateItem for BEAM
type StatusUpdateItem struct {
Description string `json:"description"`
Category string `json:"category"`
CreatedAt string `json:"created_at"`
User string `json:"user"`
UserTitle string `json:"user_title"`
Pin bool `json:"pin"`
Project struct {
coinBaseStruct
Type string `json:"type"`
Image ImageItem `json:"image"`
} `json:"project"`
}

// CoinsListItem item in CoinList
type CoinsListItem struct {
coinBaseStruct
}

// CoinsMarketItem item in CoinMarket
type CoinsMarketItem struct {
coinBaseStruct
Image string `json:"image"`
CurrentPrice float64 `json:"current_price"`
MarketCap float64 `json:"market_cap"`
MarketCapRank int16 `json:"market_cap_rank"`
TotalVolume float64 `json:"total_volume"`
High24 float64 `json:"high_24h"`
Low24 float64 `json:"low_24h"`
PriceChange24h float64 `json:"price_change_24h"`
PriceChangePercentage24h float64 `json:"price_change_percentage_24h"`
MarketCapChange24h float64 `json:"market_cap_change_24h"`
MarketCapChangePercentage24h float64 `json:"market_cap_change_percentage_24h"`
CirculatingSupply float64 `json:"circulating_supply"`
TotalSupply float64 `json:"total_supply"`
ATH float64 `json:"ath"`
ATHChangePercentage float64 `json:"ath_change_percentage"`
ATHDate string `json:"ath_date"`
ROI *ROIItem `json:"roi"`
LastUpdated string `json:"last_updated"`
SparklineIn7d *SparklineItem `json:"sparkline_in_7d"`
PriceChangePercentage1hInCurrency *float64 `json:"price_change_percentage_1h_in_currency"`
PriceChangePercentage24hInCurrency *float64 `json:"price_change_percentage_24h_in_currency"`
PriceChangePercentage7dInCurrency *float64 `json:"price_change_percentage_7d_in_currency"`
PriceChangePercentage14dInCurrency *float64 `json:"price_change_percentage_14d_in_currency"`
PriceChangePercentage30dInCurrency *float64 `json:"price_change_percentage_30d_in_currency"`
PriceChangePercentage200dInCurrency *float64 `json:"price_change_percentage_200d_in_currency"`
PriceChangePercentage1yInCurrency *float64 `json:"price_change_percentage_1y_in_currency"`
}

// EventCountryItem item in EventsCountries
type EventCountryItem struct {
Country string `json:"country"`
Code string `json:"code"`
}

// ExchangeRatesItem item in ExchangeRate
type ExchangeRatesItem map[string]ExchangeRatesItemStruct

// ExchangeRatesItemStruct struct in ExchangeRateItem
type ExchangeRatesItemStruct struct {
Name string `json:"name"`
Unit string `json:"unit"`
Value float64 `json:"value"`
Type string `json:"type"`
}

// Global for data of /global
type Global struct {
ActiveCryptocurrencies uint16 `json:"active_cryptocurrencies"`
UpcomingICOs uint16 `json:"upcoming_icos"`
EndedICOs uint16 `json:"ended_icos"`
Markets uint16 `json:"markets"`
MarketCapChangePercentage24hUSD float32 `json:"market_cap_change_percentage_24h_usd"`
TotalMarketCap AllCurrencies `json:"total_market_cap"`
TotalVolume AllCurrencies `json:"total_volume"`
MarketCapPercentage AllCurrencies `json:"market_cap_percentage"`
UpdatedAt int64 `json:"updated_at"`
}
Loading

0 comments on commit 6361b22

Please sign in to comment.