XChange icon indicating copy to clipboard operation
XChange copied to clipboard

[Question] Add Map to generic DTOs?

Open timmolter opened this issue 11 years ago • 4 comments

PR #982 adds a Map to the Order object.

From the beginning of the project it was decided that the way to access exchange-specific return data, which normally didn't "make the cut" to be included in the generic DTOs was to cast to the exchange-specific service and call the exchange-specific methods, returning the exchange-specific DTOs containing all the info you need.

@ww3456 proposes to include a Map used for adding data not included in the standard generic DTOs. BTW, such a map is already in Trade. I must not have been paying too close attention when that got in there.

If we switch to this approach I think it'd be best to do it across all DTOs (and I'm happy to do it). So the question is, should we do it?

The disadvantage is that the client now will not really know what's in the map, as it could be anything, and if the client is dealing with exchange-specific differences anyway, why not cast like we have always been doing.

The advantage would be that given a Map, the client code could check for the presence of certain keys with if statements and act accordingly, without needing to have special code for each exchange. If several exchanges that the client interacted with uses those keys, the client's logic will be simplified.

timmolter avatar Jun 14 '15 20:06 timmolter

If the additional data map is not agreeable, an alternative would be to return extended RippleUserTrade and RippleLimitOrder objects that contain fields with the exchange specific data. This would allow the interfaces of the generic DTOs to remain unchanged.

(I've just updated PR #982 with account trade query functionality.)

ww3456 avatar Jun 24 '15 21:06 ww3456

@ww3456 I'm thinking out loud here...

I think that would be a better approach, because the code would essentially be self-documenting. Whereas a Map can contain anything, a class with methods (getters) defines exactly what can be pulled out.

I think your proposal is good, and I'd like to hear any one else's comments about it. Basically, the API would remain the same, client code wouldn't need to down cast to the Raw services, instead client code can receive the clean XChange DTOs, cast that to the exchange specific one and pull out extra info from the DTOs getters. Is that the idea?

timmolter avatar Jun 25 '15 07:06 timmolter

Yes, that it is, I think sub-classing the generic DTOs is the better solution for the reasons you described. I'll start by backing out the additionalDataMap I added to the Trade object as part of #954 and create a KrakenUserTrade class that extends UserTrade, in a separate PR.

ww3456 avatar Jun 25 '15 20:06 ww3456

Excellent. Thanks.

timmolter avatar Jun 26 '15 07:06 timmolter