From a105af35ce866b1b2d6f9d3c86c40650120ce24e Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 Jul 2020 15:27:26 +0800 Subject: [PATCH] move strategy to the pkg/strategy --- bbgo/exchange/binance/exchange.go | 20 +++++++++++++++++++- bbgo/types/order.go | 11 +++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bbgo/exchange/binance/exchange.go b/bbgo/exchange/binance/exchange.go index 6a7eb6b9f..17c2e6420 100644 --- a/bbgo/exchange/binance/exchange.go +++ b/bbgo/exchange/binance/exchange.go @@ -2,6 +2,7 @@ package binance import ( "context" + "fmt" "strconv" "time" @@ -60,10 +61,15 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error { Do(ctx) */ + orderType, err := toLocalOrderType(order.Type) + if err != nil { + return err + } + req := e.Client.NewCreateOrderService(). Symbol(order.Symbol). Side(binance.SideType(order.Side)). - Type(order.Type). + Type(orderType). Quantity(order.VolumeStr) if len(order.PriceStr) > 0 { @@ -78,6 +84,18 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error { return err } +func toLocalOrderType(orderType types.OrderType) (binance.OrderType, error) { + switch orderType { + case types.OrderTypeLimit: + return binance.OrderTypeLimit, nil + + case types.OrderTypeMarket: + return binance.OrderTypeMarket, nil + } + + return "", fmt.Errorf("order type %s not supported", orderType) +} + func (e *Exchange) QueryKLines(ctx context.Context, symbol, interval string, limit int) ([]types.KLine, error) { logrus.Infof("[binance] querying kline %s %s limit %d", symbol, interval, limit) diff --git a/bbgo/types/order.go b/bbgo/types/order.go index c023be4e3..96997b3f5 100644 --- a/bbgo/types/order.go +++ b/bbgo/types/order.go @@ -5,10 +5,18 @@ import ( "github.com/slack-go/slack" ) +// OrderType define order type +type OrderType string + +const ( + OrderTypeLimit OrderType = "LIMIT" + OrderTypeMarket OrderType = "MARKET" +) + type Order struct { Symbol string Side SideType - Type binance.OrderType + Type OrderType VolumeStr string PriceStr string @@ -33,4 +41,3 @@ func (o *Order) SlackAttachment() slack.Attachment { Fields: fields, } } -