diff --git a/bbgo/exchange/binance/exchange.go b/bbgo/exchange/binance/exchange.go index 9e54124ee..c616b249d 100644 --- a/bbgo/exchange/binance/exchange.go +++ b/bbgo/exchange/binance/exchange.go @@ -227,7 +227,7 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { }, nil } -func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error { +func (e *Exchange) SubmitOrder(ctx context.Context, order *types.SubmitOrder) error { /* limit order example @@ -250,10 +250,10 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error { Symbol(order.Symbol). Side(binance.SideType(order.Side)). Type(orderType). - Quantity(order.VolumeStr) + Quantity(order.Quantity) - if len(order.PriceStr) > 0 { - req.Price(order.PriceStr) + if len(order.Price) > 0 { + req.Price(order.Price) } if len(order.TimeInForce) > 0 { req.TimeInForce(order.TimeInForce) diff --git a/bbgo/trader.go b/bbgo/trader.go index ca4556c7a..a317b6ef9 100644 --- a/bbgo/trader.go +++ b/bbgo/trader.go @@ -24,11 +24,11 @@ type KLineRegressionTrader struct { SourceKLines []types.KLine ProfitAndLossCalculator *ProfitAndLossCalculator - doneOrders []*types.Order - pendingOrders []*types.Order + doneOrders []*types.SubmitOrder + pendingOrders []*types.SubmitOrder } -func (trader *KLineRegressionTrader) SubmitOrder(cxt context.Context, order *types.Order) { +func (trader *KLineRegressionTrader) SubmitOrder(cxt context.Context, order *types.SubmitOrder) { trader.pendingOrders = append(trader.pendingOrders, order) } @@ -73,12 +73,12 @@ func (trader *KLineRegressionTrader) RunStrategy(ctx context.Context, strategy S var price float64 if order.Type == types.OrderTypeLimit { - price = util.MustParseFloat(order.PriceStr) + price = util.MustParseFloat(order.Price) } else { price = kline.GetClose() } - volume := util.MustParseFloat(order.VolumeStr) + volume := util.MustParseFloat(order.Quantity) fee := 0.0 feeCurrency := "" @@ -285,12 +285,12 @@ func (trader *Trader) ReportPnL() { trader.Notifier.ReportPnL(report) } -func (trader *Trader) SubmitOrder(ctx context.Context, order *types.Order) { - trader.Notifier.Notify(":memo: Submitting %s %s %s order with quantity: %s", order.Symbol, order.Type, order.Side, order.VolumeStr, order) +func (trader *Trader) SubmitOrder(ctx context.Context, order *types.SubmitOrder) { + trader.Notifier.Notify(":memo: Submitting %s %s %s order with quantity: %s", order.Symbol, order.Type, order.Side, order.Quantity, order) err := trader.Exchange.SubmitOrder(ctx, order) if err != nil { - log.WithError(err).Errorf("order create error: side %s quantity: %s", order.Side, order.VolumeStr) + log.WithError(err).Errorf("order create error: side %s quantity: %s", order.Side, order.Quantity) return } } diff --git a/bbgo/types/order.go b/bbgo/types/order.go index 96997b3f5..b396ca53c 100644 --- a/bbgo/types/order.go +++ b/bbgo/types/order.go @@ -13,25 +13,25 @@ const ( OrderTypeMarket OrderType = "MARKET" ) -type Order struct { - Symbol string - Side SideType - Type OrderType - VolumeStr string - PriceStr string +type SubmitOrder struct { + Symbol string + Side SideType + Type OrderType + Quantity string + Price string TimeInForce binance.TimeInForceType } -func (o *Order) SlackAttachment() slack.Attachment { +func (o *SubmitOrder) SlackAttachment() slack.Attachment { var fields = []slack.AttachmentField{ {Title: "Symbol", Value: o.Symbol, Short: true}, {Title: "Side", Value: string(o.Side), Short: true}, - {Title: "Volume", Value: o.VolumeStr, Short: true}, + {Title: "Volume", Value: o.Quantity, Short: true}, } - if len(o.PriceStr) > 0 { - fields = append(fields, slack.AttachmentField{Title: "Price", Value: o.PriceStr, Short: true}) + if len(o.Price) > 0 { + fields = append(fields, slack.AttachmentField{Title: "Price", Value: o.Price, Short: true}) } return slack.Attachment{ diff --git a/bbgo/types/trader.go b/bbgo/types/trader.go index 7cf1e06d9..bf4ebcc4a 100644 --- a/bbgo/types/trader.go +++ b/bbgo/types/trader.go @@ -3,5 +3,5 @@ package types import "context" type Trader interface { - SubmitOrder(ctx context.Context, order *Order) + SubmitOrder(ctx context.Context, order *SubmitOrder) }