mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
adjust fee calculation
This commit is contained in:
parent
7c5fa2f191
commit
6e405eb443
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -3,5 +3,5 @@ package types
|
|||
import "context"
|
||||
|
||||
type Trader interface {
|
||||
SubmitOrder(ctx context.Context, order *Order)
|
||||
SubmitOrder(ctx context.Context, order *SubmitOrder)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user