-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.go
60 lines (49 loc) · 1.71 KB
/
history.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
package goswyftx
import "strconv"
type HistoryService struct {
service
assetId int
}
type CurrencyHistory struct {
ID int `json:"id,omitempty"`
Time SwyftxTime `json:"time,omitempty"`
Quantity string `json:"quantity,omitempty"`
AddressID int `json:"address_id,omitempty"`
Status string `json:"status,omitempty"`
}
type TransactionHistory struct {
Asset int `json:"asset,omitempty"`
Amount float32 `json:"amount,omitempty"`
Updated SwyftxTime `json:"updated,omitempty"`
ActionType string `json:"actionType,omitempty"`
Status string `json:"status,omitempty"`
}
// History will return a history service that holds methods which can get history events for an asset
func (c *Client) History(asset int) *HistoryService {
return &HistoryService{service{c}, asset}
}
// Withdraw events for an asset
func (hs *HistoryService) Withdraw() (*CurrencyHistory, error) {
return hs.currency("withdraw")
}
// Deposit events for an asset
func (hs *HistoryService) Deposit() (*CurrencyHistory, error) {
return hs.currency("deposit")
}
func (hs *HistoryService) currency(actionType string) (*CurrencyHistory, error) {
var histCurrency CurrencyHistory
if err := hs.client.Get(buildString("history/", actionType, "/", strconv.Itoa(hs.assetId)),
&histCurrency); err != nil {
return nil, err
}
return &histCurrency, nil
}
// All trades, withdrawals and deposits events for an asset
func (hs *HistoryService) All(actionType string) ([]*TransactionHistory, error) {
var transHist []*TransactionHistory
if err := hs.client.Get(buildString("history/", actionType, "/", strconv.Itoa(hs.assetId)),
&transHist); err != nil {
return nil, err
}
return transHist, nil
}