Eat a banana.
I read that if you have RLS, (Restless Legs Syndrome) life-style changes may help you. Since fatigue and drowsiness often make symptoms worse, a consistent sleep routine can be a real help. If possible, it’s best to have a sleeping environment that is quiet, cool, and comfortable. Going to bed at the same time every evening and waking up at the same time every morning also help.
A regular exercise program will help you get a good night’s sleep. However, vigorous exercise within the six hours before you go to bed may have the opposite effect. Some with RLS find that moderate exercise immediately before bedtime helps them sleep. Experiment with various exercises to discover what is best for you. Don’t fight the urge to move. If you try to suppress movement, the symptoms usually worsen. Often the best solution is to get out of bed and move about. Some find a measure of relief in walking, stretching, bathing in hot or cold water, or massaging their legs. If you have to sit for a long time, such as when traveling, it may help if you keep your mind actively engaged in reading.
Sadly, there is no cure for RLS, and the symptoms often worsen over the years. However, the good news is that RLS can be treated effectively. There is no one solution; what works for one person may not work for another. Those who have it need to find what habits, activities, or medications either worsen the symptoms or improve them. Since taking drugs and especially combinations of drugs carries health risks, it is important to work closely with your health-care provider to determine what works best for you.
You need more potassium. Look up foods that contain lots of potassium. Bananas and spinach have lots.
I take ropinerol (Rx) for my restless leg! I used to get massive muscle cramps in my hands, legs, and chest. I used to be able to buy Otc quinine but they made it only available by prescription. I found some leg cramp Med's at Walgreens that contains Quinine that stopped the twitch/cramp. My masseuse suggested that I should start taking Otc magnesium, after about two weeks the cramps/twitch stopped! My restless leg showed up during a sleep study for sleep apnea. The tech said I looked like I was laying down running in place. No wonder I always woke up tired in the morning. Lol
I'm not sure what you're describing is Restless Leg Syndrome. Twitching and spasms sound more like a back or nerve related problem. Restless Leg Syndrome is when trying to keep your legs still is torture, as though a thousand ants were crawling in your bones. You have to get up and move around, can't sit or lie down standing or walking is the only way to get relief without medication.
If RLS is your problem then find a sleep disorder clinic where they certainly can help you with medication. Alcohol, antihistamine, some anesthetics and sitting for too long will also trigger it, it's usually worse at night although it can be a problem during the day if it's very severe. I've suffered from this for more than 20 years and it's changed the way I have to live my life.