move exchange and order struct to the bbgo package

This commit is contained in:
c9s 2020-06-18 18:56:54 +08:00
parent e62f1f2479
commit 965ab59580
2 changed files with 45 additions and 0 deletions

31
bbgo/binance_exchange.go Normal file
View File

@ -0,0 +1,31 @@
package bbgo
import (
"context"
"github.com/adshao/go-binance"
"github.com/sirupsen/logrus"
)
type BinanceExchange struct {
Client *binance.Client
}
func (e *BinanceExchange) SubmitOrder(ctx context.Context, order Order) error {
req := e.Client.NewCreateOrderService().
Symbol(order.Symbol).
Side(order.Side).
Type(order.Type).
Quantity(order.VolumeStr)
if len(order.PriceStr) > 0 {
req.Price(order.PriceStr)
}
if len(order.TimeInForce) > 0 {
req.TimeInForce(order.TimeInForce)
}
retOrder, err := req.Do(ctx)
logrus.Infof("order created: %+v", retOrder)
return err
}

14
bbgo/order.go Normal file
View File

@ -0,0 +1,14 @@
package bbgo
import "github.com/adshao/go-binance"
type Order struct {
Symbol string
Side binance.SideType
Type binance.OrderType
VolumeStr string
PriceStr string
TimeInForce binance.TimeInForceType
}