A martingale characterization of canonical commutation and anticommutation relations