trade SQL and ajax for past trades done