First of all, we are all different in our writing practices and our approaches to our stories, so there will be some writers for whom the ego strokes from writing will outbalance the concern for The Reader, and the reverse, and there will be those who will approach their writing with an eye toward the market (which is very different from The Reader in my thinking, and as stated by several others upstream). And who is to say that one approach will produce superior stories, or deeper stories, or more artsy stories, or more meaningful stories? This whole business is so subjective, there is room for all kinds of approaches as along as the result is the same--the writer produces a damn good story that engages The Reader.
I've said many times here at AW that it's all about the story and it's all about the reader (this is a personal writing philosophy). By that last part, I meant The Reader, not the market. Here's what I mean. When I sit down to write a scene, I think about how I want that scene to contribute to the story, but when it comes to writing, I open my toolbox of writing techniques to nudge The Reader through that scene while trying my best to anticipate how this technique or that technique might tweak The Reader's emotions or reactions to lead The Reader in my general direction, without hooking a ring through his/her nose and pulling him/her along. This is not thinking about market. This is giving me a solid reason to pull the various tools out of my toolbox. That reason is never to thrill myself. The self-thrill comes when I finish a scene or story and decide that I have been successful in doing what I wanted to do for and to The Reader to enhance how that reader wanders through the story (hopefully with a desire to keep turning the pages). When I throw a twist in a story, I don't do it so I can brag about how I tricked The Reader, I do it with the hope The Reader will slap his/her forehead and say, "I should have seen that coming." If that happens, then my ego enters to tell me I did a good job of using my personal toolbox to create a highly desired reaction in The Reader (as a reader, I love when I have this type of reaction from other authors).
I am proud of my writing accomplishments, as we all should be. So there is a bit of writing for myself in that, but that's in the aftermath, not in the motivation of figuring out how to construct and write scenes and stories. That construction is done with The Reader in mind. And for me, it IS all about the story, and it IS all about The Reader.
The market? We all hope to find a successful niche, but I personally don't let that shape the actual crafting of the story. But likely there are writers who do target the market from the very start through the full crafting of scenes and the story, who are finding success in writing those damn good stories. Good for them. Good for all of us who may have very different approaches to story selection and story construction as long as we all do one thing well--write that damn good story. And to me, that is a story that engages and thrills The Reader. After that, we all hope we can thrill many readers and establish our market niche.