move strategy to the pkg/strategy

This commit is contained in:
c9s 2020-07-11 15:27:26 +08:00
parent 6c1f214d0f
commit a105af35ce
2 changed files with 28 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package binance
import ( import (
"context" "context"
"fmt"
"strconv" "strconv"
"time" "time"
@ -60,10 +61,15 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error {
Do(ctx) Do(ctx)
*/ */
orderType, err := toLocalOrderType(order.Type)
if err != nil {
return err
}
req := e.Client.NewCreateOrderService(). req := e.Client.NewCreateOrderService().
Symbol(order.Symbol). Symbol(order.Symbol).
Side(binance.SideType(order.Side)). Side(binance.SideType(order.Side)).
Type(order.Type). Type(orderType).
Quantity(order.VolumeStr) Quantity(order.VolumeStr)
if len(order.PriceStr) > 0 { if len(order.PriceStr) > 0 {
@ -78,6 +84,18 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error {
return err 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) { 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) logrus.Infof("[binance] querying kline %s %s limit %d", symbol, interval, limit)

View File

@ -5,10 +5,18 @@ import (
"github.com/slack-go/slack" "github.com/slack-go/slack"
) )
// OrderType define order type
type OrderType string
const (
OrderTypeLimit OrderType = "LIMIT"
OrderTypeMarket OrderType = "MARKET"
)
type Order struct { type Order struct {
Symbol string Symbol string
Side SideType Side SideType
Type binance.OrderType Type OrderType
VolumeStr string VolumeStr string
PriceStr string PriceStr string
@ -33,4 +41,3 @@ func (o *Order) SlackAttachment() slack.Attachment {
Fields: fields, Fields: fields,
} }
} }