Aimed at the coordination control problem of each unit caused by microgrid participation in the spot market and considering the randomness of wind and solar output and the uncertainty of spot market prices, a day-ahead real-time two-stage optimal scheduling model for microgrid was established by using the chance-constrained programming theory. On this basis, an improved particle swarm optimization (PSO) algorithm based on stochastic simulation technology was used to solve the problem and the effect of demand side management and confidence level on scheduling results is discussed. The example results verified the correctness and effectiveness of the proposed model, which can provide a theoretical basis in terms of reasonably coordinating the output of each unit in the microgrid in the spot market.