diff --git a/src/main/java/it/trade/api/StatelessTradeItApiClient.java b/src/main/java/it/trade/api/StatelessTradeItApiClient.java index e382fd3..b540aca 100644 --- a/src/main/java/it/trade/api/StatelessTradeItApiClient.java +++ b/src/main/java/it/trade/api/StatelessTradeItApiClient.java @@ -364,4 +364,18 @@ public void onSuccessResponse(Response response) { } ); } + + public void getProxyVoteUrl( + TradeItProxyVoteUrlRequest request, + TradeItCallback callback + ) { + tradeItApi.getProxyVoteUrl(request).enqueue( + new DefaultCallbackWithErrorHandling(callback) { + @Override + public void onSuccessResponse(Response response) { + callback.onSuccess(response.body()); + } + } + ); + } } diff --git a/src/main/java/it/trade/api/TradeItApi.java b/src/main/java/it/trade/api/TradeItApi.java index a0e4917..eb6911c 100644 --- a/src/main/java/it/trade/api/TradeItApi.java +++ b/src/main/java/it/trade/api/TradeItApi.java @@ -71,5 +71,7 @@ public interface TradeItApi { @POST("api/v2/brokermarketdata/getCryptoQuote") Call getCryptoQuote(@Body TradeItCryptoQuoteRequest request); + @POST("api/v2/proxyvote/getProxyVoteUrl") + Call getProxyVoteUrl(@Body TradeItProxyVoteUrlRequest request); } diff --git a/src/main/java/it/trade/api/TradeItApiClient.java b/src/main/java/it/trade/api/TradeItApiClient.java index 0924fa0..063a50f 100644 --- a/src/main/java/it/trade/api/TradeItApiClient.java +++ b/src/main/java/it/trade/api/TradeItApiClient.java @@ -260,6 +260,19 @@ public void getCryptoQuote(String accountNumber, String pair, TradeItCallback callback + ) { + TradeItProxyVoteUrlRequest request = new TradeItProxyVoteUrlRequest( + this.sessionToken, + accountNumber, + symbol + ); + this.statelessTradeItApiClient.getProxyVoteUrl(request, callback); + } + public String getSessionToken() { return sessionToken; } diff --git a/src/main/java/it/trade/model/reponse/Instrument.java b/src/main/java/it/trade/model/reponse/Instrument.java index 5a20970..76004c5 100644 --- a/src/main/java/it/trade/model/reponse/Instrument.java +++ b/src/main/java/it/trade/model/reponse/Instrument.java @@ -5,13 +5,13 @@ public enum Instrument { - @SerializedName("equities") + @SerializedName("EQUITIES") EQUITIES, - @SerializedName("fx") + @SerializedName("FX") FX, - @SerializedName("options") + @SerializedName("OPTIONS") OPTIONS, - @SerializedName("crypto") + @SerializedName("CRYPTO") CRYPTO, UNKNOWN; } \ No newline at end of file diff --git a/src/main/java/it/trade/model/reponse/TradeItPosition.java b/src/main/java/it/trade/model/reponse/TradeItPosition.java index fafd99e..588edd5 100644 --- a/src/main/java/it/trade/model/reponse/TradeItPosition.java +++ b/src/main/java/it/trade/model/reponse/TradeItPosition.java @@ -69,6 +69,10 @@ public class TradeItPosition { @Expose public String currency; + @SerializedName("isProxyVoteEligible") + @Expose + public Boolean isProxyVoteEligible; + @Override public String toString() { return "TradeItPosition{" + @@ -86,6 +90,7 @@ public String toString() { ", totalGainLossPercentage=" + totalGainLossPercentage + ", exchange='" + exchange + '\'' + ", currency='" + currency + '\'' + + ", isProxyVoteEligible='" + isProxyVoteEligible + '\'' + '}'; } @@ -115,7 +120,8 @@ public boolean equals(Object o) { if (totalGainLossPercentage != null ? !totalGainLossPercentage.equals(that.totalGainLossPercentage) : that.totalGainLossPercentage != null) return false; if (exchange != null ? !exchange.equals(that.exchange) : that.exchange != null) return false; - return currency != null ? currency.equals(that.currency) : that.currency == null; + if (currency != null ? !currency.equals(that.currency) : that.currency != null) return false; + return isProxyVoteEligible != null ? isProxyVoteEligible.equals(that.isProxyVoteEligible) : that.isProxyVoteEligible == null; } @Override @@ -134,6 +140,7 @@ public int hashCode() { result = 31 * result + (totalGainLossPercentage != null ? totalGainLossPercentage.hashCode() : 0); result = 31 * result + (exchange != null ? exchange.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); + result = 31 * result + (isProxyVoteEligible != null ? isProxyVoteEligible.hashCode() : 0); return result; } } diff --git a/src/main/java/it/trade/model/reponse/TradeItProxyVoteUrlResponse.java b/src/main/java/it/trade/model/reponse/TradeItProxyVoteUrlResponse.java new file mode 100644 index 0000000..3095cb2 --- /dev/null +++ b/src/main/java/it/trade/model/reponse/TradeItProxyVoteUrlResponse.java @@ -0,0 +1,10 @@ +package it.trade.model.reponse; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class TradeItProxyVoteUrlResponse extends TradeItResponse { + @SerializedName("proxyVoteUrl") + @Expose + public String proxyVoteUrl; +} diff --git a/src/main/java/it/trade/model/request/TradeItProxyVoteUrlRequest.java b/src/main/java/it/trade/model/request/TradeItProxyVoteUrlRequest.java new file mode 100644 index 0000000..a52151b --- /dev/null +++ b/src/main/java/it/trade/model/request/TradeItProxyVoteUrlRequest.java @@ -0,0 +1,33 @@ +package it.trade.model.request; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class TradeItProxyVoteUrlRequest extends TradeItRequestWithSession { + @SerializedName("accountNumber") + @Expose + public String accountNumber; + + @SerializedName("symbol") + @Expose + public String symbol; + + public TradeItProxyVoteUrlRequest() { + + } + + public TradeItProxyVoteUrlRequest(String sessionToken, String accountNumber, String symbol) { + this.sessionToken = sessionToken; + this.accountNumber = accountNumber; + this.symbol = symbol; + } + + @Override + public String toString() { + return "TradeItProxyVoteUrlRequest{" + + "accountNumber='" + accountNumber + '\'' + + ", symbol='" + symbol + '\'' + + ", sessionToken='" + sessionToken + '\'' + + '}'; + } +} diff --git a/src/test/groovy/it/trade/api/TradeItApiClientSpec.groovy b/src/test/groovy/it/trade/api/TradeItApiClientSpec.groovy index ce3f93d..994c08c 100644 --- a/src/test/groovy/it/trade/api/TradeItApiClientSpec.groovy +++ b/src/test/groovy/it/trade/api/TradeItApiClientSpec.groovy @@ -1215,4 +1215,54 @@ class TradeItApiClientSpec extends Specification { cryptoQuoteResponse.dayHigh == 299.45 cryptoQuoteResponse.dayLow == 291.08 } + + def "getProxyVoteUrl handles a successful response from trade it"() { + given: "A successful response from trade it" + int successfulCallbackCount = 0 + int errorCallbackCount = 0 + + Call call = Mock(Call) + 1 * tradeItApi.getProxyVoteUrl(_) >> call + 1 * call.enqueue(_) >> { args -> + Callback callback = args[0] + TradeItProxyVoteUrlResponse tradeItProxyVoteUrlresponse = new TradeItProxyVoteUrlResponse() + tradeItProxyVoteUrlresponse.sessionToken = "My session token" + tradeItProxyVoteUrlresponse.longMessages = null + tradeItProxyVoteUrlresponse.status = TradeItResponseStatus.SUCCESS + tradeItProxyVoteUrlresponse.proxyVoteUrl = "http://myproxyvoteurl.com" + + + Response response = Response.success(tradeItProxyVoteUrlresponse); + callback.onResponse(call, response); + } + + when: "calling getProxyVoteUrl" + TradeItProxyVoteUrlResponse proxyVoteUrlResponse = null + apiClient.getProxyVoteUrl( + "MyAccountNumber", + "BR", + new TradeItCallback() { + + @Override + void onSuccess(TradeItProxyVoteUrlResponse response) { + proxyVoteUrlResponse = response + successfulCallbackCount++ + } + + @Override + void onError(TradeItErrorResult error) { + errorCallbackCount++ + } + } + ) + + + then: "expect the success callback called" + successfulCallbackCount == 1 + errorCallbackCount == 0 + + and: "the proxy vote url response is correctly filled" + proxyVoteUrlResponse.status == TradeItResponseStatus.SUCCESS + proxyVoteUrlResponse.proxyVoteUrl == "http://myproxyvoteurl.com" + } }