def get_market_price_history(asset1, asset2, start_ts=None, end_ts=None, as_dict=False):
    """Return block-by-block aggregated market history data for the specified asset pair, within the specified date range.
    @returns List of lists (or list of dicts, if as_dict is specified).
        * If as_dict is False, each embedded list has 8 elements [block time (epoch in MS), open, high, low, close, volume, # trades in block, block index]
        * If as_dict is True, each dict in the list has the keys: block_time (epoch in MS), block_index, open, high, low, close, vol, count

    Aggregate on an an hourly basis 
    """
    now_ts = calendar.timegm(time.gmtime())
    if not end_ts:  # default to current datetime
        end_ts = now_ts
    if not start_ts:  # default to 180 days before the end date
        start_ts = end_ts - (180 * 24 * 60 * 60)
    base_asset, quote_asset = util.assets_to_asset_pair(asset1, asset2)

    # get ticks -- open, high, low, close, volume
    result = config.mongo_db.trades.aggregate([
        {"$match": {
            "base_asset": base_asset,
            "quote_asset": quote_asset,
            "block_time": {
                "$gte": datetime.datetime.utcfromtimestamp(start_ts)
            } if end_ts == now_ts else {
                "$gte": datetime.datetime.utcfromtimestamp(start_ts),
                "$lte": datetime.datetime.utcfromtimestamp(end_ts)
            }
        }},
        {"$project": {
            "year":  {"$year": "$block_time"},
            "month": {"$month": "$block_time"},
            "day":   {"$dayOfMonth": "$block_time"},
            "hour":  {"$hour": "$block_time"},
            "block_index": 1,
            "unit_price": 1,
            "base_quantity_normalized": 1  # to derive volume
        }},
        {"$group": {
            "_id":   {"year": "$year", "month": "$month", "day": "$day", "hour": "$hour"},
            "open":  {"$first": "$unit_price"},
            "high":  {"$max": "$unit_price"},
            "low":   {"$min": "$unit_price"},
            "close": {"$last": "$unit_price"},
            "vol":   {"$sum": "$base_quantity_normalized"},
            "count": {"$sum": 1},
        }},
        {"$sort": SON([("_id.year", pymongo.ASCENDING), ("_id.month", pymongo.ASCENDING), ("_id.day", pymongo.ASCENDING), ("_id.hour", pymongo.ASCENDING)])},
    ])
    result = list(result)
    if not len(result):
        return False

    midline = [((r['high'] + r['low']) / 2.0) for r in result]
    if as_dict:
        for i in range(len(result)):
            result[i]['interval_time'] = int(calendar.timegm(datetime.datetime(
                result[i]['_id']['year'], result[i]['_id']['month'], result[i]['_id']['day'], result[i]['_id']['hour']).timetuple()) * 1000)
            result[i]['midline'] = midline[i]
            del result[i]['_id']
        return result
    else:
        list_result = []
        for i in range(len(result)):
            list_result.append([
                int(calendar.timegm(datetime.datetime(
                    result[i]['_id']['year'], result[i]['_id']['month'], result[i]['_id']['day'], result[i]['_id']['hour']).timetuple()) * 1000),
                result[i]['open'], result[i]['high'], result[i]['low'], result[i]['close'], result[i]['vol'],
                result[i]['count'], midline[i]
            ])
        return list_result