def get_trade_history(asset1=None, asset2=None, start_ts=None, end_ts=None, limit=50):
    """
    Gets last N of trades within a specific date range (normally, for a specified asset pair, but this can
    be left blank to get any/all trades).
    """
    assert (asset1 and asset2) or (not asset1 and not asset2)  # cannot have one asset, but not the other

    if limit > 500:
        raise Exception("Requesting history of too many trades")

    now_ts = calendar.timegm(time.gmtime())
    if not end_ts:  # default to current datetime
        end_ts = now_ts
    if not start_ts:  # default to 30 days before the end date
        start_ts = end_ts - (30 * 24 * 60 * 60)

    filters = {
        "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)
        }
    }
    if asset1 and asset2:
        base_asset, quote_asset = util.assets_to_asset_pair(asset1, asset2)
        filters["base_asset"] = base_asset
        filters["quote_asset"] = quote_asset

    last_trades = config.mongo_db.trades.find(filters, {'_id': 0}).sort("block_time", pymongo.DESCENDING).limit(limit)
    if not last_trades.count():
        return False  # no suitable trade data to form a market price
    last_trades = list(last_trades)
    return last_trades