-
Notifications
You must be signed in to change notification settings - Fork 8
/
estimate_coin_sell.go
54 lines (45 loc) · 1.45 KB
/
estimate_coin_sell.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
package api
import (
"encoding/json"
"strconv"
)
type EstimateCoinSellResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Result *EstimateCoinSellResult `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type EstimateCoinSellResult struct {
WillGet string `json:"will_get"`
Commission string `json:"commission"`
}
// Return estimate of sell coin transaction.
func (a *Api) EstimateCoinSell(coinToSell string, valueToSell string, coinToBuy string) (*EstimateCoinSellResult, error) {
return a.EstimateCoinSellAtHeight(coinToSell, valueToSell, coinToBuy, LatestBlockHeight)
}
// Return estimate of sell coin transaction.
func (a *Api) EstimateCoinSellAtHeight(coinToSell string, valueToSell string, coinToBuy string, height int) (*EstimateCoinSellResult, error) {
params := make(map[string]string)
params["coin_to_sell"] = coinToSell
params["value_to_sell"] = valueToSell
params["coin_to_buy"] = coinToBuy
if height > 0 {
params["height"] = strconv.Itoa(height)
}
res, err := a.client.R().SetQueryParams(params).Get("/estimate_coin_sell")
if err != nil {
return nil, err
}
if res.IsError() {
return nil, NewResponseError(res)
}
response := new(EstimateCoinSellResponse)
err = json.Unmarshal(res.Body(), response)
if err != nil {
return nil, err
}
if response.Error != nil {
return nil, response.Error
}
return response.Result, nil
}