A self-consistent magnetostatic particle code for numerical simulation of plasmas