fix/order-executor: check for short position

This commit is contained in:
Andy Cheng 2022-10-07 13:28:24 +08:00
parent 7a80b90dac
commit 5ad247c8fe

View File

@ -412,8 +412,15 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
submitOrder.ReduceOnly = true submitOrder.ReduceOnly = true
if e.position.IsLong() { if e.position.IsLong() {
submitOrder.Side = types.SideTypeSell submitOrder.Side = types.SideTypeSell
} else { } else if e.position.IsShort() {
submitOrder.Side = types.SideTypeBuy submitOrder.Side = types.SideTypeBuy
} else {
submitOrder.Side = types.SideTypeSelf
submitOrder.Quantity = fixedpoint.Zero
}
if submitOrder.Quantity.IsZero() {
return fmt.Errorf("no position to close: %+v", submitOrder)
} }
} else { // Spot and spot margin } else { // Spot and spot margin
// check base balance and adjust the close position order // check base balance and adjust the close position order