buy and sell function complete