def act(self, world=None, market=None):
        """
        Return order as a dict with keys in (direction, price, quantity).
        If BUY, bid lower if last order was successful, otherwise higher.
        If SELL, bid higher if last order was successful, otherwise lower.
        Bids are random bounded by previous bid and reservation prices.

        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.successes:
            # Average price of successful bids
            stockprice = float(sum(self.successes))/len(self.successes)
        else:
            stockprice = random.randint(1, self.maxprice*100)/100.

        if self.prevorder[SELL][1]:
            sellprice = random.randint(int(self.prevorder[SELL][0]*100), \
                        self.maxprice*100)/100.
        else:
            sellprice = random.randint(int(self.ressell*100-1), \
                        int(self.prevorder[SELL][0]*100+1))/100.
        sellquant = self.stocks
        if self.prevorder[BUY][1]:
            buyprice = random.randint(1, \
                       int(self.prevorder[BUY][0]*100))/100.
        else:
            buyprice = random.randint(int(self.prevorder[BUY][0]*100-1), \
                       int(self.resbuy*100+1))/100.
        if buyprice <= 0:
            buyprice = 0.01
        buyquant = int(self.money/buyprice)

        # Choose buy or sell, place order
        # Wealth if trader sells all his stock
        sellwealth = self.money + sellquant*sellprice
        # Wealth if trader uses as much money as possible to buy
        buywealth = self.money - buyquant*buyprice + \
                    (self.stocks + buyquant)*stockprice
        if sellwealth > buywealth:
            direction = SELL
            price = sellprice
            quantity = sellquant
        else:
            direction = BUY
            price = buyprice
            quantity = buyquant
        self.prevorder[direction] = [price, False]
        return {'direction':direction, 'price':price, 'quantity':quantity}
dataset/ETHPy150Open jcbagneris/fms/fms/contrib/coleman/agents/smartprobeboundedtrader.py/SmartProbeBoundedTrader.act/original