While I mine my self, I want to try buying from nicehash and sell that to other places.
No this will not be profitable and may be even not be possible.
Miningrigrentals and nicehash are the only marketplace to buy/sell mining power and miningrigrentals doesn't provide any api to automate the process of buying/selling. Nicehash has api here
https://www.nicehash.com/?p=api you can play with it but i haven't tried it personally.