-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
115 lines (100 loc) · 3.93 KB
/
market.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
package goswyftx
import "strconv"
type MarketService service
type MarketRate struct {
DailyPriceChange string `json:"dailyPriceChange,omitempty"`
MidPrice string `json:"midPrice,omitempty"`
}
type MarketAsset struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
MinimumOrder string `json:"minimum_order,omitempty"`
PriceScale int `json:"price_scale,omitempty"`
DepositEnabled bool `json:"deposit_enabled,omitempty"`
WithdrawEnabled bool `json:"withdraw_enabled,omitempty"`
MinConfirmations int `json:"min_confirmations,omitempty"`
MinWithdrawal int `json:"min_withdrawal,omitempty"`
MinimumOrderIncrement float32 `json:"minimum_order_increment,omitempty"`
MiningFee int `json:"mining_fee,omitempty"`
Primary bool `json:"primary,omitempty"`
Secondary bool `json:"secondary,omitempty"`
}
type MarketBasicInfo struct {
Name string `json:"name,omitempty"`
AltName string `json:"altName,omitempty"`
Code string `json:"code,omitempty"`
ID int `json:"id,omitempty"`
Rank int `json:"rank,omitempty"`
Buy string `json:"buy,omitempty"`
Sell string `json:"sell,omitempty"`
Spread string `json:"spread,omitempty"`
Volume24H float32 `json:"volume24H,omitempty"`
MarketCap float64 `json:"marketCap,omitempty"`
}
type MarketDetailedInfo struct {
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Description string `json:"description,omitempty"`
Category string `json:"category,omitempty"`
Mineable int `json:"mineable,omitempty"`
Spread string `json:"spread,omitempty"`
Rank int `json:"rank,omitempty"`
RankSuffix string `json:"rankSuffix,omitempty"`
Volume struct {
H24 float32 `json:"24H,omitempty"`
W1 float32 `json:"1W,omitempty"`
M1 float32 `json:"1M,omitempty"`
MarketCap float64 `json:"marketCap,omitempty"`
} `json:"volume,omitempty"`
URL struct {
Website string `json:"website,omitempty"`
Twitter string `json:"twitter,omitempty"`
Reddit string `json:"reddit,omitempty"`
TechDoc string `json:"techDoc,omitempty"`
Explorer string `json:"explorer,omitempty"`
} `json:"urls,omitempty"`
Supply struct {
Circulating int `json:"circulating,omitempty"`
Total int `json:"total,omitempty"`
Max int `json:"max,omitempty"`
} `json:"supply,omitempty"`
}
// Market will return a market service that holds methods which can information assets
func (c *Client) Market() *MarketService {
return (*MarketService)(&service{c})
}
// LiveRates will get live rates from swyftx
func (ms *MarketService) LiveRates(asset int) (*MarketRate, error) {
var marketRate struct {
MarketRate MarketRate `json:"1"`
}
if err := ms.client.Get(buildString("live-rates/", strconv.Itoa(asset)), &marketRate); err != nil {
return nil, err
}
return &marketRate.MarketRate, nil
}
// Assets will retrieve market information on assets
func (ms *MarketService) Assets() ([]*MarketAsset, error) {
var marketAssets []*MarketAsset
if err := ms.client.Get("markets/assets/", &marketAssets); err != nil {
return nil, err
}
return marketAssets, nil
}
// BasicInfo on an asset given the asset code
func (ms *MarketService) BasicInfo(assetCode string) (*MarketBasicInfo, error) {
var marketBasic MarketBasicInfo
if err := ms.client.Get(buildString("markets/info/basic/", assetCode), &marketBasic); err != nil {
return nil, err
}
return &marketBasic, nil
}
// DetailedInfo on an asset given the asset code
func (ms *MarketService) DetailedInfo(assetCode string) ([]*MarketDetailedInfo, error) {
var detailedInfo []*MarketDetailedInfo
if err := ms.client.Get(buildString("markets/info/details/", assetCode), &detailedInfo); err != nil {
return nil, err
}
return detailedInfo, nil
}