Engine QA - Order update (#372)

Engine QA - Order update
This commit is contained in:
Ryan O'Hara-Reid
2019-10-30 14:06:48 +11:00
committed by Adrian Gallagher
parent 242b02c382
commit 63a9e9fcb1
89 changed files with 3077 additions and 2876 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
log "github.com/thrasher-corp/gocryptotrader/logger"
)
@@ -288,7 +289,7 @@ func (c *CoinbasePro) GetHolds(accountID string) ([]AccountHolds, error) {
func (c *CoinbasePro) PlaceLimitOrder(clientRef string, price, amount float64, side, timeInforce, cancelAfter, productID, stp string, postOnly bool) (string, error) {
resp := GeneralizedOrderResponse{}
req := make(map[string]interface{})
req["type"] = exchange.LimitOrderType.ToLower().ToString()
req["type"] = order.Limit.Lower()
req["price"] = strconv.FormatFloat(price, 'f', -1, 64)
req["size"] = strconv.FormatFloat(amount, 'f', -1, 64)
req["side"] = side
@@ -339,7 +340,7 @@ func (c *CoinbasePro) PlaceMarketOrder(clientRef string, size, funds float64, si
req := make(map[string]interface{})
req["side"] = side
req["product_id"] = productID
req["type"] = exchange.MarketOrderType.ToLower().ToString()
req["type"] = order.Market.Lower()
if size != 0 {
req["size"] = strconv.FormatFloat(size, 'f', -1, 64)

View File

@@ -9,6 +9,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
)
@@ -382,8 +383,8 @@ func TestGetActiveOrders(t *testing.T) {
c.SetDefaults()
TestSetup(t)
var getOrdersRequest = exchange.GetOrdersRequest{
OrderType: exchange.AnyOrderType,
var getOrdersRequest = order.GetOrdersRequest{
OrderType: order.AnyType,
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
currency.LTC)},
}
@@ -400,8 +401,8 @@ func TestGetOrderHistory(t *testing.T) {
c.SetDefaults()
TestSetup(t)
var getOrdersRequest = exchange.GetOrdersRequest{
OrderType: exchange.AnyOrderType,
var getOrdersRequest = order.GetOrdersRequest{
OrderType: order.AnyType,
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
currency.LTC)},
}
@@ -428,14 +429,14 @@ func TestSubmitOrder(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var orderSubmission = &exchange.OrderSubmission{
var orderSubmission = &order.Submit{
Pair: currency.Pair{
Delimiter: "-",
Base: currency.BTC,
Quote: currency.USD,
},
OrderSide: exchange.BuyOrderSide,
OrderType: exchange.LimitOrderType,
OrderSide: order.Buy,
OrderType: order.Limit,
Price: 1,
Amount: 1,
ClientID: "meowOrder",
@@ -459,7 +460,7 @@ func TestCancelExchangeOrder(t *testing.T) {
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = &exchange.OrderCancellation{
var orderCancellation = &order.Cancel{
OrderID: "1",
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
AccountID: "1",
@@ -486,7 +487,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = &exchange.OrderCancellation{
var orderCancellation = &order.Cancel{
OrderID: "1",
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
AccountID: "1",
@@ -502,13 +503,13 @@ func TestCancelAllExchangeOrders(t *testing.T) {
t.Errorf("Could not cancel orders: %v", err)
}
if len(resp.OrderStatus) > 0 {
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
if len(resp.Status) > 0 {
t.Errorf("%v orders failed to cancel", len(resp.Status))
}
}
func TestModifyOrder(t *testing.T) {
_, err := c.ModifyOrder(&exchange.ModifyOrder{})
_, err := c.ModifyOrder(&order.Modify{})
if err == nil {
t.Error("ModifyOrder() Expected error")
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
@@ -240,7 +241,7 @@ func (c *CoinbasePro) ProcessUpdate(update WebsocketL2Update) error {
price, _ := strconv.ParseFloat(update.Changes[i][1].(string), 64)
volume, _ := strconv.ParseFloat(update.Changes[i][2].(string), 64)
if update.Changes[i][0].(string) == exchange.BuyOrderSide.ToLower().ToString() {
if update.Changes[i][0].(string) == order.Buy.Lower() {
bids = append(bids, orderbook.Item{Price: price, Amount: volume})
} else {
asks = append(asks, orderbook.Item{Price: price, Amount: volume})

View File

@@ -12,6 +12,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
@@ -186,7 +187,8 @@ func (c *CoinbasePro) Start(wg *sync.WaitGroup) {
// Run implements the coinbasepro wrapper
func (c *CoinbasePro) Run() {
if c.Verbose {
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n",
log.Debugf(log.ExchangeSys,
"%s Websocket: %s. (url: %s).\n",
c.GetName(),
common.IsEnabled(c.Websocket.IsEnabled()),
coinbaseproWebsocketURL)
@@ -369,34 +371,30 @@ func (c *CoinbasePro) GetExchangeHistory(p currency.Pair, assetType asset.Item)
}
// SubmitOrder submits a new order
func (c *CoinbasePro) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
var submitOrderResponse exchange.SubmitOrderResponse
if order == nil {
return submitOrderResponse, exchange.ErrOrderSubmissionIsNil
}
if err := order.Validate(); err != nil {
func (c *CoinbasePro) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
var submitOrderResponse order.SubmitResponse
if err := s.Validate(); err != nil {
return submitOrderResponse, err
}
var response string
var err error
switch order.OrderType {
case exchange.MarketOrderType:
switch s.OrderType {
case order.Market:
response, err = c.PlaceMarketOrder("",
order.Amount,
order.Amount,
order.OrderSide.ToString(),
c.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
s.Amount,
s.Amount,
s.OrderSide.String(),
c.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
"")
case exchange.LimitOrderType:
case order.Limit:
response, err = c.PlaceLimitOrder("",
order.Price,
order.Amount,
order.OrderSide.ToString(),
s.Price,
s.Amount,
s.OrderSide.String(),
"",
"",
c.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
c.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
"",
false)
default:
@@ -416,25 +414,25 @@ func (c *CoinbasePro) SubmitOrder(order *exchange.OrderSubmission) (exchange.Sub
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (c *CoinbasePro) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
func (c *CoinbasePro) ModifyOrder(action *order.Modify) (string, error) {
return "", common.ErrFunctionNotSupported
}
// CancelOrder cancels an order by its corresponding ID number
func (c *CoinbasePro) CancelOrder(order *exchange.OrderCancellation) error {
func (c *CoinbasePro) CancelOrder(order *order.Cancel) error {
return c.CancelExistingOrder(order.OrderID)
}
// CancelAllOrders cancels all orders associated with a currency pair
func (c *CoinbasePro) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
func (c *CoinbasePro) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
// CancellAllExisting orders returns a list of successful cancellations, we're only interested in failures
_, err := c.CancelAllExistingOrders("")
return exchange.CancelAllOrdersResponse{}, err
return order.CancelAllResponse{}, err
}
// GetOrderInfo returns information on a current open order
func (c *CoinbasePro) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
var orderDetail exchange.OrderDetail
func (c *CoinbasePro) GetOrderInfo(orderID string) (order.Detail, error) {
var orderDetail order.Detail
return orderDetail, common.ErrNotYetImplemented
}
@@ -498,30 +496,34 @@ func (c *CoinbasePro) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, er
}
// GetActiveOrders retrieves any orders that are active/open
func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
func (c *CoinbasePro) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
var respOrders []GeneralizedOrderResponse
for i := range getOrdersRequest.Currencies {
for i := range req.Currencies {
resp, err := c.GetOrders([]string{"open", "pending", "active"},
c.FormatExchangeCurrency(getOrdersRequest.Currencies[i], asset.Spot).String())
c.FormatExchangeCurrency(req.Currencies[i], asset.Spot).String())
if err != nil {
return nil, err
}
respOrders = append(respOrders, resp...)
}
var orders []exchange.OrderDetail
var orders []order.Detail
for i := range respOrders {
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
c.GetPairFormat(asset.Spot, false).Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
if err != nil {
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
log.Warnf(log.ExchangeSys,
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
c.Name,
"GetActiveOrders",
respOrders[i].ID,
respOrders[i].CreatedAt)
}
orders = append(orders, exchange.OrderDetail{
orders = append(orders, order.Detail{
ID: respOrders[i].ID,
Amount: respOrders[i].Size,
ExecutedAmount: respOrders[i].FilledSize,
@@ -533,17 +535,17 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersReques
})
}
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
order.FilterOrdersByType(&orders, req.OrderType)
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
order.FilterOrdersBySide(&orders, req.OrderSide)
return orders, nil
}
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
func (c *CoinbasePro) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
var respOrders []GeneralizedOrderResponse
for _, currency := range getOrdersRequest.Currencies {
for _, currency := range req.Currencies {
resp, err := c.GetOrders([]string{"done", "settled"},
c.FormatExchangeCurrency(currency, asset.Spot).String())
if err != nil {
@@ -552,19 +554,23 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
respOrders = append(respOrders, resp...)
}
var orders []exchange.OrderDetail
var orders []order.Detail
for i := range respOrders {
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
c.GetPairFormat(asset.Spot, false).Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
if err != nil {
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
log.Warnf(log.ExchangeSys,
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
c.Name,
"GetActiveOrders",
respOrders[i].ID,
respOrders[i].CreatedAt)
}
orders = append(orders, exchange.OrderDetail{
orders = append(orders, order.Detail{
ID: respOrders[i].ID,
Amount: respOrders[i].Size,
ExecutedAmount: respOrders[i].FilledSize,
@@ -576,10 +582,9 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
})
}
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
getOrdersRequest.EndTicks)
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
order.FilterOrdersByType(&orders, req.OrderType)
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
order.FilterOrdersBySide(&orders, req.OrderSide)
return orders, nil
}