If you have to ask the question then the likelihood is that you are a beginner and you should play all the notes in first position, including open strings.
If you are a bit beyond beginner then the next question is when to play open strings and when to play 4th finger.
There are three considerations for this:
- Does one choice avoid a string crossing? e.g. finger sequence 2-3-4-3-2 (all same string) vs 2-3-0-3-2 (string crossing). Use the 4th finger and avoid the string crossing.
- Do you want to vibrate the note? If "yes" then you can only do that with a 4th finger.
- Do you want to avoid a "squeaky" open E string? If "yes" then 4th finger on the A string.
As you reach intermediate / advanced levels the questions you have to ask yourself change a little bit:
- What sounds better. Often composers have a view and express it by writing something like "sul G" or "sul A" which are instructions to play that part on the G string (sul G) or A string (sul A). In the absence of such instruction you should use your own judgment. Which sounds better to you? Be prepared to be overruled by your teacher (happens to me all the time).
- Which way is easier. This might mean which way is easier for me personally, like vibrating consecutive notes on 2nd and 3rd finger vs 3rd and 4th. If the 2nd, 3rd combination is easier for you then shift if necessary to make it happen.
Note that some very difficult pieces can be made slightly less difficult at a personal level by changing a fingering. Top violinists (and not so top) do this all the time and will often discus their different fingerings.
Note that even when the composer has written fingerings on the score these are not commands and can be overruled by the violinist. A good example is Elgar's "Salut d'Amour". The first note is marked as a 4th finger.
Last year Nicola Benedetti's Benedetti Foundation ran massive online sessions for string players. Salut D'Amour featured and Nicola Benedetti recorded an example YouTube video below in which she starts on the 3rd finger instead of the indicated 4th and then a bar later shifts down a half step on 1st finger then back up a half step on the same 1st finger to avoid a string crossing (which wouldn't have been necessary had she followed Elgar's marked fingering). Benedetti's fingering is actually just as easy for intermediate / advanced violinists but allows for much stronger and richer vibrato.