Just to clarify what everyone is saying, the Trade Hub collection range does go through the gateway. So once you have that tech, you only need one Starbase to collect trade.
In my last game, I had 6 Trade Hubs in the Starbase in my capital's system. I built a gateway there.
I then built additional gateways throughout my empire placed such that anything that produced trade that I wanted was no more than 5 steps away from a gateway. That's 5 steps because the Trade Hubs have a range of 6 and the step through the gateway itself counts as a step. So that made sure that all of these sources were within range of my capital's Starbase.
I also made sure that no system with a source of trade had a Starbase other than my capital system! If any of them did then the trade would be collected by their Starbase, since every Starbase has a collection range of 0 for the local system, even if you don't install any Trade Hubs in it. This would cause a trade route to appear from that Starbase to the nearest gateway, and any system along that might get piracy.
If all these steps are followed, then the trade gets collected by the main Starbase and there is no trade going along any trade routes. No trade means no piracy. Wallah.