Skip to content

Commit

Permalink
OrderInput added
Browse files Browse the repository at this point in the history
  • Loading branch information
aliereno committed Apr 19, 2020
1 parent 58ad3a5 commit 63005ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ func main() {

_, _ = api.Balance()

_, _ = api.Quantity(0.001).
Price(50000).
StopPrice(0).
OrderMethod("limit").
PairSymbol(btcturk.BTCTRY).
Buy()
_, _ = api.Buy(&btcturk.OrderInput{
Quantity: 0.001,
Price: 50000,
StopPrice: 0,
NewOrderClientId: "Go test",
OrderMethod: "limit",
PairSymbol: btcturk.BTCTRY,
})
}

```
Expand Down
27 changes: 20 additions & 7 deletions btcturk/user_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,21 @@ type OrderType struct {
Amount float64 `json:"amount"`
}

type OrderInput struct {
Quantity float64 `json:"quantity"`
Price float64 `json:"price"`
StopPrice float64 `json:"stopPrice"`
NewOrderClientId string `json:"newOrderClientId"`
OrderMethod string `json:"orderMethod"`
OrderType string `json:"orderType"`
PairSymbol string `json:"pairSymbol"`
}

func (c *Client) OpenOrders() ([]OpenOrders, error) {
jsonString, err := json.Marshal(c.params)
if err != nil {
return []OpenOrders{}, err
}
req, err := c.newRequest("GET", "/api/v1/openOrders", bytes.NewBuffer(jsonString))
if err != nil {
return []OpenOrders{}, err
Expand Down Expand Up @@ -108,7 +121,7 @@ func (c *Client) CancelOrder() (bool, error) {

var response GeneralResponse

// TODO
// TODO : solve
// API returns `"code":""`
// my code expects `"code":0` an integer
// so it will return error
Expand All @@ -119,9 +132,9 @@ func (c *Client) CancelOrder() (bool, error) {
return response.Success, nil
}

func (c *Client) Buy() (OrderType, error) {
c.params.Add("orderType", "buy")
jsonString, err := json.Marshal(c.params)
func (c *Client) Buy(o *OrderInput) (OrderType, error) {
o.OrderType = "buy"
jsonString, err := json.Marshal(o)
if err != nil {
return OrderType{}, err
}
Expand All @@ -142,9 +155,9 @@ func (c *Client) Buy() (OrderType, error) {
return response, nil
}

func (c *Client) Sell() (OrderType, error) {
c.params.Add("orderType", "sell")
jsonString, err := json.Marshal(c.params)
func (c *Client) Sell(o *OrderInput) (OrderType, error) {
o.OrderType = "sell"
jsonString, err := json.Marshal(o)
if err != nil {
return OrderType{}, err
}
Expand Down

0 comments on commit 63005ce

Please sign in to comment.