mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 07:26:48 +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:
@@ -416,6 +416,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
Exchange: b.Name,
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.LTC,
|
||||
@@ -428,7 +429,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := b.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")
|
||||
@@ -443,7 +444,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,
|
||||
@@ -467,7 +468,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,
|
||||
@@ -510,7 +511,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = b.ModifyOrder(context.Background(), &order.Modify{
|
||||
ID: "1337",
|
||||
OrderID: "1337",
|
||||
Price: 100,
|
||||
Amount: 1000,
|
||||
Side: order.Sell,
|
||||
|
||||
@@ -473,15 +473,14 @@ func (b *Bithumb) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: Fill this out to support limit orders
|
||||
func (b *Bithumb) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
func (b *Bithumb) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fPair, err := b.FormatExchangeCurrency(s.Pair, s.AssetType)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orderID string
|
||||
@@ -489,24 +488,18 @@ func (b *Bithumb) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi
|
||||
var result MarketBuy
|
||||
result, err = b.MarketBuyOrder(ctx, fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
orderID = result.OrderID
|
||||
} else if s.Side == order.Sell {
|
||||
var result MarketSell
|
||||
result, err = b.MarketSellOrder(ctx, fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
return nil, err
|
||||
}
|
||||
orderID = result.OrderID
|
||||
}
|
||||
if orderID != "" {
|
||||
submitOrderResponse.OrderID = orderID
|
||||
submitOrderResponse.FullyMatched = true
|
||||
}
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
|
||||
return submitOrderResponse, nil
|
||||
return s.DeriveSubmitResponse(orderID)
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
@@ -521,9 +514,7 @@ func (b *Bithumb) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := b.CancelTrade(ctx, o.Side.String(),
|
||||
o.ID,
|
||||
o.Pair.Base.String())
|
||||
_, err := b.CancelTrade(ctx, o.Side.String(), o.OrderID, o.Pair.Base.String())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -692,7 +683,7 @@ func (b *Bithumb) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ExecutedAmount: resp.Data[i].Units - resp.Data[i].UnitsRemaining,
|
||||
ID: resp.Data[i].OrderID,
|
||||
OrderID: resp.Data[i].OrderID,
|
||||
Date: resp.Data[i].OrderDate.Time(),
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
@@ -755,7 +746,7 @@ func (b *Bithumb) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
ExecutedAmount: resp.Data[i].Units - resp.Data[i].UnitsRemaining,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
OrderID: resp.Data[i].OrderID,
|
||||
Date: resp.Data[i].OrderDate.Time(),
|
||||
Price: resp.Data[i].Price,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
|
||||
Reference in New Issue
Block a user