예제 #1
0
 def _valid_order(self, order):
     """ 判断订单是否合法。 """
     if order.side == TradeSide.PING:
         try:
             pos = self.current_positions[order.contract]
             if pos.quantity >= order.quantity:
                 return True
         except KeyError:
             # 没有持有该合约
             logger.warn("不存在合约[%s]" % order.contract)
             return False
         logger.warn("下单仓位问题")
         return False
     elif order.side == TradeSide.KAI:
         if self.current_holdings['cash'] < order.price * order.quantity:
             raise Exception('没有足够的资金开仓')
     return True
예제 #2
0
 def _valid_order(self, order):
     """ 判断订单是否合法。 """ 
     if order.side == TradeSide.PING:
         try:
             pos = self.current_positions[order.contract]
             if pos.quantity >= order.quantity:
                 return True 
         except KeyError:
             # 没有持有该合约
             logger.warn("不存在合约[%s]" % order.contract)
             return False
         logger.warn("下单仓位问题")
         return False
     elif order.side == TradeSide.KAI:
         if self.current_holdings['cash'] < order.price * order.quantity:
             raise Exception('没有足够的资金开仓') 
     return True
예제 #3
0
 def _valid_order(self, order):
     """ 判断订单是否合法。 """ 
     if order.side == TradeSide.PING:
         try:
             pos = self.current_positions[order.contract]
             if order.direction == Direction.LONG:
                 ## @todo 自动改变合法仓位。
                 if pos.total > 0:
                     return True 
             elif order.direction == Direction.SHORT:
                 ## @todo 自动改变合法仓位。
                 if pos.total < 0:
                     return True 
         except KeyError:
             # 没有持有该合约
             logger.warn("不存在合约[%s]" % order.contract)
             return False
         return False
     elif order.side == TradeSide.KAI:
         if self.current_holdings['cash'] < 0:
             raise Exception('没有足够的资金开仓') 
     return True