Yeah, opticals generally some with some kind of cap on the ends, sometimes it's like a little "flip cap" if that makes sense.
You are correct, the TOSlink optical cables - that's the style with the square connector (two corners are slightly more rounded) - can be a little finicky, some are metal, and the ports are plastic (or the opposite), and generally not a super tight tolerance. You might could shop a couple of different cables, maybe try plastic connectors - or, you might try putting a very tiny strip of electrical tape on the connector so it hold tighter.
I loved the style of optical on the Mac (when it still had it), it was a 3.5mm headphone style jack, had a really positive connection. Also Coax optical, much tighter (not unlike an RCA connector).