mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
Engine improvements
This commit is contained in:
@@ -246,12 +246,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.USD,
|
||||
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 := c.SubmitOrder(p, exchange.BuyOrderSide, exchange.LimitOrderType, 1, 10, "1234234")
|
||||
response, err := c.SubmitOrder(orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package coinut
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -328,33 +327,41 @@ func (c *COINUT) GetExchangeHistory(p currency.Pair, assetType assets.AssetType)
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (c *COINUT) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
func (c *COINUT) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var err error
|
||||
var APIresponse interface{}
|
||||
isBuyOrder := side == exchange.BuyOrderSide
|
||||
clientIDInt, err := strconv.ParseUint(clientID, 0, 32)
|
||||
clientIDUint := uint32(clientIDInt)
|
||||
if order == nil {
|
||||
return submitOrderResponse, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var APIresponse interface{}
|
||||
isBuyOrder := order.OrderSide == exchange.BuyOrderSide
|
||||
clientIDInt, err := strconv.ParseUint(order.ClientID, 0, 32)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
clientIDUint := uint32(clientIDInt)
|
||||
|
||||
// Need to get the ID of the currency sent
|
||||
instruments, err := c.GetInstruments()
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
currencyArray := instruments.Instruments[p.String()]
|
||||
currencyArray := instruments.Instruments[order.Pair.String()]
|
||||
currencyID := currencyArray[0].InstID
|
||||
|
||||
switch orderType {
|
||||
switch order.OrderType {
|
||||
case exchange.LimitOrderType:
|
||||
APIresponse, err = c.NewOrder(currencyID, amount, price, isBuyOrder, clientIDUint)
|
||||
APIresponse, err = c.NewOrder(currencyID, order.Amount, order.Price,
|
||||
isBuyOrder, clientIDUint)
|
||||
case exchange.MarketOrderType:
|
||||
APIresponse, err = c.NewOrder(currencyID, amount, 0, isBuyOrder, clientIDUint)
|
||||
default:
|
||||
return submitOrderResponse, errors.New("unsupported order type")
|
||||
APIresponse, err = c.NewOrder(currencyID, order.Amount, 0, isBuyOrder,
|
||||
clientIDUint)
|
||||
}
|
||||
|
||||
switch apiResp := APIresponse.(type) {
|
||||
|
||||
Reference in New Issue
Block a user