Refactor of trade.py.