Skip to content

Commit

Permalink
Engine QA - Order update (thrasher-corp#372)
Browse files Browse the repository at this point in the history
Engine QA - Order update
  • Loading branch information
shazbert authored and thrasher- committed Oct 30, 2019
1 parent 242b02c commit 63a9e9f
Show file tree
Hide file tree
Showing 89 changed files with 3,077 additions and 2,876 deletions.
20 changes: 10 additions & 10 deletions cmd/exchange_template/wrapper_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,29 @@ func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, asset
}

// SubmitOrder submits a new order
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
return exchange.SubmitOrderResponse{}, common.ErrNotYetImplemented
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side order.Side, orderType order.Type, amount, price float64, clientID string) (order.SubmitResponse, error) {
return order.SubmitResponse{}, common.ErrNotYetImplemented
}

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action *order.Modify) (string, error) {
return "", common.ErrNotYetImplemented
}

// CancelOrder cancels an order by its corresponding ID number
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order *exchange.OrderCancellation) error {
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order *order.Cancel) error {
return common.ErrNotYetImplemented
}

// CancelAllOrders cancels all orders associated with a currency pair
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
return exchange.CancelAllOrdersResponse{}, common.ErrNotYetImplemented
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
return order.CancelAllResponse{}, common.ErrNotYetImplemented
}

// GetOrderInfo returns information on a current open order
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
return exchange.OrderDetail{}, common.ErrNotYetImplemented
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (order.Detail, error) {
return order.Detail{}, common.ErrNotYetImplemented
}

// GetDepositAddress returns a deposit address for a specified currency
Expand Down Expand Up @@ -170,13 +170,13 @@ func ({{.Variable}} *{{.CapitalName}}) GetWebsocket() (*exchange.Websocket, erro
}

// GetActiveOrders retrieves any orders that are active/open
func ({{.Variable}} *{{.CapitalName}}) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
func ({{.Variable}} *{{.CapitalName}}) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
return nil, common.ErrNotYetImplemented
}

// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func ({{.Variable}} *{{.CapitalName}}) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
func ({{.Variable}} *{{.CapitalName}}) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
return nil, common.ErrNotYetImplemented
}

Expand Down
17 changes: 9 additions & 8 deletions cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
)

const (
Expand Down Expand Up @@ -116,10 +117,10 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "GetFundingHistory")
}

s := &exchange.OrderSubmission{
s := &order.Submit{
Pair: p,
OrderSide: exchange.BuyOrderSide,
OrderType: exchange.LimitOrderType,
OrderSide: order.Buy,
OrderType: order.Limit,
Amount: 1000000,
Price: 10000000000,
ClientID: "meow",
Expand All @@ -129,17 +130,17 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "SubmitOrder")
}

_, err = e.ModifyOrder(&exchange.ModifyOrder{})
_, err = e.ModifyOrder(&order.Modify{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "ModifyOrder")
}

err = e.CancelOrder(&exchange.OrderCancellation{})
err = e.CancelOrder(&order.Cancel{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "CancelOrder")
}

_, err = e.CancelAllOrders(&exchange.OrderCancellation{})
_, err = e.CancelAllOrders(&order.Cancel{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "CancelAllOrders")
}
Expand All @@ -149,12 +150,12 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "GetOrderInfo")
}

_, err = e.GetOrderHistory(&exchange.GetOrdersRequest{})
_, err = e.GetOrderHistory(&order.GetOrdersRequest{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "GetOrderHistory")
}

_, err = e.GetActiveOrders(&exchange.GetOrdersRequest{})
_, err = e.GetActiveOrders(&order.GetOrdersRequest{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "GetActiveOrders")
}
Expand Down
84 changes: 43 additions & 41 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/engine"
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/ticker"
)
Expand Down Expand Up @@ -225,43 +226,44 @@ func setExchangeAPIKeys(name string, keys map[string]*config.APICredentialsConfi
return base.ValidateAPICredentials()
}

func parseOrderSide(orderSide string) exchange.OrderSide {
func parseOrderSide(orderSide string) order.Side {
switch orderSide {
case exchange.AnyOrderSide.ToString():
return exchange.AnyOrderSide
case exchange.BuyOrderSide.ToString():
return exchange.BuyOrderSide
case exchange.SellOrderSide.ToString():
return exchange.SellOrderSide
case exchange.BidOrderSide.ToString():
return exchange.BidOrderSide
case exchange.AskOrderSide.ToString():
return exchange.AskOrderSide
case order.AnySide.String():
return order.AnySide
case order.Buy.String():
return order.Buy
case order.Sell.String():
return order.Sell
case order.Bid.String():
return order.Bid
case order.Ask.String():
return order.Ask
default:
log.Printf("Orderside '%v' not recognised, defaulting to BUY", orderSide)
return exchange.BuyOrderSide
return order.Buy
}
}

func parseOrderType(orderType string) exchange.OrderType {
func parseOrderType(orderType string) order.Type {
switch orderType {
case exchange.AnyOrderType.ToString():
return exchange.AnyOrderType
case exchange.LimitOrderType.ToString():
return exchange.LimitOrderType
case exchange.MarketOrderType.ToString():
return exchange.MarketOrderType
case exchange.ImmediateOrCancelOrderType.ToString():
return exchange.ImmediateOrCancelOrderType
case exchange.StopOrderType.ToString():
return exchange.StopOrderType
case exchange.TrailingStopOrderType.ToString():
return exchange.TrailingStopOrderType
case exchange.UnknownOrderType.ToString():
return exchange.UnknownOrderType
case order.AnyType.String():
return order.AnyType
case order.Limit.String():
return order.Limit
case order.Market.String():
return order.Market
case order.ImmediateOrCancel.String():
return order.ImmediateOrCancel
case order.Stop.String():
return order.Stop
case order.TrailingStop.String():
return order.TrailingStop
case order.Unknown.String():
return order.Unknown
default:
log.Printf("OrderType '%v' not recognised, defaulting to LIMIT", orderTypeOverride)
return exchange.LimitOrderType
log.Printf("OrderType '%v' not recognised, defaulting to LIMIT",
orderTypeOverride)
return order.Limit
}
}

Expand Down Expand Up @@ -457,15 +459,15 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r10}),
})

s := &exchange.OrderSubmission{
s := &order.Submit{
Pair: p,
OrderSide: testOrderSide,
OrderType: testOrderType,
Amount: config.OrderSubmission.Amount,
Price: config.OrderSubmission.Price,
ClientID: config.OrderSubmission.OrderID,
}
var r11 exchange.SubmitOrderResponse
var r11 order.SubmitResponse
r11, err = e.SubmitOrder(s)
msg = ""
if err != nil {
Expand All @@ -479,10 +481,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r11}),
})

modifyRequest := exchange.ModifyOrder{
modifyRequest := order.Modify{
OrderID: config.OrderSubmission.OrderID,
OrderType: testOrderType,
OrderSide: testOrderSide,
Type: testOrderType,
Side: testOrderSide,
CurrencyPair: p,
Price: config.OrderSubmission.Price,
Amount: config.OrderSubmission.Amount,
Expand All @@ -501,7 +503,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: r12,
})
// r13
cancelRequest := exchange.OrderCancellation{
cancelRequest := order.Cancel{
Side: testOrderSide,
CurrencyPair: p,
OrderID: config.OrderSubmission.OrderID,
Expand All @@ -519,7 +521,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{nil}),
})

var r14 exchange.CancelAllOrdersResponse
var r14 order.CancelAllResponse
r14, err = e.CancelAllOrders(&cancelRequest)
msg = ""
if err != nil {
Expand All @@ -533,7 +535,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r14}),
})

var r15 exchange.OrderDetail
var r15 order.Detail
r15, err = e.GetOrderInfo(config.OrderSubmission.OrderID)
msg = ""
if err != nil {
Expand All @@ -547,12 +549,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r15}),
})

historyRequest := exchange.GetOrdersRequest{
historyRequest := order.GetOrdersRequest{
OrderType: testOrderType,
OrderSide: testOrderSide,
Currencies: []currency.Pair{p},
}
var r16 []exchange.OrderDetail
var r16 []order.Detail
r16, err = e.GetOrderHistory(&historyRequest)
msg = ""
if err != nil {
Expand All @@ -566,12 +568,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r16}),
})

orderRequest := exchange.GetOrdersRequest{
orderRequest := order.GetOrdersRequest{
OrderType: testOrderType,
OrderSide: testOrderSide,
Currencies: []currency.Pair{p},
}
var r17 []exchange.OrderDetail
var r17 []order.Detail
r17, err = e.GetActiveOrders(&orderRequest)
msg = ""
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions engine/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ func (a *databaseManager) Start() (err error) {

if Bot.Config.Database.Enabled {
if Bot.Config.Database.Driver == database.DBPostgreSQL {
log.Debugf(log.DatabaseMgr, "Attempting to establish database connection to host %s/%s utilising %s driver\n",
Bot.Config.Database.Host, Bot.Config.Database.Database, Bot.Config.Database.Driver)
log.Debugf(log.DatabaseMgr,
"Attempting to establish database connection to host %s/%s utilising %s driver\n",
Bot.Config.Database.Host,
Bot.Config.Database.Database,
Bot.Config.Database.Driver)
dbConn, err = dbpsql.Connect()
} else if Bot.Config.Database.Driver == database.DBSQLite || Bot.Config.Database.Driver == database.DBSQLite3 {
log.Debugf(log.DatabaseMgr, "Attempting to establish database connection to %s utilising %s driver\n",
Bot.Config.Database.Database, Bot.Config.Database.Driver)
} else if Bot.Config.Database.Driver == database.DBSQLite ||
Bot.Config.Database.Driver == database.DBSQLite3 {
log.Debugf(log.DatabaseMgr,
"Attempting to establish database connection to %s utilising %s driver\n",
Bot.Config.Database.Database,
Bot.Config.Database.Driver)
dbConn, err = dbsqlite3.Connect()
}
if err != nil {
Expand Down
Loading

0 comments on commit 63a9e9f

Please sign in to comment.