def trade(self):
    ''
    self.cancel_all()
    pos_change = (self.target_pos - self.pos)
    if (not pos_change):
        return
    long_price = 0
    short_price = 0
    if self.last_tick:
        if (pos_change > 0):
            long_price = (self.last_tick.ask_price_1 + self.tick_add)
            if self.last_tick.limit_up:
                long_price = min(long_price, self.last_tick.limit_up)
        else:
            short_price = (self.last_tick.bid_price_1 - self.tick_add)
            if self.last_tick.limit_down:
                short_price = max(short_price, self.last_tick.limit_down)
    elif (pos_change > 0):
        long_price = (self.last_bar.close_price + self.tick_add)
    else:
        short_price = (self.last_bar.close_price - self.tick_add)
    if (self.get_engine_type() == EngineType.BACKTESTING):
        if (pos_change > 0):
            vt_orderids = self.buy(long_price, abs(pos_change))
        else:
            vt_orderids = self.short(short_price, abs(pos_change))
        self.vt_orderids.extend(vt_orderids)
    else:
        if self.vt_orderids:
            return
        if (pos_change > 0):
            if (self.pos < 0):
                if (pos_change < abs(self.pos)):
                    vt_orderids = self.cover(long_price, pos_change)
                else:
                    vt_orderids = self.cover(long_price, abs(self.pos))
            else:
                vt_orderids = self.buy(long_price, abs(pos_change))
        elif (self.pos > 0):
            if (abs(pos_change) < self.pos):
                vt_orderids = self.sell(short_price, abs(pos_change))
            else:
                vt_orderids = self.sell(short_price, abs(self.pos))
        else:
            vt_orderids = self.short(short_price, abs(pos_change))
        self.vt_orderids.extend(vt_orderids)
def trade(self):
    
    self.cancel_all()
    pos_change = (self.target_pos - self.pos)
    if (not pos_change):
        return
    long_price = 0
    short_price = 0
    if self.last_tick:
        if (pos_change > 0):
            long_price = (self.last_tick.ask_price_1 + self.tick_add)
            if self.last_tick.limit_up:
                long_price = min(long_price, self.last_tick.limit_up)
        else:
            short_price = (self.last_tick.bid_price_1 - self.tick_add)
            if self.last_tick.limit_down:
                short_price = max(short_price, self.last_tick.limit_down)
    elif (pos_change > 0):
        long_price = (self.last_bar.close_price + self.tick_add)
    else:
        short_price = (self.last_bar.close_price - self.tick_add)
    if (self.get_engine_type() == EngineType.BACKTESTING):
        if (pos_change > 0):
            vt_orderids = self.buy(long_price, abs(pos_change))
        else:
            vt_orderids = self.short(short_price, abs(pos_change))
        self.vt_orderids.extend(vt_orderids)
    else:
        if self.vt_orderids:
            return
        if (pos_change > 0):
            if (self.pos < 0):
                if (pos_change < abs(self.pos)):
                    vt_orderids = self.cover(long_price, pos_change)
                else:
                    vt_orderids = self.cover(long_price, abs(self.pos))
            else:
                vt_orderids = self.buy(long_price, abs(pos_change))
        elif (self.pos > 0):
            if (abs(pos_change) < self.pos):
                vt_orderids = self.sell(short_price, abs(pos_change))
            else:
                vt_orderids = self.sell(short_price, abs(self.pos))
        else:
            vt_orderids = self.short(short_price, abs(pos_change))
        self.vt_orderids.extend(vt_orderids)