forked from bbenzikry/go-1inch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote.go
68 lines (58 loc) · 1.57 KB
/
quote.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
package go1inch
import (
"context"
"errors"
"net/http"
)
// Quote gets quote for an aggregated swap which can be used with a web3 provider to send the transaction
func (c *Client) Quote(ctx context.Context, network Network, src, dst, amount string, opts *QuoteOpts) (*QuoteRes, int, http.Header, error) {
endpoint := "/quote"
if src == "" || dst == "" || amount == "" {
return nil, 0, nil, errors.New("required parameter is missing")
}
queries := make(map[string]interface{})
queries["src"] = src
queries["dst"] = dst
queries["amount"] = amount
if opts != nil {
if opts.Fee != "" {
queries["fee"] = opts.Fee
}
if opts.Protocols != "" {
queries["protocols"] = opts.Protocols
}
if opts.GasPrice != "" {
queries["gasPrice"] = opts.GasPrice
}
if opts.ComplexityLevel != "" {
queries["complexityLevel"] = opts.ComplexityLevel
}
if opts.ConnectorTokens != "" {
queries["connectorTokens"] = opts.ConnectorTokens
}
if opts.GasLimit != "" {
queries["gasLimit"] = opts.GasLimit
}
if opts.MainRouteParts != "" {
queries["mainRouteParts"] = opts.MainRouteParts
}
if opts.Parts != "" {
queries["parts"] = opts.Parts
}
if opts.IncludeGas {
queries["includeGas"] = true
}
if opts.IncludeProtocols {
queries["includeProtocols"] = true
}
if opts.IncludeTokensInfo {
queries["includeTokensInfo"] = true
}
}
var dataRes QuoteRes
statusCode, headers, err := c.doRequest(ctx, network, endpoint, "GET", &dataRes, nil, queries)
if err != nil {
return nil, statusCode, headers, err
}
return &dataRes, statusCode, headers, nil
}