-
Notifications
You must be signed in to change notification settings - Fork 4
/
orders.go
167 lines (159 loc) · 7.87 KB
/
orders.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package go_cowswap
import (
"context"
"fmt"
"time"
)
// GetOrdersByUid - Get existing order from UID
func (c *Client) GetOrdersByUid(ctx context.Context, uid string) (*OrderByUidResponse, int, error) {
if uid == "" {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_order_id", Description: "order UID not provided"}
}
endpoint := fmt.Sprintf("/orders/%s", uid)
var dataRes OrderByUidResponse
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 OrderByUidResponse struct {
SellToken string `json:"sellToken"`
BuyToken string `json:"buyToken"`
Receiver string `json:"receiver"`
SellAmount string `json:"sellAmount"`
BuyAmount string `json:"buyAmount"`
ValidTo int `json:"validTo"`
AppData string `json:"appData"`
FeeAmount string `json:"feeAmount"`
Kind string `json:"kind"`
PartiallyFillable bool `json:"partiallyFillable"`
SellTokenBalance string `json:"sellTokenBalance"`
BuyTokenBalance string `json:"buyTokenBalance"`
SigningScheme string `json:"signingScheme"`
Signature string `json:"signature"`
From string `json:"from"`
QuoteID int `json:"quoteId"`
CreationTime time.Time `json:"creationTime"`
Owner string `json:"owner"`
UID string `json:"UID"`
AvailableBalance string `json:"availableBalance"`
ExecutedSellAmount string `json:"executedSellAmount"`
ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"`
ExecutedBuyAmount string `json:"executedBuyAmount"`
ExecutedFeeAmount string `json:"executedFeeAmount"`
Invalidated bool `json:"invalidated"`
Status string `json:"status"`
FullFeeAmount string `json:"fullFeeAmount"`
IsLiquidityOrder bool `json:"isLiquidityOrder"`
EthflowData struct {
IsRefunded bool `json:"isRefunded"`
UserValidTo int `json:"userValidTo"`
} `json:"ethflowData"`
OnchainUser string `json:"onchainUser"`
}
// GetOrdersBySettlementTxHash - Get orders by settlement transaction hash
func (c *Client) GetOrdersBySettlementTxHash(ctx context.Context, txHash string) (*OrdersByTxHashResponse, int, error) {
if txHash == "" {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_tx_hash", Description: "transaction hash not provided"}
}
endpoint := fmt.Sprintf("/transactions/%s/orders", txHash)
var dataRes OrdersByTxHashResponse
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 OrdersByTxHashResponse []struct {
CreationDate time.Time `json:"creationDate"`
Owner string `json:"owner"`
UID string `json:"uid"`
AvailableBalance interface{} `json:"availableBalance"`
ExecutedBuyAmount string `json:"executedBuyAmount"`
ExecutedSellAmount string `json:"executedSellAmount"`
ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"`
ExecutedFeeAmount string `json:"executedFeeAmount"`
Invalidated bool `json:"invalidated"`
Status string `json:"status"`
Class string `json:"class"`
SettlementContract string `json:"settlementContract"`
FullFeeAmount string `json:"fullFeeAmount"`
IsLiquidityOrder bool `json:"isLiquidityOrder"`
SellToken string `json:"sellToken"`
BuyToken string `json:"buyToken"`
Receiver string `json:"receiver"`
SellAmount string `json:"sellAmount"`
BuyAmount string `json:"buyAmount"`
ValidTo int `json:"validTo"`
AppData string `json:"appData"`
FeeAmount string `json:"feeAmount"`
Kind string `json:"kind"`
PartiallyFillable bool `json:"partiallyFillable"`
SellTokenBalance string `json:"sellTokenBalance"`
BuyTokenBalance string `json:"buyTokenBalance"`
SigningScheme string `json:"signingScheme"`
Signature string `json:"signature"`
Interactions struct {
Pre []interface{} `json:"pre"`
} `json:"interactions"`
}
// GetOrdersByUser - Get orders of a user paginated
func (c *Client) GetOrdersByUser(ctx context.Context, userAddress string, opts *OrdersPaginated) (*OrdersByUserResponse, int, error) {
if userAddress == "" {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_user_address", Description: "user address not provided"}
}
endpoint := fmt.Sprintf("/account/%s/orders", userAddress)
var queries = make(map[string]interface{})
if opts != nil {
if opts.Limit != "" {
queries["limit"] = opts.Limit
}
if opts.Offset != "" {
queries["offset"] = opts.Offset
}
}
var dataRes OrdersByUserResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil, queries)
if err != nil {
return nil, statusCode, &ErrorCowResponse{Code: statusCode, ErrorType: "do_request_error", Description: err.Error()}
}
return &dataRes, statusCode, nil
}
type OrdersPaginated struct {
Offset string
Limit string
}
type OrdersByUserResponse []struct {
CreationDate time.Time `json:"creationDate"`
Owner string `json:"owner"`
UID string `json:"uid"`
AvailableBalance interface{} `json:"availableBalance"`
ExecutedBuyAmount string `json:"executedBuyAmount"`
ExecutedSellAmount string `json:"executedSellAmount"`
ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"`
ExecutedFeeAmount string `json:"executedFeeAmount"`
Invalidated bool `json:"invalidated"`
Status string `json:"status"`
Class string `json:"class"`
SettlementContract string `json:"settlementContract"`
FullFeeAmount string `json:"fullFeeAmount"`
IsLiquidityOrder bool `json:"isLiquidityOrder"`
SellToken string `json:"sellToken"`
BuyToken string `json:"buyToken"`
Receiver string `json:"receiver"`
SellAmount string `json:"sellAmount"`
BuyAmount string `json:"buyAmount"`
ValidTo int `json:"validTo"`
AppData string `json:"appData"`
FeeAmount string `json:"feeAmount"`
Kind string `json:"kind"`
PartiallyFillable bool `json:"partiallyFillable"`
SellTokenBalance string `json:"sellTokenBalance"`
BuyTokenBalance string `json:"buyTokenBalance"`
SigningScheme string `json:"signingScheme"`
Signature string `json:"signature"`
Interactions struct {
Pre []interface{} `json:"pre"`
} `json:"interactions"`
}