Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/it/trade/api/StatelessTradeItApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,18 @@ public void onSuccessResponse(Response<TradeItCryptoQuoteResponse> response) {
}
);
}

public void getProxyVoteUrl(
TradeItProxyVoteUrlRequest request,
TradeItCallback<TradeItProxyVoteUrlResponse> callback
) {
tradeItApi.getProxyVoteUrl(request).enqueue(
new DefaultCallbackWithErrorHandling<TradeItProxyVoteUrlResponse, TradeItProxyVoteUrlResponse>(callback) {
@Override
public void onSuccessResponse(Response<TradeItProxyVoteUrlResponse> response) {
callback.onSuccess(response.body());
}
}
);
}
}
2 changes: 2 additions & 0 deletions src/main/java/it/trade/api/TradeItApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ public interface TradeItApi {
@POST("api/v2/brokermarketdata/getCryptoQuote")
Call<TradeItCryptoQuoteResponse> getCryptoQuote(@Body TradeItCryptoQuoteRequest request);

@POST("api/v2/proxyvote/getProxyVoteUrl")
Call<TradeItProxyVoteUrlResponse> getProxyVoteUrl(@Body TradeItProxyVoteUrlRequest request);

}
13 changes: 13 additions & 0 deletions src/main/java/it/trade/api/TradeItApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ public void getCryptoQuote(String accountNumber, String pair, TradeItCallback<Tr
this.statelessTradeItApiClient.getCryptoQuote(request, callback);
}

public void getProxyVoteUrl(
String accountNumber,
String symbol,
TradeItCallback<TradeItProxyVoteUrlResponse> callback
) {
TradeItProxyVoteUrlRequest request = new TradeItProxyVoteUrlRequest(
this.sessionToken,
accountNumber,
symbol
);
this.statelessTradeItApiClient.getProxyVoteUrl(request, callback);
}

public String getSessionToken() {
return sessionToken;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/it/trade/model/reponse/Instrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 8 additions & 1 deletion src/main/java/it/trade/model/reponse/TradeItPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public class TradeItPosition {
@Expose
public String currency;

@SerializedName("isProxyVoteEligible")
@Expose
public Boolean isProxyVoteEligible;

@Override
public String toString() {
return "TradeItPosition{" +
Expand All @@ -86,6 +90,7 @@ public String toString() {
", totalGainLossPercentage=" + totalGainLossPercentage +
", exchange='" + exchange + '\'' +
", currency='" + currency + '\'' +
", isProxyVoteEligible='" + isProxyVoteEligible + '\'' +
'}';
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
50 changes: 50 additions & 0 deletions src/test/groovy/it/trade/api/TradeItApiClientSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<TradeItResponse> call = Mock(Call)
1 * tradeItApi.getProxyVoteUrl(_) >> call
1 * call.enqueue(_) >> { args ->
Callback<TradeItProxyVoteUrlResponse> 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<TradeItProxyVoteUrlResponse> response = Response.success(tradeItProxyVoteUrlresponse);
callback.onResponse(call, response);
}

when: "calling getProxyVoteUrl"
TradeItProxyVoteUrlResponse proxyVoteUrlResponse = null
apiClient.getProxyVoteUrl(
"MyAccountNumber",
"BR",
new TradeItCallback<TradeItProxyVoteUrlResponse>() {

@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"
}
}