High-contrast medium resolution spectroscopy has been used to detect molecules such as water and carbon monoxide in the atmospheres of gas giant exoplanets. In this work, we show how it can be used to derive radial velocity (RV) measurements of directly imaged exoplanets. Improving upon the traditional cross-correlation technique, we develop a new likelihood based on joint forward modelling of the planetary signal and the starlight background (i.e., speckles). After marginalizing over the starlight model, we infer the barycentric RV of HR 8799 b and c in 2010 yielding -9.2 +- 0.5 km/s and -11.6 +- 0.5 km/s respectively. These RV measurements help to constrain the 3D orientation of the orbit of the planet by resolving the degeneracy in the longitude of ascending node. Assuming coplanar orbits for HR 8799 b and c, but not including d and e, we estimate Omega = 89 (+27,-17) deg and i = 20.8 (4.5,-3.7) deg.