def tie_account_to_order(AccountKey, order):
    """tie_account_to_order - inject the AccountKey in the orderbody.

    An order specification is 'anonymous'. To apply it to an account it needs
    the AccountKey of the account.

    Parameters
    ----------
    AccountKey: string (required)
        the accountkey

    order: dict representing an orderbody or <...>Order instance
        the details of the order.
    """
    _r = order.copy() if isinstance(order, dict) else order.data.copy()

    # add the key to the orderbody, but ONLY if this is not a positionclose
    # body
    if "PositionId" not in _r:
        _r.update({'AccountKey': AccountKey})

    # and add it to related orders in Orders (if any)
    if 'Orders' in _r:
        for o in _r['Orders']:
            o.update({'AccountKey': AccountKey})

    return _r