forked from preichenberger/go-coinbasepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.go
70 lines (59 loc) · 1.74 KB
/
order.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
package coinbase
import (
"fmt"
)
type Order struct {
Type string `json:"type"`
Size float64 `json:"size,string"`
Side string `json:"side"`
ProductId string `json:"product_id"`
ClientOID string `json:"client_oid,omitempty"`
Stp string `json:"stp,omitempty"`
// Limit Order
Price float64 `json:"price,string,omitempty"`
TimeInForce string `json:"time_in_force,omitempty"`
PostOnly bool `json:"post_only,omitempty"`
// Market Order
Funds float64 `json:"funds,string,omitempty"`
// Response Fields
Id string `json:"id"`
Status string `json:"status,omitempty"`
Settled bool `json:"settled,omitempty"`
DoneReason string `json:"done_reason,omitempty"`
CreatedAt Time `json:"created_at,string,omitempty"`
}
type ListOrdersParams struct {
Status string
Pagination PaginationParams
}
func (c *Client) CreateOrder(newOrder *Order) (Order, error) {
var savedOrder Order
if len(newOrder.Type) == 0 {
newOrder.Type = "limit"
}
url := fmt.Sprintf("/orders")
_, err := c.Request("POST", url, newOrder, &savedOrder)
return savedOrder, err
}
func (c *Client) CancelOrder(id string) error {
url := fmt.Sprintf("/orders/%s", id)
_, err := c.Request("DELETE", url, nil, nil)
return err
}
func (c *Client) GetOrder(id string) (Order, error) {
var savedOrder Order
url := fmt.Sprintf("/orders/%s", id)
_, err := c.Request("GET", url, nil, &savedOrder)
return savedOrder, err
}
func (c *Client) ListOrders(p ...ListOrdersParams) *Cursor {
paginationParams := PaginationParams{}
if len(p) > 0 {
paginationParams = p[0].Pagination
if p[0].Status != "" {
paginationParams.AddExtraParam("status", p[0].Status)
}
}
return NewCursor(c, "GET", fmt.Sprintf("/orders"),
&paginationParams)
}