-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update: simple use options * update: client names, add: ping * update: contract use options * add: gecko api version * update: assetPlatforms use options * update: categories use options * update: exchanges use options * update: derivatices use options * fix * update: nfts use options * update: exchangeRates use options * update: search use options * update: trending use options * update: global use options * update: companies use options * update: move common types to api * del: tests
- Loading branch information
1 parent
1ac956e
commit 5b3bc45
Showing
106 changed files
with
1,788 additions
and
1,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package assetPlatforms | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/JulianToledano/goingecko/api" | ||
|
||
"github.com/JulianToledano/goingecko/api/assetPlatforms/types" | ||
) | ||
|
||
// assetPlatformsOption is an interface that extends api.Option to provide | ||
// asset platform-specific options | ||
type assetPlatformsOption interface { | ||
api.Option | ||
|
||
isAssetPlatformsOption() | ||
} | ||
|
||
// WithFilter returns an assetPlatformsOption that sets the filter parameter | ||
// for asset platform requests. The filter parameter can be used to filter | ||
// asset platforms by name or ID. | ||
// Current supported filters: [nft] | ||
func WithFilter(filter string) assetPlatformsOption { | ||
return &filterOption{filter} | ||
} | ||
|
||
// AssetPlatforms allows you to query all the asset platforms on CoinGecko. | ||
// | ||
// 👍 Tips | ||
// | ||
// You may use this endpoint to query the list of asset platforms for other endpoints that contain params like id orids(asset platforms) | ||
// You may include NFT at the filter params to get the list of NFT-support asset platforms on CoinGecko | ||
func (c *AssetPlatformsClient) AssetPlatforms(ctx context.Context, opts ...assetPlatformsOption) (*types.AssetPlatforms, error) { | ||
params := url.Values{} | ||
|
||
for _, opt := range opts { | ||
opt.Apply(¶ms) | ||
} | ||
|
||
rUrl := fmt.Sprintf("%s?%s", c.assetPlatformsUrl(), params.Encode()) | ||
resp, err := c.MakeReq(ctx, rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data *types.AssetPlatforms | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
type filterOption struct{ filter string } | ||
|
||
func (o filterOption) Apply(v *url.Values) { | ||
v.Set("filter", o.filter) | ||
} | ||
|
||
func (o filterOption) isAssetPlatformsOption() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package assetPlatforms | ||
|
||
import ( | ||
"github.com/JulianToledano/goingecko/api/internal" | ||
geckohttp "github.com/JulianToledano/goingecko/http" | ||
) | ||
|
||
type AssetPlatformsClient struct { | ||
*internal.Client | ||
} | ||
|
||
func NewClient(c *geckohttp.Client, url string) *AssetPlatformsClient { | ||
return &AssetPlatformsClient{ | ||
internal.NewClient(c, url), | ||
} | ||
} | ||
|
||
func (c *AssetPlatformsClient) assetPlatformsUrl() string { | ||
return c.URL + "/asset_platforms" | ||
} | ||
|
||
// TODO: https://docs.coingecko.com/reference/token-lists |
2 changes: 1 addition & 1 deletion
2
assetPlatforms/assetPlatforms.go → api/assetPlatforms/types/assetPlatforms.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package assetPlatforms | ||
package types | ||
|
||
type AssetPlatforms []Asset | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package categories | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/JulianToledano/goingecko/api" | ||
"github.com/JulianToledano/goingecko/api/categories/types" | ||
) | ||
|
||
// categoriesOption is an interface that extends api.Option to provide | ||
// category-specific options | ||
type categoriesOption interface { | ||
api.Option | ||
|
||
isCategoryOptions() | ||
} | ||
|
||
// WithOrderOption returns a categoriesOption that sets the order parameter | ||
// for category requests. The order parameter can be used to sort categories | ||
// by market cap, volume, etc. | ||
func WithOrderOption(order string) categoriesOption { | ||
return &orderOption{order} | ||
} | ||
|
||
// Categories allows you to query all the coins categories with market data (market cap, volume, etc.) on CoinGecko. | ||
// | ||
// 📘Notes | ||
// | ||
// CoinGecko Equivalent Page: https://www.coingecko.com/en/categories | ||
// Cache / Update Frequency: every 5 minutes for all the API plans | ||
// CoinGecko categories are different from GeckoTerminal categories | ||
func (c *CategoriesClient) Categories(ctx context.Context, options ...categoriesOption) (*types.CategoriesWithMarketDataList, error) { | ||
params := url.Values{} | ||
|
||
for _, opt := range options { | ||
opt.Apply(¶ms) | ||
} | ||
|
||
rUrl := fmt.Sprintf("%s?%s", c.categoriesUrl(), params.Encode()) | ||
resp, err := c.MakeReq(ctx, rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data *types.CategoriesWithMarketDataList | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
type orderOption struct{ order string } | ||
|
||
func (o orderOption) Apply(v *url.Values) { | ||
v.Set("order", o.order) | ||
} | ||
func (o orderOption) isCategoryOptions() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package categories | ||
|
||
import ( | ||
"github.com/JulianToledano/goingecko/api/internal" | ||
geckohttp "github.com/JulianToledano/goingecko/http" | ||
) | ||
|
||
type CategoriesClient struct { | ||
*internal.Client | ||
} | ||
|
||
func NewClient(c *geckohttp.Client, url string) *CategoriesClient { | ||
return &CategoriesClient{ | ||
internal.NewClient(c, url), | ||
} | ||
} | ||
|
||
func (c *CategoriesClient) categoriesUrl() string { | ||
return c.URL + "/categories" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package categories | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/JulianToledano/goingecko/api/categories/types" | ||
) | ||
|
||
// CategoriesList allows you to query all the coins categories on CoinGecko. | ||
// | ||
// 👍 Tips | ||
// | ||
// You may use this endpoint to query the list of categories for other endpoints that contain params like category | ||
// | ||
// 📘 Notes | ||
// | ||
// CoinGecko Equivalent Page: https://www.coingecko.com/en/categories | ||
// Cache / Update Frequency: every 5 minutes for all the API plans | ||
// CoinGecko categories are different from GeckoTerminal categories | ||
func (c *CategoriesClient) CategoriesList(ctx context.Context) (*types.CategoriesList, error) { | ||
rUrl := fmt.Sprintf("%s/%s", c.categoriesUrl(), "list") | ||
resp, err := c.MakeReq(ctx, rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data *types.CategoriesList | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package categories | ||
package types | ||
|
||
type CategoriesList []Category | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package coins | ||
|
||
import ( | ||
"github.com/JulianToledano/goingecko/api/internal" | ||
geckohttp "github.com/JulianToledano/goingecko/http" | ||
) | ||
|
||
type Client struct { | ||
*geckohttp.Client | ||
|
||
url string | ||
type CoinsClient struct { | ||
*internal.Client | ||
} | ||
|
||
func NewCoinsClient(c *geckohttp.Client, url string) *Client { | ||
return &Client{ | ||
c, | ||
url, | ||
func NewClient(c *geckohttp.Client, url string) *CoinsClient { | ||
return &CoinsClient{ | ||
internal.NewClient(c, url), | ||
} | ||
} | ||
|
||
func (c *Client) coinsUrl() string { | ||
return c.url + "/coins" | ||
func (c *CoinsClient) coinsUrl() string { | ||
return c.URL + "/coins" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.