-
Notifications
You must be signed in to change notification settings - Fork 14
/
quote.go
56 lines (48 loc) · 1.42 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
package go1inch
import (
"context"
"errors"
)
// 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, fromTokenAddress, toTokenAddress, amount string, opts *QuoteOpts) (*QuoteRes, int, error) {
endpoint := "/quote"
if fromTokenAddress == "" || toTokenAddress == "" || amount == "" {
return nil, 0, errors.New("required parameter is missing")
}
var queries = make(map[string]interface{})
queries["fromTokenAddress"] = fromTokenAddress
queries["toTokenAddress"] = toTokenAddress
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
}
}
var dataRes QuoteRes
statusCode, err := c.doRequest(ctx, network, endpoint, "GET", &dataRes, nil, queries)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}