Closed granthoff1107 closed 3 years ago
I don't remember the exact reason why, but it probably had to do with semantics from an API usage perspective. IE: If we want some notion of "subscribe" and "unsubscribe" in the API; then, what do you do when someone gives you the following object (when someone probably makes a mistake):
var subObject = new Subscription{ Type = MessageType.Unsubscribe }; // probably an error
socket.Subscribe( subObject ); //when really it should be a subscription; not an unsubscription.
So we forcibly set the "type" in association with the appropriate method call to ensure correct behavior.
We could probably subclass, and apply some type safety, but I didn't want to derive my own types too much away from the "official" API.
What happens if there is no Unsubscribe JToken to be removed from the subscription?
If type
does not exist; one will be added. If the type
exists, the current type
is overwritten before being sent over the socket. The sub/unsub methods ensure that the correct type
corresponding to the method call is always correct before being sent over the socket.
So I decided to look into the subscription methods on the coinbase pro socket to be aware of whether I need to call them from the Dispose method.
I noticed something interesting, that we mutate the options when sending them into the socket.
Why do we mutate the existing options? What happens if there is no
Unsubscribe
JToken to be removed from the subscription?