The present application relates to a macrocycle containing aminopyrazole and pyrimidine, which is represented by formula (I), a pharmaceutical composition thereof, and a use thereof in inhibiting tropomyosin receptor kinase (Trk) activity and in treating diseases in mammals that are mediated by Trk.