I have still these questions: Were all assumptions in my first paragraph right? Do you have to set SidRotPeriod and Obliquity etc. when you create the solar systems? Because these parameters are needed to calculate the Rotation matrix for the coordinate transformation. If the answers to the questions are yes, then the next paragraphs will make sense (kind of):
Let me start at the beginning. I think you first have to get the spherical polar coordinates. That's easy, because it is just the three components lat, lng and radius.
Then you have to transform these in cartesian coordinates. This is similar to what you already do to calculate e.g. ylng (and xlng and zlng).
Now you have to do the same calculations as the function oapiGetPlanetObliquityMatrix does and transform the coordinates from equatorial in ecliptic coordinates. Here you need all the information from the config file of the planet as specified under "Rotation and precession parameters". I don't know how your program will work, but I guess it creates these information? I can explain you in detail what you would have to do.
The velocity is another story. I think you don't even need the LAN. With a given position and the velocity there are 0,1 or 2 possibilites for the LAN. For example, an inclination of 30° with the latitude of 50° would never work, because the spacecraft will never go so high north/south.
I don't know if I am overcomplicating things, but I had to do all of this for a lua script, where the nice API functions aren't avaiable either. I hope I could/can help.