The ever‐evolving electricity distribution network calls for new effective, transparent and fair market procedures to be implemented. This paper offers a systematic framework for real‐time trading in prosumer communities. A data‐driven robust optimization model that deals with uncertainty is proposed using the flexibility requirement envelope concept. Using machine learning techniques, high quality point and quantile forecasts are prepared to form the envelope. Next, this data is fed into the optimization problem to match the peers and the distribution grid, trading power, and flexibility in a short‐term look‐ahead horizon. To increase the quality of forecasts, a clustering approach accompanied by a pattern recognition machine is proposed to determine the cluster to which the recently observed net‐load data belongs. To provide forecasts, a forecasting machine is developed using a hybrid of tree‐based ensemble learning models, which provides intuitive, robust, and accurate results. Finally, the peer matching is done in a decentralized fashion using the alternating direction method of multipliers (ADMM), while each agent calculates its battery storage aging cost. Case studies demonstrate the hybrid model's capability in providing high quality power and flexibility forecasts compared to single models and ARIMA models and its positive impact on reducing the overall cost of the system.