Include isMyOffer flag in API's trade/offer proto wrappers

Optionally displaying an ENABLED column in CLI side getoffer output
depends on the value of offer.isMyOffer, which is passed via new
boolean arguments to the trade & offer pojo builders.
This commit is contained in:
ghubstan 2021-06-18 17:40:21 -03:00
parent 1a56a5161a
commit 0e9c6650e3
No known key found for this signature in database
GPG key ID: E35592D6800A861E
2 changed files with 15 additions and 7 deletions

View file

@ -63,7 +63,7 @@ public class OfferInfo implements Payload {
private final long date;
private final String state;
private final boolean isActivated;
private final boolean isMyOffer;
private boolean isMyOffer;
public OfferInfo(OfferInfoBuilder builder) {
this.id = builder.id;
@ -93,13 +93,19 @@ public class OfferInfo implements Payload {
this.isMyOffer = builder.isMyOffer;
}
// Allow isMyOffer to be set on new offers' OfferInfo instances.
public void setIsMyOffer(boolean myOffer) {
isMyOffer = myOffer;
}
public static OfferInfo toOfferInfo(Offer offer) {
// Offer is not mine.
// Assume the offer is not mine, but isMyOffer can be reset to true, i.e., when
// calling TradeInfo toTradeInfo(Trade trade, String role, boolean isMyOffer);
return getOfferInfoBuilder(offer, false).build();
}
public static OfferInfo toOfferInfo(OpenOffer openOffer) {
// OpenOffer is mine.
// An OpenOffer is always my offer.
return getOfferInfoBuilder(openOffer.getOffer(), true)
.withTriggerPrice(openOffer.getTriggerPrice())
.withIsActivated(!openOffer.isDeactivated())

View file

@ -92,11 +92,11 @@ public class TradeInfo implements Payload {
this.contract = builder.contract;
}
public static TradeInfo toTradeInfo(Trade trade) {
return toTradeInfo(trade, null);
public static TradeInfo toNewTradeInfo(Trade trade) {
return toTradeInfo(trade, null, false);
}
public static TradeInfo toTradeInfo(Trade trade, String role) {
public static TradeInfo toTradeInfo(Trade trade, String role, boolean isMyOffer) {
ContractInfo contractInfo;
if (trade.getContract() != null) {
Contract contract = trade.getContract();
@ -116,8 +116,10 @@ public class TradeInfo implements Payload {
contractInfo = ContractInfo.emptyContract.get();
}
OfferInfo offerInfo = toOfferInfo(trade.getOffer());
offerInfo.setIsMyOffer(isMyOffer);
return new TradeInfoBuilder()
.withOffer(toOfferInfo(trade.getOffer()))
.withOffer(offerInfo)
.withTradeId(trade.getId())
.withShortId(trade.getShortId())
.withDate(trade.getDate().getTime())