Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order update request through websocket #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,43 @@ func (o *OrderNewRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(&body)
}

// OrderUpdateRequest represents an posted order to be updated on the bitfinex via
// the websocket service.
type OrderUpdateRequest struct {
ID int64 `json:"id"`
GID int64 `json:"gid,omitempty"`
Amount float64 `json:"amount,string,omitempty"`
Price float64 `json:"price,string,omitempty"`
Delta float64 `json:"delta,string,omitempty"`
PriceAuxLimit float64 `json:"price_aux_limit,string,omitempty"`
PriceTrailing float64 `json:"price_trailing,string,omitempty"`
}

// MarshalJSON converts the order object into the format required by the bitfinex
// websocket service.
func (o *OrderUpdateRequest) MarshalJSON() ([]byte, error) {
aux := struct {
ID int64 `json:"id"`
GID int64 `json:"gid,omitempty"`
Amount float64 `json:"amount,string,omitempty"`
Price float64 `json:"price,string,omitempty"`
Delta float64 `json:"delta,string,omitempty"`
PriceAuxLimit float64 `json:"price_aux_limit,string,omitempty"`
PriceTrailing float64 `json:"price_trailing,string,omitempty"`
}{
ID: o.ID,
GID: o.GID,
Amount: o.Amount,
Price: o.Price,
Delta: o.Delta,
PriceAuxLimit: o.PriceAuxLimit,
PriceTrailing: o.PriceTrailing,
}

body := []interface{}{0, "ou", nil, aux}
return json.Marshal(&body)
}

// OrderCancelRequest represents an order cancel request.
// An order can be cancelled using the internal ID or a
// combination of Client ID (CID) and the daten for the given
Expand Down
5 changes: 5 additions & 0 deletions v2/websocket/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func (c *Client) SubmitOrder(ctx context.Context, order *bitfinex.OrderNewReques
return c.asynchronous.Send(ctx, order)
}

// UpdateOrder sends an update order requst.
func (c *Client) UpdateOrder(ctx context.Context, order *bitfinex.OrderUpdateRequest) error {
return c.asynchronous.Send(ctx, order)
}

// SubmitCancel sends a cancel request.
func (c *Client) SubmitCancel(ctx context.Context, cancel *bitfinex.OrderCancelRequest) error {
return c.asynchronous.Send(ctx, cancel)
Expand Down