def act(self, world=None, market=None):
        """
        Return random order as a dict with keys in (direction, price, quantity).

        To avoid short selling as far as possible, if # of stocks
        is zero or negative, force BUY direction.
 
        To avoid levering up as far as possible, if money
        is zero or negative, force SELL.
        """
        if self.stocks > 0 and self.money > 0:
            direction = random.choice((BUY, SELL))
        elif self.stocks <= 0:
            # Short selling is forbidden
            direction = BUY
        else:
            # money<=0, levering is discouraged
            direction = SELL
        if self.prevprice == 0.01:
            self.updown = 1
        if self.prevprice == self.maxprice:
            self.updown = 0
        if self.updown:
            price = min(self.prevprice + random.randint(1, \
                        self.maxprice*10)/100., self.maxprice)
        else:
            price = max(self.prevprice - random.randint(1, \
                        self.maxprice*10)/100., 0.01)
        if direction:
            quantity = random.randint(1, self.stocks)
        else:
            quantity = random.randint(1, self.maxbuy)
        self.prevprice = price
        return {'direction':direction, 'price':price, 'quantity':quantity}
dataset/ETHPy150Open jcbagneris/fms/fms/contrib/coleman/agents/zigtrader.py/ZigTrader.act/original