MCPcopy Create free account
hub / github.com/kernc/backtesting.py / __set_contingent

Method __set_contingent

backtesting/backtesting.py:730–740  ·  view source on GitHub ↗
(self, type, price)

Source from the content-addressed store, hash-verified

728 self.__set_contingent('tp', price)
729
730 def __set_contingent(self, type, price):
731 assert type in ('sl', 'tp')
732 assert price is None or 0 < price < np.inf, f'Make sure 0 < price < inf! price: {price}'
733 attr = f'_{self.__class__.__qualname__}__{type}_order'
734 order: Order = getattr(self, attr)
735 if order:
736 order.cancel()
737 if price:
738 kwargs = {'stop': price} if type == 'sl' else {'limit': price}
739 order = self.__broker.new_order(-self.size, trade=self, tag=self.tag, **kwargs)
740 setattr(self, attr, order)
741
742
743class _Broker:

Callers 2

slMethod · 0.95
tpMethod · 0.95

Calls 2

new_orderMethod · 0.80
cancelMethod · 0.45

Tested by

no test coverage detected