The job market is somewhat of a crapshot. A dice roll if you will. I got rejected from all kinds of place before I got a highly paid one from a Reddit post of all places. I got rejected from all kinds of places that only paid like 1/2 or 1/3 of what that job was paying, and I wasn't even looking for it at that time. It's been over for over half a year, and I wouldn't be able to replicate that sort of performance at will. Though at this point, I am not even looking for one and just working on my own projects since I have a lot saved up and barely spend anything.
One thing that I understand at my age of nearly 39 now is that success comes pretty hard, and luck plays a large role in it. As programmers all we can do is build and develop our skills, even if the world doesn't validate our efforts.
You're asking yourself what you are doing wrong, but you should be asking yourself what your goal is and focus on that. Is it really to just work for other people?
What can you do for yourself?