The rapid growth of edge devices and mobile applications has driven the adoption of edge computing to handle computing tasks closer to end-users. However, the heterogeneity of edge devices and their limited computing resources raise challenges in the efficient allocation of computing resources to complete services with different characteristics and preferences. In this paper, we delve into an edge scenario comprising multiple Edge Computing Servers (ECSs), multiple Device-to-Device (D2D) Edge Nodes (ENs), and multiple edge devices. In order to address the resource allocation challenge among ECSs, ENs, and edge devices in high-workload environments, as well as the pricing of edge resources within the resource market framework, we propose a Risk Assessment Contract Algorithm (RACA) based on risk assessment theory. The RACA enables ECSs to assess risks associated with local users by estimating their future revenue potential and updating the contract autonomously at present and in the future. ENs acquire additional resources from ECSs to efficiently complete local users’ tasks. Simultaneously, ENs can also negotiate reasonable resource requests and pricing with ECSs by a Stackelberg game algorithm. Furthermore, we prove the unique existence of Nash equilibrium in the established game, implying that equilibrium solutions can stably converge through computational methods in heterogeneous environments. Finally, through simulation experiments on the dataset, we demonstrate that risk assessment can better enhance the overall profit capability of the system. Moreover, through multiple experiments, we showcase the stability of the contract’s autonomous update capability. The RACA exhibits better utility in terms of system profit capabilities, stability in high-workload environments, and energy consumption. This work provides a more dynamic and effective solution to the resource allocation problem in edge systems under high-workload environments.