forked from JulianToledano/goingecko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfts.go
84 lines (73 loc) · 2.22 KB
/
nfts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
}