adjust fee calculation

This commit is contained in:
c9s 2020-08-14 13:11:34 +08:00
parent 7c5fa2f191
commit 6e405eb443
4 changed files with 23 additions and 23 deletions

View File

@ -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)

View File

@ -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
}
}

View File

@ -13,25 +13,25 @@ const (
OrderTypeMarket OrderType = "MARKET"
)
type Order struct {
type SubmitOrder struct {
Symbol string
Side SideType
Type OrderType
VolumeStr string
PriceStr string
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{

View File

@ -3,5 +3,5 @@ package types
import "context"
type Trader interface {
SubmitOrder(ctx context.Context, order *Order)
SubmitOrder(ctx context.Context, order *SubmitOrder)
}