Suggestions on close order
-
currently, close an order will call buy/sell in strategy class. and I found my future broker allow me to hold long position and short position at the same time,
if I send one buy cmd and one sell cmd, I have two open positions! the only way to close the position is send a close cmdso, my suggestion is not to convert the close call within strategy class, XXStore or XXBroker will be better place
-
The idea of the
close
order is to provide the simplified method to close existing position. If you don't want to close existing position, than theclose
order should not be used. If you want to hold long and short positions at the same time, than usebuy
andsell
orders to initiate the positions. -
@ab_trader I do want to close the existing order, but there is no way to do that in this system, no
close
to override in BrokerBase. I am suggest moveclose
fromStrategy
toBrokerBase
, It makes code much more extensible without lose any convenient -
Following the existing concept, I think that
close
order can be implemented at the strategy level only, similar to the target orders, for example. The reason is that it uses position size as an argument and position size relates to strategy. At the broker level it can be several positions open by different strategies in the same data feed. Simple moving of theclose
order to broker level can easily break the legacy of thebt
scripts, since the call of theclose
order will be closing all positions in all strategies.If you desperately needs this, than sub-class the
bbroker
and write your own implementation. But honestly, the strategy can be written without using of theclose
order at all, therefore I think that this mod will bring more hassle than worth. -
what @ab_trader said is what you should follow to prevent later issues. You could overwrite the close method of the strategy and check for your broker. If it is your broker, use a different way to close the order, if not, just call super(self).close(order)