Refactoring to include database trade handling