mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
orders: Add methods to derive SubmitResponse and Detail types (#955)
* orders: deprecate SubmitResponse return and change to *order.Detail construct detail from order.Submit struct * orders: add coverage, fix tests * coinut: rm test for checking * orders: revert change for return and change field ID to a more explicit name OrderID * orders: Add method to see if the order was placed * order: change field name in Cancel type to be more explicit * orders: standardize field -> OrderID * backtester: populate change * orders: add test * gctscript: fix field name * linter: fix issues * linter: more fixes * linter: forever * exchanges_tests: populate order.Submit field exchange name * Update exchanges/order/order_types.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/order/orders.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * glorious: nits * thrasher: nits Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -322,7 +322,7 @@ func ExchangeOrderQuery(args ...objects.Object) (objects.Object, error) {
|
||||
|
||||
data := make(map[string]objects.Object, 14)
|
||||
data["exchange"] = &objects.String{Value: orderDetails.Exchange}
|
||||
data["id"] = &objects.String{Value: orderDetails.ID}
|
||||
data["id"] = &objects.String{Value: orderDetails.OrderID}
|
||||
data["accountid"] = &objects.String{Value: orderDetails.AccountID}
|
||||
data["currencypair"] = &objects.String{Value: orderDetails.Pair.String()}
|
||||
data["price"] = &objects.Float{Value: orderDetails.Price}
|
||||
@@ -480,11 +480,7 @@ func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
|
||||
data := make(map[string]objects.Object, 2)
|
||||
data["orderid"] = &objects.String{Value: rtn.OrderID}
|
||||
if rtn.IsOrderPlaced {
|
||||
data["isorderplaced"] = objects.TrueValue
|
||||
} else {
|
||||
data["isorderplaced"] = objects.FalseValue
|
||||
}
|
||||
data["isorderplaced"] = objects.TrueValue
|
||||
|
||||
return &objects.Map{
|
||||
Value: data,
|
||||
|
||||
@@ -23,15 +23,10 @@ const (
|
||||
)
|
||||
|
||||
// Wrapper instance of GCT to use for modules
|
||||
var Wrapper GCT
|
||||
|
||||
// GCT interface requirements
|
||||
type GCT interface {
|
||||
Exchange
|
||||
}
|
||||
var Wrapper GCTExchange
|
||||
|
||||
// Exchange interface requirements
|
||||
type Exchange interface {
|
||||
type GCTExchange interface {
|
||||
Exchanges(enabledOnly bool) []string
|
||||
IsEnabled(exch string) bool
|
||||
Orderbook(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error)
|
||||
@@ -48,6 +43,6 @@ type Exchange interface {
|
||||
}
|
||||
|
||||
// SetModuleWrapper link the wrapper and interface to use for modules
|
||||
func SetModuleWrapper(wrapper GCT) {
|
||||
func SetModuleWrapper(wrapper GCTExchange) {
|
||||
Wrapper = wrapper
|
||||
}
|
||||
|
||||
@@ -94,7 +94,14 @@ func (e Exchange) SubmitOrder(ctx context.Context, submit *order.Submit) (*order
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.SubmitResponse, nil
|
||||
resp, err := submit.DeriveSubmitResponse(r.OrderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Status = r.Status
|
||||
resp.Trades = make([]order.TradeHistory, len(r.Trades))
|
||||
copy(resp.Trades, r.Trades)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CancelOrder wrapper to cancel order on exchange
|
||||
@@ -106,7 +113,7 @@ func (e Exchange) CancelOrder(ctx context.Context, exch, orderID string, cp curr
|
||||
|
||||
cancel := &order.Cancel{
|
||||
AccountID: orderDetails.AccountID,
|
||||
ID: orderDetails.ID,
|
||||
OrderID: orderDetails.OrderID,
|
||||
Pair: orderDetails.Pair,
|
||||
Side: orderDetails.Side,
|
||||
AssetType: orderDetails.AssetType,
|
||||
|
||||
@@ -122,7 +122,7 @@ func (w Wrapper) QueryOrder(ctx context.Context, exch, _ string, _ currency.Pair
|
||||
return &order.Detail{
|
||||
Exchange: exch,
|
||||
AccountID: "hello",
|
||||
ID: "1",
|
||||
OrderID: "1",
|
||||
Pair: pair,
|
||||
Side: order.Ask,
|
||||
Type: order.Limit,
|
||||
@@ -157,16 +157,17 @@ func (w Wrapper) SubmitOrder(ctx context.Context, o *order.Submit) (*order.Submi
|
||||
return nil, errTestFailed
|
||||
}
|
||||
|
||||
tempOrder := &order.SubmitResponse{
|
||||
IsOrderPlaced: false,
|
||||
OrderID: o.Exchange,
|
||||
resp, err := o.DeriveSubmitResponse(o.Exchange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.Status = order.Rejected
|
||||
if o.Exchange == "true" {
|
||||
tempOrder.IsOrderPlaced = true
|
||||
resp.Status = order.New
|
||||
}
|
||||
|
||||
return tempOrder, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CancelOrder validator for test execution/scripts
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// GetWrapper returns the instance of each wrapper to use
|
||||
func GetWrapper() modules.GCT {
|
||||
func GetWrapper() modules.GCTExchange {
|
||||
if validator.IsTestExecution.Load() == true {
|
||||
return validator.Wrapper{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user