There are passionate proponents of writing to market. The businesslike author wants to maximise return on their writing efforts which is fair enough.
The Write What You Love proponents swear by writing the sort of story that fires you up, that your zeal and passion will shine through and delight readers.
Both are correct. However, there is a key here that will answer both approaches; whether you write to market or write what you love.
The key - clearly identify your audience and present your story to Them.
If you write to market, you will already spend a lot of time analysing and identifying your target audience. That falls in line with the whole approach.
If you write what you love be razor sharp in who you present your story to. Be sure to nail which genres your book fits into or know clearly what your crossover genres may be. There is a niche for every book ever written but it is so important to identify it and market your book correctly to that audience.