-
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.
- Loading branch information
1 parent
38bede9
commit 3a3d23a
Showing
5 changed files
with
190 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package goingecko | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/JulianToledano/goingecko/nfts" | ||
"net/url" | ||
) | ||
|
||
// NftsList Use this to obtain all the NFT ids in order to make API calls, paginated to 100 items. | ||
// | ||
// Cache / Update Frequency: every 5 minutes | ||
// Parameters: | ||
// order(string) - valid values: h24_volume_native_asc, h24_volume_native_desc, floor_price_native_asc, floor_price_native_desc, market_cap_native_asc, market_cap_native_desc, market_cap_usd_asc, market_cap_usd_desc | ||
// assetPlatformId(string) - The id of the platform issuing tokens (See asset_platforms endpoint for list of options) | ||
// per_page(integer) - Valid values: 1..250. Total results per page | ||
// page(integer) - Page through results | ||
func (c *Client) NftsList(order, assetPlatformId string, perPage, page int32) ([]nfts.Nft, error) { | ||
params := url.Values{} | ||
if order != "" { | ||
params.Add("order", order) | ||
} | ||
if assetPlatformId != "" { | ||
params.Add("asset_platform_id", assetPlatformId) | ||
} | ||
if perPage > 0 { | ||
params.Add("per_page", string(perPage)) | ||
} | ||
if page > 0 { | ||
params.Add("page", string(page)) | ||
} | ||
|
||
rUrl := fmt.Sprintf("%s/list?%s", nftsURL, params.Encode()) | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data []nfts.Nft | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// NftsId Get current data (name, price_floor, volume_24h ...) for an NFT collection. native_currency (string) is only a representative of the currency. | ||
// | ||
// Cache / Update Frequency: every 60 seconds | ||
// Parameters: | ||
// id*(string) - id of nft collection (can be obtained from /nfts/list) | ||
func (c *Client) NftsId(id string) (*nfts.NftId, error) { | ||
rUrl := fmt.Sprintf("%s/%s", nftsURL, id) | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data *nfts.NftId | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// NftsContract | ||
func (c *Client) NftsContract(assetPlatform, contract string) (*nfts.NftId, error) { | ||
rUrl := fmt.Sprintf("%s/%s/contract/%s", nftsURL, assetPlatform, contract) | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data *nfts.NftId | ||
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package nfts | ||
|
||
type Nft struct { | ||
Id string `json:"id"` | ||
ContractAddress string `json:"contract_address"` | ||
Name string `json:"name"` | ||
AssetPlatformId string `json:"asset_platform_id"` | ||
Symbol string `json:"symbol"` | ||
} | ||
|
||
type NftId struct { | ||
Id string `json:"id"` | ||
ContractAddress string `json:"contract_address"` | ||
AssetPlatformId string `json:"asset_platform_id"` | ||
Name string `json:"name"` | ||
Symbol string `json:"symbol"` | ||
Image Image `json:"image"` | ||
Description string `json:"description"` | ||
NativeCurrency string `json:"native_currency"` | ||
NativeCurrencySymbol string `json:"native_currency_symbol"` | ||
FloorPrice Price `json:"floor_price"` | ||
MarketCap Price `json:"market_cap"` | ||
Volume24H Price `json:"volume_24h"` | ||
FloorPriceInUsd24HPercentageChange float64 `json:"floor_price_in_usd_24h_percentage_change"` | ||
FloorPrice24HPercentageChange Price `json:"floor_price_24h_percentage_change"` | ||
MarketCap24HPercentageChange Price `json:"market_cap_24h_percentage_change"` | ||
Volume24HPercentageChange Price `json:"volume_24h_percentage_change"` | ||
NumberOfUniqueAddresses float64 `json:"number_of_unique_addresses"` | ||
NumberOfUniqueAddresses24HPercentageChange float64 `json:"number_of_unique_addresses_24h_percentage_change"` | ||
VolumeInUsd24HPercentageChange float64 `json:"volume_in_usd_24h_percentage_change"` | ||
TotalSupply float64 `json:"total_supply"` | ||
OneDaySales float64 `json:"one_day_sales"` | ||
OneDaySales24HPercentageChange float64 `json:"one_day_sales_24h_percentage_change"` | ||
OneDayAverageSalePrice float64 `json:"one_day_average_sale_price"` | ||
OneDayAverageSalePrice24HPercentageChange float64 `json:"one_day_average_sale_price_24h_percentage_change"` | ||
Links Links `json:"links"` | ||
FloorPrice7DPercentageChange Price `json:"floor_price_7d_percentage_change"` | ||
FloorPrice14DPercentageChange Price `json:"floor_price_14d_percentage_change"` | ||
FloorPrice30DPercentageChange Price `json:"floor_price_30d_percentage_change"` | ||
FloorPrice60DPercentageChange Price `json:"floor_price_60d_percentage_change"` | ||
FloorPrice1YPercentageChange Price `json:"floor_price_1y_percentage_change"` | ||
Explorers []Explorers `json:"explorers"` | ||
} | ||
|
||
type Price struct { | ||
Usd float64 `json:"usd"` | ||
NativeCurrency float64 `json:"native_currency"` | ||
} | ||
|
||
type Image struct { | ||
Small string `json:"small"` | ||
} | ||
|
||
type Links struct { | ||
Homepage string `json:"homepage"` | ||
Twitter string `json:"twitter"` | ||
Discord string `json:"discord"` | ||
} | ||
|
||
type Explorers struct { | ||
Name string `json:"name"` | ||
Link string `json:"link"` | ||
} |
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,39 @@ | ||
package test | ||
|
||
import ( | ||
"github.com/JulianToledano/goingecko" | ||
"testing" | ||
) | ||
|
||
func TestNftsList(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
data, err := cgClient.NftsList("", "", 0, 0) | ||
if data == nil { | ||
t.Errorf("Error") | ||
} | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
} | ||
|
||
func TestNftsId(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
data, err := cgClient.NftsId("squiggly") | ||
if data == nil { | ||
t.Errorf("Error") | ||
} | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
} | ||
|
||
func TestNftsContract(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
data, err := cgClient.NftsContract("ethereum", "0x36F379400DE6c6BCDF4408B282F8b685c56adc60") | ||
if data == nil { | ||
t.Errorf("Error") | ||
} | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
} |