def build_ohlcv(self, trades, timeframe='1m', since=None, limit=None):
    ms = (self.parse_timeframe(timeframe) * 1000)
    ohlcvs = []
    (high, low, close, volume) = (2, 3, 4, 5)
    num_trades = len(trades)
    oldest = ((num_trades - 1) if (limit is None) else min((num_trades - 1), limit))
    for i in range(0, oldest):
        trade = trades[i]
        if ((since is not None) and (trade['timestamp'] < since)):
            continue
        opening_time = int((math.floor((trade['timestamp'] / ms)) * ms))
        j = len(ohlcvs)
        if ((j == 0) or (opening_time >= (ohlcvs[(j - 1)][0] + ms))):
            ohlcvs.append([opening_time, trade['price'], trade['price'], trade['price'], trade['price'], trade['amount']])
        else:
            ohlcvs[(j - 1)][high] = max(ohlcvs[(j - 1)][high], trade['price'])
            ohlcvs[(j - 1)][low] = min(ohlcvs[(j - 1)][low], trade['price'])
            ohlcvs[(j - 1)][close] = trade['price']
            ohlcvs[(j - 1)][volume] += trade['amount']
    return ohlcvs
def build_ohlcv(self, trades, timeframe='1m', since=None, limit=None):
    ms = (self.parse_timeframe(timeframe) * 1000)
    ohlcvs = []
    (high, low, close, volume) = (2, 3, 4, 5)
    num_trades = len(trades)
    oldest = ((num_trades - 1) if (limit is None) else min((num_trades - 1), limit))
    for i in range(0, oldest):
        trade = trades[i]
        if ((since is not None) and (trade['timestamp'] < since)):
            continue
        opening_time = int((math.floor((trade['timestamp'] / ms)) * ms))
        j = len(ohlcvs)
        if ((j == 0) or (opening_time >= (ohlcvs[(j - 1)][0] + ms))):
            ohlcvs.append([opening_time, trade['price'], trade['price'], trade['price'], trade['price'], trade['amount']])
        else:
            ohlcvs[(j - 1)][high] = max(ohlcvs[(j - 1)][high], trade['price'])
            ohlcvs[(j - 1)][low] = min(ohlcvs[(j - 1)][low], trade['price'])
            ohlcvs[(j - 1)][close] = trade['price']
            ohlcvs[(j - 1)][volume] += trade['amount']
    return ohlcvs