-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassets.go
162 lines (135 loc) · 4.75 KB
/
assets.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package atomicmarket
import (
"fmt"
"github.com/TheBoringDude/go-urljoin"
"github.com/google/go-querystring/query"
)
const ASSETS_API = "assets"
type GetAssetsQuery struct {
CollectionName string `url:"collection_name,omitempty"`
SchemaName string `url:"schema_name,omitempty"`
TemplateID int `url:"template_id,omitempty"`
IsTransferable bool `url:"is_transferable,omitempty"`
IsBurnable bool `url:"is_burnable,omitempty"`
Burned bool `url:"burned,omitempty"`
Owner string `url:"owner,omitempty"`
Match string `url:"match,omitempty"`
CollectionBlacklist []string `url:"collection_blacklist,omitempty" del:","`
CollectionWhitelist []string `url:"collection_whitelist,omitempty" del:","`
OnlyDuplicateTemplates bool `url:"only_duplicate_templates,omitempty"`
HasBackedTokens bool `url:"has_backed_tokens,omitempty"`
AuthorizedAccount bool `url:"authorized_account,omitempty"`
TemplateWhitelist []string `url:"template_whitelist,omitempty" del:","`
TemplateBlacklist []string `url:"template_blacklist,omitempty" del:","`
HideTemplatesByAccounts string `url:"hide_templates_by_accounts,omitempty"`
HideOffers bool `url:"hide_offers,omitempty"`
IDs []string `url:"ids,omitempty" del:","`
LowerBound []string `url:"lower_bound,omitempty" del:","`
UpperBound []string `url:"upper_bound,omitempty" del:","`
Before int64 `url:"before,omitempty"`
After int64 `url:"after,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
Order string `url:"order,omitempty"`
Sort string `url:"sort,omitempty"`
}
// Fetch assets.
func (a *AtomicMarket) GetAssets(options *GetAssetsQuery) (*AssetsProps, error) {
var u string
if options != nil {
v, _ := query.Values(options)
u = urljoin.UrlJoin(a.apiUrl, ASSETS_API, fmt.Sprintf("?%s", v.Encode()))
} else {
u = urljoin.UrlJoin(a.apiUrl, ASSETS_API)
}
var result = &AssetsProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
// Fetch asset by id.
func (a *AtomicMarket) GetAssetID(id string) (*AssetIDProps, error) {
u := urljoin.UrlJoin(a.apiUrl, ASSETS_API, id)
var result = &AssetIDProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
// Fetch asset stats.
func (a *AtomicMarket) GetAssetIDStats(id string) (*AssetIDStatsProps, error) {
u := urljoin.UrlJoin(a.apiUrl, ASSETS_API, id, "stats")
var result = &AssetIDStatsProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
type GetAssetLogsQuery struct {
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
Order string `url:"order,omitempty"`
ActionWhitelist string `url:"action_whitelist,omitempty"`
ActionBlacklist string `url:"action_blacklist,omitempty"`
}
// Fetch asset logs.
func (a *AtomicMarket) GetAssetIDLogs(id string, options *GetAssetLogsQuery) (*AssetIDLogsProps, error) {
var opts = &GetAssetLogsQuery{
Limit: 100,
Page: 1,
Order: "desc",
}
if options != nil {
opts = &GetAssetLogsQuery{
ActionWhitelist: options.ActionWhitelist,
ActionBlacklist: options.ActionBlacklist,
}
if options.Limit < 1 {
opts.Limit = 100
}
if options.Page < 1 {
opts.Page = 1
}
if options.Order == "desc" || options.Order == "asc" {
opts.Order = options.Order
} else {
// default to `desc`
opts.Order = "desc"
}
}
v, _ := query.Values(opts)
u := urljoin.UrlJoin(a.apiUrl, ASSETS_API, id, "logs", fmt.Sprintf("?%s", v.Encode()))
var result = &AssetIDLogsProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
type GetAssetSalesQuery struct {
Buyer string `url:"buyer,omitempty" `
Seller string `url:"seller,omitempty"`
Symbol string `url:"symbol,omitempty"`
Order string `url:"order,omitempty"`
}
// Gets price history for a specific asset.
func (a *AtomicMarket) GetAssetIDSales(id string, options *GetAssetSalesQuery) (*AssetIDSalesProps, error) {
var opts = &GetAssetSalesQuery{
Order: "asc",
}
if options != nil {
if options.Order == "desc" || options.Order == "asc" {
opts.Order = options.Order
} else {
// default to `asc`
opts.Order = "asc"
}
}
v, _ := query.Values(opts)
u := urljoin.UrlJoin(a.apiUrl, ASSETS_API, id, "sales", fmt.Sprintf("?%s", v.Encode()))
var result = &AssetIDSalesProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}