-
Notifications
You must be signed in to change notification settings - Fork 4
/
trades.go
49 lines (45 loc) · 1.6 KB
/
trades.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
package go_cowswap
import (
"context"
"fmt"
)
// GetTrades - Get trades for an owner or order_uid
func (c *Client) GetTrades(ctx context.Context, opts *GetTrades) (*TradesResponse, int, error) {
endpoint := "/trades"
if opts == nil {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_payload", Description: "must specify exactly one of owner or order_uid"}
}
if opts != nil {
if opts.Owner != "" && opts.OrderUid != "" {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_payload", Description: "must specify exactly one of owner or order_uid"}
}
if opts.Owner != "" {
endpoint = fmt.Sprintf("%s?owner=%s", endpoint, opts.Owner)
}
if opts.OrderUid != "" {
endpoint = fmt.Sprintf("%s?orderUid=%s", endpoint, opts.OrderUid)
}
}
var dataRes TradesResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, &ErrorCowResponse{Code: statusCode, ErrorType: "do_request_error", Description: err.Error()}
}
return &dataRes, statusCode, nil
}
type GetTrades struct {
Owner string
OrderUid string
}
type TradesResponse []struct {
BlockNumber int `json:"blockNumber"`
LogIndex int `json:"logIndex"`
OrderUID string `json:"orderUid"`
BuyAmount string `json:"buyAmount"`
SellAmount string `json:"sellAmount"`
SellAmountBeforeFees string `json:"sellAmountBeforeFees"`
Owner string `json:"owner"`
BuyToken string `json:"buyToken"`
SellToken string `json:"sellToken"`
TxHash string `json:"txHash"`
}