Ju.
As Barb says, this will vary between cultures, but this is how I understand the terms.
A nickname is usually given to somebody by their family, friends, workmates or others that are acquainted with them, or sometimes by people who don't know them very well at all. A nickname is often used by very many people and can become the name that somebody is best known by.
A pet name more commonly occurs between lovers, husband and wife, family members or close friends. Unlike a nickname, it is typically used by one person towards another, or within a family, and would rarely be used by anyone else outside the relationship or family group.
A person might also have a pet name for a car, an item of clothing, a project, or any other thing that they have a particular fondness for or personal involvement in. Normally only that person uses the pet name when referring to these things.
I don't say that there is always a clear distinction, I think someone might describe a nickname as a pet name if there was a distinct fondness in their attitude to the person named, even if they didn't know them personally.
I keep making little changes to this post, so I'll leave it there and hope these notes are useful.
not a teacher