mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 07:26:47 +00:00
Engine improvements
This commit is contained in:
@@ -303,12 +303,18 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var p = currency.Pair{
|
||||
Delimiter: "",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USDT,
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
}
|
||||
response, err := i.SubmitOrder(p, exchange.BuyOrderSide, exchange.LimitOrderType, 1, 10, "hi")
|
||||
response, err := i.SubmitOrder(orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
|
||||
@@ -273,10 +273,17 @@ func (i *ItBit) GetExchangeHistory(p currency.Pair, assetType assets.AssetType)
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (i *ItBit) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (i *ItBit) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var wallet string
|
||||
if order == nil {
|
||||
return submitOrderResponse, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var wallet string
|
||||
wallets, err := i.GetWallets(url.Values{})
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
@@ -285,8 +292,8 @@ func (i *ItBit) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType
|
||||
// Determine what wallet ID to use if there is any actual available currency to make the trade!
|
||||
for _, i := range wallets {
|
||||
for j := range i.Balances {
|
||||
if i.Balances[j].Currency == p.Base.String() &&
|
||||
i.Balances[j].AvailableBalance >= amount {
|
||||
if i.Balances[j].Currency == order.Pair.Base.String() &&
|
||||
i.Balances[j].AvailableBalance >= order.Amount {
|
||||
wallet = i.ID
|
||||
}
|
||||
}
|
||||
@@ -295,23 +302,21 @@ func (i *ItBit) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType
|
||||
if wallet == "" {
|
||||
return submitOrderResponse,
|
||||
fmt.Errorf("no wallet found with currency: %s with amount >= %v",
|
||||
p.Base,
|
||||
amount)
|
||||
order.Pair.Base,
|
||||
order.Amount)
|
||||
}
|
||||
|
||||
response, err := i.PlaceOrder(wallet,
|
||||
side.ToString(),
|
||||
orderType.ToString(),
|
||||
p.Base.String(),
|
||||
amount,
|
||||
price,
|
||||
p.String(),
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
order.Pair.Base.String(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
order.Pair.String(),
|
||||
"")
|
||||
|
||||
if response.ID != "" {
|
||||
submitOrderResponse.OrderID = response.ID
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user