Beispiel #1
0
 def close_position(self):
     """
     close the position when current size of position is not zero
     """
     if position() != 0:
         # print("in close", position_list[-1])
         Broker(self.init_capital).make_order(unit=-1 * position(),
                                              limit_price=None,
                                              stop_loss=None,
                                              stop_profit=None)
     else:
         pass
Beispiel #2
0
 def sell(self,
          unit=None,
          limit_price=None,
          stop_loss=None,
          stop_profit=None):
     if unit is None:
         unit = -position()
     assert unit < 0, ' in sell action, unit must be negative'
     Broker(self.init_capital).make_order(unit=unit,
                                          limit_price=limit_price,
                                          stop_loss=stop_loss,
                                          stop_profit=stop_profit)
Beispiel #3
0
 def buy(self,
         unit=None,
         limit_price=None,
         stop_loss=None,
         stop_profit=None):
     if unit is None:
         unit = position()
     assert unit > 0, 'in buy action, unit must be positive'
     Broker(self.init_capital).make_order(unit=unit,
                                          limit_price=limit_price,
                                          stop_loss=stop_loss,
                                          stop_profit=stop_profit)
Beispiel #4
0
 def short_position(self):
     return position() < 0
Beispiel #5
0
 def long_position(self):
     return position() > 0
Beispiel #6
0
 def empty_position(self):
     return position() == 0
Beispiel #7
0
 def position(self):
     return position()