Placing FamilyInstance at local coordinate system

Hi fellows!
I’m trying to make a Zero-Touch node that can place family instance at local coordinate system whose Z-axis does not parallel to World Coordinate System Z-axis.
I’ve tried something like this(I copied and altered Dynamo source code from Github):

        public static Revit.Elements.FamilyInstance ByCoordinateSystem(Revit.Elements.FamilyType familyType, CoordinateSystem coordinateSystem)
        {
            var transform = coordinateSystem.ToTransform() as Autodesk.Revit.DB.Transform;
            double[] newRotationAngles;
            TransformUtils.ExtractEularAnglesFromTransform(transform, out newRotationAngles);
            double rotation = ConvertEularToAngleDegrees(newRotationAngles.FirstOrDefault());
            Point location = transform.ToCoordinateSystem().Origin;

            Revit.Elements.FamilyInstance familyInstance = Revit.Elements.FamilyInstance.ByPoint(familyType, location);
            familyInstance.SetRotation(rotation);
            return familyInstance;
        }

        private static double ConvertEularToAngleDegrees(double newRotationAngles)
        {
            return (newRotationAngles / (2 * Math.PI)) * 360;
        }

The question is that my code can only make family instance “rotate” on certain level(aka. the result instance is always vertical). My test family is simply a “cube” Family and I moved all parallel or vertical restrictions. Can any mentor tell me where did I make a mistake.
PS: Is there any package or node that can do what I want. Appreciate!
Our Revit version is restricted to 2018 and no higher.