it's a horrible time for any pet person, OP. He sounds like a lovely chap, a real friend to you, and it really sucks that pets don't have a longer life expectancy. We take them on knowing that we will outlive them and we will have to suffer their illnesses and deaths.
From what you've told us, your lovely boy has incurable cancer. I feel for you: I lost a cat to leukaemia. The vet is giving him a very strong painkiller, so his treatment is about trying to keep him comfortable, rather than trying to treat and/or cure the cancer. 
The hard fact is that most pets do end their lives being put to sleep, it's very unusual for a well looked after pet to just pass peacefully in their sleep in comfort. It's a cliche but putting to sleep really is the kindest thing we can do for them to end or prevent their suffering.
It's now a case of when, not if, for your lovely boy.
I have taken tramadol, and have given it to my dog (who recently had to be put to sleep). Both I and my dog felt stoned out of our faces on it 😳 She was very unhappy on it, and she went off her food, I think everything tasted and smelled funny to her. It made me puke violently 😳. Obviously this isn't everybody's reaction to tramadol (see wolfiefan's post just above mine) but it's a very common one, and is something to bear in mind when you see how your boy is on it now.
Him hiding away, not wanting to eat is, as you know, giving you clear signals about how he feels. If he doesn't improve very much very soon then he won't on tramadol; it gets into the system straight away. As I say, it might bring other problems. When we make a decision to put a pet to sleep, it has to be all about them. These are the questions I find helpful in deciding when it's time;
Are they suffering right now?
Will they suffer in the near future?
Are they able to do their normal activities? Eat, wash, jump up, wander around the house and garden, toilet normally?
Are they behaving like they want to do normal for them things? Come up for a cuddle, greet you when you come in, play?
If they are suffering or are likely to suffer very soon, is it fair and reasonable to ask them to do that? It might be, if for example the suffering is keeping an otherwise fit and healthy dog on cage rest for 6 weeks to recover from a broken leg they stand a high chance of full recovery from. I'd gently suggest in your boy's case, that it's not reasonable to ask him to do this suffering if tramadol doesn't make him feel much better, as he's not going to recover 
Vets are lovely when it's time to put to sleep. It upsets them to do it, they do their job because they want to make animals better. They accept that euthanasia is part of their job because they don't want animals to suffer if they can't make them better. Your vet will show your boy the ultimate in kindness and dignity when it's time. If you'd like to talk about what to expect, do feel free to direct message me. I've had a few animals put to sleep over the years. Xxx