fix/order-executor: ClosePosition() works on futures position

This commit is contained in:
Andy Cheng 2022-10-07 13:06:32 +08:00
parent 34866ce7cc
commit 7a80b90dac

View File

@ -407,6 +407,15 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
atomic.AddInt64(&e.closing, 1)
defer atomic.StoreInt64(&e.closing, 0)
if e.session.Futures { // Futures: Use base qty in e.position
submitOrder.Quantity = e.position.GetBase().Abs()
submitOrder.ReduceOnly = true
if e.position.IsLong() {
submitOrder.Side = types.SideTypeSell
} else {
submitOrder.Side = types.SideTypeBuy
}
} else { // Spot and spot margin
// check base balance and adjust the close position order
if e.position.IsLong() {
if baseBalance, ok := e.session.Account.Balance(e.position.Market.BaseCurrency); ok {
@ -424,6 +433,7 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
}
*/
}
}
tagStr := strings.Join(tags, ",")
submitOrder.Tag = tagStr