Tradeports are simply spam them everywhere. Refineries are based on supply and demand. say you have a bunch of metal and no crystal and one ice planet. the ice planet gets a refinery maybe 2. in addition to it's tradeport.
Actually, if you were just covering the ice planet and not much else, a tradeport would still be better because you can just buy the crystal off the black market with the money. However, if you could cover a couple ice planets and another neighboring planet or two, then it is very desirable to build a refinery. Refineries become cost effective when more worlds neighbor the location of the refinery.
1Tiberius1, my understanding from the wiki is it works slightly differently in that your longest trade route determines the income level of *all* your trade ports, not just the ones on the route itself.
This is true, but the point 1Tiberius1 is making is that you can actually force your trade route to be longer by not building everywhere. Sometimes excluding a tradeport on a planet forces the route to take a longer, "twistier" path. I've noticed this when I had trade routes that were 7 jumps long, but then I added another tradeport at a central world and "short circuited" the route, turning it into a 5 jump route.