mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 23:16:54 +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:
@@ -320,6 +320,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
Exchange: i.Name,
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
@@ -332,7 +333,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := i.SubmitOrder(context.Background(), orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
if areTestAPIKeysSet() && (err != nil || response.Status != order.New) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
@@ -346,7 +347,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
ID: "1",
|
||||
OrderID: "1",
|
||||
WalletAddress: core.BitcoinDonationAddress,
|
||||
AccountID: "1",
|
||||
Pair: currencyPair,
|
||||
@@ -370,7 +371,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
ID: "1",
|
||||
OrderID: "1",
|
||||
WalletAddress: core.BitcoinDonationAddress,
|
||||
AccountID: "1",
|
||||
Pair: currencyPair,
|
||||
|
||||
@@ -372,16 +372,15 @@ func (i *ItBit) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.It
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wallet string
|
||||
wallets, err := i.GetWallets(ctx, url.Values{})
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Determine what wallet ID to use if there is any actual available currency to make the trade!
|
||||
@@ -395,7 +394,7 @@ func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR
|
||||
}
|
||||
|
||||
if wallet == "" {
|
||||
return submitOrderResponse,
|
||||
return nil,
|
||||
fmt.Errorf("no wallet found with currency: %s with amount >= %v",
|
||||
s.Pair.Base,
|
||||
s.Amount)
|
||||
@@ -403,7 +402,7 @@ func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR
|
||||
|
||||
fPair, err := i.FormatExchangeCurrency(s.Pair, s.AssetType)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := i.PlaceOrder(ctx,
|
||||
@@ -416,17 +415,16 @@ func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR
|
||||
fPair.String(),
|
||||
"")
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
if response.ID != "" {
|
||||
submitOrderResponse.OrderID = response.ID
|
||||
subResp, err := s.DeriveSubmitResponse(response.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.AmountFilled == s.Amount {
|
||||
submitOrderResponse.FullyMatched = true
|
||||
subResp.Status = order.Filled
|
||||
}
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
return submitOrderResponse, nil
|
||||
return subResp, nil
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
@@ -440,7 +438,7 @@ func (i *ItBit) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
return i.CancelExistingOrder(ctx, o.WalletAddress, o.ID)
|
||||
return i.CancelExistingOrder(ctx, o.WalletAddress, o.OrderID)
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
@@ -572,7 +570,7 @@ func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
ID: allOrders[j].ID,
|
||||
OrderID: allOrders[j].ID,
|
||||
Side: side,
|
||||
Amount: allOrders[j].Amount,
|
||||
ExecutedAmount: allOrders[j].AmountFilled,
|
||||
@@ -652,7 +650,7 @@ func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest
|
||||
}
|
||||
|
||||
detail := order.Detail{
|
||||
ID: allOrders[j].ID,
|
||||
OrderID: allOrders[j].ID,
|
||||
Side: side,
|
||||
Status: status,
|
||||
Amount: allOrders[j].Amount,
|
||||
|
||||
Reference in New Issue
Block a user