A transactive energy system can provide an integral management scheme that facilitates power delivery with high efficiency and reliability. To close the gap between wholesale and retail markets, this paper presents a two-stage optimal scheduling model for distributed energy resources (DERs) in the form of a virtual power plant (VPP) participating in the day-ahead (DA) and real-time (RT) markets. In the first stage, the hourly scheduling strategy of the VPP is optimized, in order to maximize the total profit in the DA market. In the second stage, the outputs of the VPP are optimally adjusted, in order to minimize the imbalance cost in the RT market. The conditional-value-at-risk (CVaR) is used to assess the risk of profit variability due to the presence of uncertainties in renewable energy outputs, market prices and energy demands. The formulated two-stage models are solved by an enhanced particle swarm optimization algorithm (PSO) and the commercial solver AMPL/IPOPT 3.8.0. In the procedures of the enhanced PSO, two particles with the lowest and highest fitness values are used as the starting points, and then the interior point method will be employed to quickly locate local optima. The population size is set at 200, and the iteration number is set at 1000. Simulation results show that coordinated scheduling can effectively offset the renewable energy fluctuation and mitigate the impacts of uncertainties. With the two-level scheduling, the risk exposure can be mitigated, and the cost related to the risk aversion is also effectively reduced. The paper finds that coordinated two-level DERs scheduling is a flexible risk-hedging tool that can identify optimal operation, resulting in more affordable electricity prices for end users.