-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
73 lines (58 loc) · 2.02 KB
/
account.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
package btcmarkets
import (
"fmt"
)
/*
ACCOUNT [HTTP ENDPOINTS]
Endpoints:
GET /account/balance (Rate Limited: 25x / 10sec)
GET /account/:instrument/:currency/tradingfee (Rate Limited: 10x / 10sec)
*/
// AccountBalanceResponse represents the JSON data structure sent to
// the GET /account/balance endpoint.
type AccountBalanceResponse []AccountBalanceItem
// AccountBalance implements the GET /account/balance endpoint.
func (c *Client) AccountBalance() (*AccountBalanceResponse, error) {
abr := &AccountBalanceResponse{}
err := c.Get("/account/balance", abr, rateLimit10)
if err != nil {
return nil, err
}
return abr, nil
}
// AccountTradingFeeResponse represents the JSON data structure sent to
// the GET /account/:instrument/:currency/tradingfee endpoint.
type AccountTradingFeeResponse struct {
Success bool `json:"success"`
ErrorCode int `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
TradingFee AmountWhole `json:"tradingFeeRate"`
Volume30Days AmountWhole `json:"volume30Day"`
}
// AccountTradingFee implements the /account/:instrument/:currency/tradingfee endpoint.
func (c *Client) AccountTradingFee(instrument Instrument, currency Currency) (*AccountTradingFeeResponse, error) {
atfd := &AccountTradingFeeResponse{}
err := c.Get(fmt.Sprintf("/account/%s/%s/tradingfee", instrument, currency), atfd, rateLimit10)
if err != nil {
return nil, err
}
return atfd, nil
}
// GetBalance returns the balance of the provided currency.
func (a AccountBalanceResponse) GetBalance(currency Currency) AmountWhole {
for _, b := range a {
if b.Currency == currency {
return b.Balance
}
}
return AmountWhole(0)
}
// AccountBalanceItem is the data structure that represents currency account balance.
type AccountBalanceItem struct {
Currency Currency `json:"currency"`
Balance AmountWhole `json:"balance"`
Pending AmountWhole `json:"pendingFunds"`
}
func (ab *AccountBalanceItem) String() string {
return fmt.Sprintf("%s: %f", ab.Currency, ab.Balance.ToAmountDecimal())
}