import pytz


def datetime2unixepoch(dt):
    """ Utility to transform a datetime instance into an unix epoch represented as an int.
    The unixepoch is in milliseconds as this is the standard for the exchange

    Parameters
    ----------
    dt: datetime

    Returns
    -------
    int
        unix epoch
    """
    if dt.tzinfo is None:
        dt = pytz.UTC.localize(dt)
    else:
        dt = dt.astimezone(pytz.UTC)

    result = dt.timestamp()
    result *= 1000

    return int(result)