import hmac
import hashlib


def _sign_request(api_secret: str, timestamp: int, method: str, path: str, body: str = "") -> str:
    """Signs the request payload using the api key secret

    :param timestamp: the unix timestamp of this request e.g. int(time.time()*1000)
    :param method: Http method - GET, POST, PUT or DELETE
    :param path: path excluding FQDN
    :param body: http request body as a JSON string, optional
    :return signature hash
    """
    body = body if body else ""
    payload = f"{timestamp}{method.upper()}{path}{body}"
    message = bytearray(payload, 'utf-8')
    signature = hmac.new(bytearray(api_secret, 'utf-8'), message, digestmod=hashlib.sha512).hexdigest()
    return signature