move MarginSettings struct to a file

This commit is contained in:
c9s 2021-01-15 15:11:38 +08:00
parent 1c77de031a
commit 5cab37488b
2 changed files with 90 additions and 81 deletions

View File

@ -30,22 +30,6 @@ func init() {
}
}
type MarginSettings struct {
useMargin bool
useMarginIsolated bool
useMarginIsolatedSymbol string
}
func (e *MarginSettings) UseMargin() {
e.useMargin = true
}
func (e *MarginSettings) UseIsolatedMargin(symbol string) {
e.useMargin = true
e.useMarginIsolated = true
e.useMarginIsolatedSymbol = symbol
}
type Exchange struct {
MarginSettings
@ -388,11 +372,14 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
return err2
}
func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) {
for _, order := range orders {
func (e *Exchange) submitMarginOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
return nil, nil
}
func (e *Exchange) submitSpotOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
orderType, err := toLocalOrderType(order.Type)
if err != nil {
return createdOrders, err
return nil, err
}
clientOrderID := uuid.New().String()
@ -415,7 +402,7 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
switch order.Type {
case types.OrderTypeStopLimit, types.OrderTypeStopMarket:
if len(order.StopPriceString) == 0 {
return createdOrders, fmt.Errorf("stop price string can not be empty")
return nil, fmt.Errorf("stop price string can not be empty")
}
req.StopPrice(order.StopPriceString)
@ -428,12 +415,12 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
response, err := req.Do(ctx)
if err != nil {
return createdOrders, err
return nil, err
}
log.Infof("order creation response: %+v", response)
retOrder := binance.Order{
createdOrder, err := ToGlobalOrder(&binance.Order{
Symbol: response.Symbol,
OrderID: response.OrderID,
ClientOrderID: response.ClientOrderID,
@ -445,16 +432,21 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
TimeInForce: response.TimeInForce,
Type: response.Type,
Side: response.Side,
UpdateTime: response.TransactTime,
Time: response.TransactTime,
// IsIsolated: response.IsIsolated,
// StopPrice:
// IcebergQuantity:
Time: response.TransactTime,
// UpdateTime:
// IsWorking: ,
})
return createdOrder, err
}
createdOrder, err := ToGlobalOrder(&retOrder)
func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) {
for _, order := range orders {
createdOrder, err := e.submitSpotOrder(ctx, order)
if err != nil {
return createdOrders, err
}

View File

@ -0,0 +1,17 @@
package binance
type MarginSettings struct {
useMargin bool
useMarginIsolated bool
useMarginIsolatedSymbol string
}
func (e *MarginSettings) UseMargin() {
e.useMargin = true
}
func (e *MarginSettings) UseIsolatedMargin(symbol string) {
e.useMargin = true
e.useMarginIsolated = true
e.useMarginIsolatedSymbol = symbol
}