With the development of the electricity market, peer-to-peer (P2P) transaction plays an important role in promoting local consumption of renewable energy and arousing the enthusiasm of prosumers. However, due to the diversification of prosumers, the confidentiality of the information and the interaction between prosumers, there are increasing challenges for the traditional model-based optimisation methods in both P2P modelling and model solution accuracy. Therefore, this paper proposes a novel P2P transaction method based on deep learning under a two-stage market environment, which uses a data-driven approach to build a transaction behaviour model based on public information. The neural network model based on Long Short-Term Memory (LSTM) is utilised to characterise the behaviour of prosumers in P2P transactions effectively. Based on this model, the energy consumption plans and P2P bids of prosumers are optimised accordingly. Through the simulation test of an example system with six prosumers, the results show that the model established can well represent the P2P transaction behaviour of prosumers, and the proposed method can effectively improve the efficiency of P2P transactions and the economic benefits of prosumers, providing a reference for the decision-making of P2P transactions.