I am looking for a solution to apply existing theme in SharePoint Modern Site using code.
The Official Documentation on Microsoft gives us a few REST calls to manage your tenant themes:
http://<site url>/_api/thememanager/AddTenantTheme http://<site url>/_api/thememanager/RemoveTenantTheme http://<site url>/_api/thememanager/GetTenantThemingOptions
Since add/removing themes is a tenant scoped feature, you must have the clearance to manage them (Tenant Admin).
If you wish to apply a classic theme to a modern site, here is a link that gives a script to use.
To select the correct theme in a site, this is a manual procedure (I haven't found an endpoint, but there may be) which is pretty simple (Cog in the ribbon > Change the look > Select your theme).
Rolling out pretty soon (announced without a release date I believe), Hub sites will automatically apply the hub theme to any site you decide to attach.
Hope this helps!