Which code language and strategies for best Performance in short time trading?

My Questions are once as stated in the title and:
What to do to get the total latency to place Orders on the Spot Market?
Languages used: JavaScript/Node.js, python

I have started coding my own trading bot. after some testing, the bot worked fine. But when it started to trade for real, I constantly lost money. Of course I can make the time it takes to calculate each trade longer, meaning that trades take an hour instead of a few seconds/minutes, but I do want to try to fix my current problem.

I found out, after comparing data, that it seemed my orders where executed hundreds of milliseconds later to even seconds, which made it so that the trades often didn’t make profit and in total lost me money.
Therefore I plan on optimizing my code, currently I’m using Node.js to run my bot but I’m certain there are better languages. That’s why I ask of you which language is good for fast calculation of large data or rather what I should do. It would also be preferable to learn something that I can use for other stuff too but that doesn’t really matter its just a nice bonus.

I also read about getting an virtual machine or something of the sort to set up in Japan next to the Binance server to get very low latency, which I do plan to implement but I would need to look into it a bit more. Although I think this will help I would still like to optimize my code, meaning not the code itself (which I will need to do either way), but the language I use and strategies that could help me.

Moreover I had an idea where I try to get a ping how long executing a trade takes before hand so that I can change my code to predict lets say 100ms (total latency to place order) before what’s going to happen and if it should take action, my problem that I run into is to get an accurate reading of the latency it takes to place orders, I can get the ping to the server but that’s not the actual latency. I thought about maybe taking a very small amount of money to test what the ping is but it ended in me losing even more, since the latency always changed so I need another way. I couldn’t find anything useful so I’m asking if anyone of you knows what I could do? (this would solve my problem with having higher latencies)

Your calculation (CPU) time is most likely negligble compared to the stuff happening on the network. So your very first challenge would probably to make sure you run on a data center as close to Binance’s as possible. When you say “testing” I assume you mean backtesting. It is very easily to accidentially code backtesters to use unrealistic assumptions. For instance you will seldom get the same price as the one that triggered your stop loss action (unless you already had the order in Binance’s system of course). To get more realistic results it is probably WAY easier to add more realistic assumptions when you backtest than trying to optimize your stack to perform like what is most likely “ideal” conditions in your backtest. So use the first tick after minimum 200 msec after your stop loss get a more realistic stop loss price etc.