Is there a method to conditionally execute code based upon whether an algorithm is running live or running in a backtest environment?

Thanks in advance.