Let $X$ be a compact Calabi-Yau 3-fold, and write $mathcal M,bar{mathcal M}$ for the moduli stacks of objects in coh$(X),D^b$coh$(X)$. There are natural line bundles $K_{mathcal M}tomathcal M$, $K_{bar{mathcal M}}tobar{mathcal M}$, analogues of canonical bundles. Orientation data on $mathcal M,bar{mathcal M}$ is an isomorphism class of square root line bundles $K_{mathcal M}^{1/2},K_{bar{mathcal M}}^{1/2}$, satisfying a compatibility condition on the stack of short exact sequences. It was introduced by Kontsevich and Soibelman arXiv:1006.270 in their theory of motivic Donaldson-Thomas invariants, and is important in categorifying Donaldson-Thomas theory using perverse sheaves. We show that natural orientation data can be constructed for all compact Calabi-Yau 3-folds, and also for compactly-supported coherent sheaves and perfect complexes on noncompact Calabi-Yau 3-folds $X$ with a spin smooth projective compactification $Xhookrightarrow Y$. This proves a long-standing conjecture in Donaldson-Thomas theory. These are special cases of a more general result. Let $X$ be a spin smooth projective 3-fold. Using the spin structure we construct line bundles $K_{mathcal M}tomathcal M$, $K_{bar{mathcal M}}tobar{mathcal M}$. We define spin structures on $mathcal M,bar{mathcal M}$ to be isomorphism classes of square roots $K_{mathcal M}^{1/2},K_{bar{mathcal M}}^{1/2}$. We prove that natural spin structures exist on $mathcal M,bar{mathcal M}$. They are equivalent to orientation data when $X$ is a Calabi-Yau 3-fold with the trivial spin structure. We prove this using our previous paper arXiv:1908.03524, which constructs spin structures (square roots of a certain complex line bundle $K_Ptomathcal B_P$) on differential-geometric moduli stacks $mathcal B_P$ of connections on a principal U$(m)$-bundle $Pto X$ over a compact spin 6-manifold $X$.