orders: Add derive modify struct method from order.Detail (#948)

* orders: Add derive modify struct method to order.Detail and then subsequent method to derive and standardize response details

* exchanges: call modify method in wrappers

* linter: fixes

* engine/wsroutineman: remove print summary

* glorious: nits, removed modifyOrder functionality for Bithumb. There are not docs to support this.

* Update exchanges/order/orders.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2022-05-30 14:38:21 +10:00
committed by GitHub
parent 293d6104ed
commit a63aa6b616
42 changed files with 298 additions and 427 deletions

View File

@@ -405,9 +405,9 @@ func (m *OrderManager) Modify(ctx context.Context, mod *order.Modify) (*order.Mo
}
m.orderStore.commsManager.PushEvent(base.Event{
Type: "order",
Message: fmt.Sprintf(message, mod.Exchange, res.ID),
Message: fmt.Sprintf(message, mod.Exchange, res.OrderID),
})
return &order.ModifyResponse{OrderID: res.ID}, err
return &order.ModifyResponse{OrderID: res.OrderID}, err
}
// Submit will take in an order struct, send it to the exchange and
@@ -892,7 +892,7 @@ func (s *store) updateExisting(od *order.Detail) error {
// modifyExisting depends on mod.Exchange and given ID to uniquely identify an order and
// modify it.
func (s *store) modifyExisting(id string, mod *order.Modify) error {
func (s *store) modifyExisting(id string, mod *order.ModifyResponse) error {
s.m.Lock()
defer s.m.Unlock()
r, ok := s.Orders[strings.ToLower(mod.Exchange)]
@@ -903,7 +903,7 @@ func (s *store) modifyExisting(id string, mod *order.Modify) error {
if r[x].ID != id {
continue
}
r[x].UpdateOrderFromModify(mod)
r[x].UpdateOrderFromModifyResponse(mod)
if !r[x].AssetType.IsFutures() {
return nil
}

View File

@@ -83,10 +83,13 @@ func (f omfExchange) GetActiveOrders(ctx context.Context, req *order.GetOrdersRe
}}, nil
}
func (f omfExchange) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) {
ans := *action
ans.ID = "modified_order_id"
return &ans, nil
func (f omfExchange) ModifyOrder(ctx context.Context, action *order.Modify) (*order.ModifyResponse, error) {
ans, err := action.DeriveModifyResponse()
if err != nil {
return nil, err
}
ans.OrderID = "modified_order_id"
return ans, nil
}
func TestSetupOrderManager(t *testing.T) {
@@ -317,12 +320,12 @@ func TestStore_modifyOrder(t *testing.T) {
t.Error(err)
}
err = m.orderStore.modifyExisting("fake_order_id", &order.Modify{
err = m.orderStore.modifyExisting("fake_order_id", &order.ModifyResponse{
Exchange: testExchange,
ID: "another_fake_order_id",
Price: 16,
Amount: 256,
OrderID: "another_fake_order_id",
Price: 16,
Amount: 256,
})
if err != nil {
t.Error(err)

View File

@@ -233,12 +233,12 @@ func (m *websocketRoutineManager) websocketDataHandler(exchName string, data int
}
m.syncer.PrintOrderbookSummary(base, "websocket", nil)
case *order.Detail:
m.printOrderSummary(d)
if !m.orderManager.Exists(d) {
err := m.orderManager.Add(d)
if err != nil {
return err
}
m.printOrderSummary(d, false)
} else {
od, err := m.orderManager.GetByExchangeAndID(d.Exchange, d.ID)
if err != nil {
@@ -250,17 +250,7 @@ func (m *websocketRoutineManager) websocketDataHandler(exchName string, data int
if err != nil {
return err
}
}
case *order.Modify:
m.printOrderChangeSummary(d)
od, err := m.orderManager.GetByExchangeAndID(d.Exchange, d.ID)
if err != nil {
return err
}
od.UpdateOrderFromModify(d)
err = m.orderManager.UpdateExistingOrder(od)
if err != nil {
return err
m.printOrderSummary(d, true)
}
case order.ClassificationError:
return fmt.Errorf("%w %s", d.Err, d.Error())
@@ -299,37 +289,21 @@ func (m *websocketRoutineManager) FormatCurrency(p currency.Pair) currency.Pair
m.currencyConfig.CurrencyPairFormat.Uppercase)
}
// printOrderChangeSummary this function will be deprecated when a order manager
// update is done.
func (m *websocketRoutineManager) printOrderChangeSummary(o *order.Modify) {
if m == nil || atomic.LoadInt32(&m.started) == 0 || o == nil {
return
}
log.Debugf(log.WebsocketMgr,
"Order Change: %s %s %s %s %s %s OrderID:%s ClientOrderID:%s Price:%f Amount:%f Executed Amount:%f Remaining Amount:%f",
o.Exchange,
o.AssetType,
o.Pair,
o.Status,
o.Type,
o.Side,
o.ID,
o.ClientOrderID,
o.Price,
o.Amount,
o.ExecutedAmount,
o.RemainingAmount)
}
// printOrderSummary this function will be deprecated when a order manager
// update is done.
func (m *websocketRoutineManager) printOrderSummary(o *order.Detail) {
func (m *websocketRoutineManager) printOrderSummary(o *order.Detail, isUpdate bool) {
if m == nil || atomic.LoadInt32(&m.started) == 0 || o == nil {
return
}
orderNotif := "New Order:"
if isUpdate {
orderNotif = "Order Change:"
}
log.Debugf(log.WebsocketMgr,
"New Order: %s %s %s %s %s %s OrderID:%s ClientOrderID:%s Price:%f Amount:%f Executed Amount:%f Remaining Amount:%f",
"%s %s %s %s %s %s %s OrderID:%s ClientOrderID:%s Price:%f Amount:%f Executed Amount:%f Remaining Amount:%f",
orderNotif,
o.Exchange,
o.AssetType,
o.Pair,

View File

@@ -199,7 +199,7 @@ func TestWebsocketRoutineManagerHandleData(t *testing.T) {
t.Error("Bad pipeline")
}
err = m.websocketDataHandler(exchName, &order.Modify{
err = m.websocketDataHandler(exchName, &order.Detail{
Exchange: "Bitstamp",
ID: orderID,
Status: order.Active,