Skip to content

Commit

Permalink
Bitstamp: Avoid allocating again in handleWSOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Sep 15, 2023
1 parent 681dbf2 commit 9a17177
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions exchanges/bitstamp/bitstamp_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ func (b *Bitstamp) handleWSOrder(wsResp *websocketResponse, msg []byte) error {
return err
}

o := r.Order
if o.ID == 0 && o.ClientOrderID == "" {
if r.Order.ID == 0 && r.Order.ClientOrderID == "" {
return fmt.Errorf("unable to parse an order id from order msg: %s", msg)
}

Expand All @@ -197,32 +196,32 @@ func (b *Bitstamp) handleWSOrder(wsResp *websocketResponse, msg []byte) error {
case "order_created":
status = order.New
case "order_changed":
if o.ExecutedAmount > 0 {
if r.Order.ExecutedAmount > 0 {
status = order.PartiallyFilled
}
case "order_deleted":
if o.RemainingAmount == 0 && o.Amount > 0 {
if r.Order.RemainingAmount == 0 && r.Order.Amount > 0 {
status = order.Filled
} else {
status = order.Cancelled
}
}

// o.ExecutedAmount is an atomic partial fill amount; We want total
executedAmount := o.Amount - o.RemainingAmount
// r.Order.ExecutedAmount is an atomic partial fill amount; We want total
executedAmount := r.Order.Amount - r.Order.RemainingAmount

d := &order.Detail{
Price: o.Price,
Amount: o.Amount,
RemainingAmount: o.RemainingAmount,
Price: r.Order.Price,
Amount: r.Order.Amount,
RemainingAmount: r.Order.RemainingAmount,
ExecutedAmount: executedAmount,
Exchange: b.Name,
OrderID: o.IDStr,
ClientOrderID: o.ClientOrderID,
Side: o.Side.Side(),
OrderID: r.Order.IDStr,
ClientOrderID: r.Order.ClientOrderID,
Side: r.Order.Side.Side(),
Status: status,
AssetType: asset.Spot,
Date: o.Microtimestamp.Time(),
Date: r.Order.Microtimestamp.Time(),
Pair: wsResp.pair,
}

Expand Down

0 comments on commit 9a17177

Please sign in to comment.