buying algorithm