def _trim(self, book, balances, side):
        """
        >>> m = MultiOrderbook()
        >>> book = [
            [7800, 1.1, GDAX()],
            [7805, 3.2, Poloniex()],
            [7810, 0.3, GDAX()],
            [7900, 7.0, GDAX()]
        ]
        >>> m._trim(book, {GDAX(): 1.2, Poloniex(): 1.0}, 'crypto')
        [[7800, 1.1, <Service: GDAX (0 in cache)>],
         [7805, 1.0, <Service: Poloniex (0 in cache)>],
         [7810, 0.1, <Service: GDAX (0 in cache)>]]
        """
        new_book = []
        for service, balance in balances.items():
            accumulation = 0
            for order in book:
                if order[2].name == service.name:
                    if side == 'crypto':
                        size = order[1]
                    else:
                        size = order[1] * order[0] # convert to fiat

                    if size + accumulation <= balance:
                        new_book.append(order)
                        accumulation += size
                    else:
                        remaining = balance - accumulation
                        new_book.append([order[0], float("%.8f" % remaining), order[2]])
                        break

        return sorted(new_book, key=lambda x: x[0], reverse=side == 'fiat')
def _trim ( self , book , balances , side ) : new_book = [ ] for service , balance in balances . items ( ) : accumulation = 0 for order in book : if order [ 2 ] . name == service . name : if side == 'crypto' : size = order [ 1 ] else : size = order [ 1 ] * order [ 0 ] if size + accumulation <= balance : new_book . append ( order ) accumulation += size else : remaining = balance - accumulation new_book . append ( [ order [ 0 ] , float ( "%.8f" % remaining ) , order [ 2 ] ] ) break return sorted ( new_book , key = lambda x : x [ 0 ] , reverse = side == 'fiat' )
>>> m = MultiOrderbook()
        >>> book = [
            [7800, 1.1, GDAX()],
            [7805, 3.2, Poloniex()],
            [7810, 0.3, GDAX()],
            [7900, 7.0, GDAX()]
        ]
        >>> m._trim(book, {GDAX(): 1.2, Poloniex(): 1.0}, 'crypto')
        [[7800, 1.1, <Service: GDAX (0 in cache)>],
         [7805, 1.0, <Service: Poloniex (0 in cache)>],
         [7810, 0.1, <Service: GDAX (0 in cache)>]]