Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gd/proxyvote/164100440 #110

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,13 @@ private void getPositionsFirstLinkedBroker() {
showAlert("getPositionsFirstLinkedBroker", "No linked broker accounts detected for first linked broker! Try authenticating.");
} else {
TradeItLinkedBrokerParcelable linkedBroker = linkedBrokers.get(0);
for (TradeItLinkedBrokerAccountParcelable linkedBrokerAccount : linkedBroker.getAccounts()) {
for (final TradeItLinkedBrokerAccountParcelable linkedBrokerAccount : linkedBroker.getAccounts()) {
linkedBrokerAccount.refreshPositions(
new TradeItCallback<List<TradeItPositionParcelable>>() {
@Override
public void onSuccess(List<TradeItPositionParcelable> positions) {
Intent intent = new Intent(mainActivity, PositionsActivity.class);
intent.putExtra(PARCELED_ACCOUNT_PARAMETER, linkedBrokerAccount);
intent.putParcelableArrayListExtra(POSITIONS_PARAMETER, (ArrayList<? extends Parcelable>) positions);
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import java.util.List;

import it.trade.android.sdk.model.TradeItLinkedBrokerAccountParcelable;
import it.trade.android.sdk.model.TradeItPositionParcelable;
import it.trade.model.TradeItErrorResult;
import it.trade.model.callback.TradeItCallback;

import static it.trade.android.exampleapp.MainActivity.POSITIONS_PARAMETER;

Expand All @@ -19,10 +22,29 @@ public class PositionsActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_positions);
TextView textView = (TextView) this.findViewById(R.id.positions_textview);
final TextView textView = (TextView) this.findViewById(R.id.positions_textview);
textView.setMovementMethod(new ScrollingMovementMethod());
Intent intent = getIntent();
List<TradeItPositionParcelable> positions = intent.getParcelableArrayListExtra(POSITIONS_PARAMETER);
textView.setText(positions.toString());
TradeItLinkedBrokerAccountParcelable linkedBrokerAccount = intent.getParcelableExtra(MainActivity.PARCELED_ACCOUNT_PARAMETER);
TradeItPositionParcelable position = null;
for (TradeItPositionParcelable positionParcelable: positions) {
if (positionParcelable.isProxyVoteEligible) {
position = positionParcelable;
break;
}
}
linkedBrokerAccount.getProxyVoteUrl(position.symbol, new TradeItCallback<String>() {
@Override
public void onSuccess(String proxyVoteUrl) {
textView.setText("Proxyvote url for last position: " + proxyVoteUrl);
}

@Override
public void onError(TradeItErrorResult error) {
textView.setText("Error getting Proxyvote url for last position: " + error);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class MainActivity : AppCompatActivity() {
object : TradeItCallback<List<TradeItPositionParcelable>> {
override fun onSuccess(positions: List<TradeItPositionParcelable>) {
val intent = Intent(mainActivity, PositionsActivity::class.java)
intent.putExtra(PARCELED_ACCOUNT_PARAMETER, linkedBrokerAccount)
intent.putParcelableArrayListExtra(POSITIONS_PARAMETER, positions as ArrayList<out Parcelable>)
startActivity(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.method.ScrollingMovementMethod
import android.widget.TextView
import it.trade.android.sdk.model.TradeItLinkedBrokerAccountParcelable
import it.trade.android.sdk.model.TradeItPositionParcelable
import it.trade.model.TradeItErrorResult
import it.trade.model.callback.TradeItCallback


class PositionsActivity : AppCompatActivity() {
Expand All @@ -16,6 +19,20 @@ class PositionsActivity : AppCompatActivity() {
textView!!.movementMethod = ScrollingMovementMethod()
val intent = intent
val positions = intent.getParcelableArrayListExtra<TradeItPositionParcelable>(MainActivity.POSITIONS_PARAMETER)
val linkedBrokerAccount = intent.getParcelableExtra<TradeItLinkedBrokerAccountParcelable>(MainActivity.PARCELED_ACCOUNT_PARAMETER)
textView.text = positions.toString()
val position = positions.find { it.isProxyVoteEligible }
position?.let {
linkedBrokerAccount.getProxyVoteUrl(it.symbol, object : TradeItCallback<String> {
override fun onSuccess(proxyVoteUrl: String) {
textView.text = "Proxyvote url for last position: " + proxyVoteUrl
}

override fun onError(error: TradeItErrorResult?) {
textView.text = "Error getting Proxyvote url for last position: " + error
}

})
}
}
}
2 changes: 1 addition & 1 deletion tradeit-android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:appcompat-v7:27.1.1'
api 'it.trade:tradeit-java-api:1.1.18'
api 'it.trade:tradeit-java-api:1.1.19'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TradeItLinkedBrokerAccountParcelableTest {
position.quantity = 12.00
position.symbol = "GE"
position.lastPrice = 29.84
position.isProxyVoteEligible = false
val positions = ArrayList<TradeItPositionParcelable>()
positions.add(position)
linkedBrokerAccount!!.positions = positions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ class TradeItLinkedBrokerAccountParcelable : Parcelable {
)
}

fun getProxyVoteUrl(symbol: String, callback: TradeItCallback<String>) {
this.tradeItApiClient?.getProxyVoteUrl(
accountNumber,
symbol,
object : TradeItCallback<TradeItProxyVoteUrlResponse> {
override fun onSuccess(response: TradeItProxyVoteUrlResponse) {
response.proxyVoteUrl?.let { callback.onSuccess(it)}
?: callback.onError(TradeItErrorResultParcelable(
TradeItErrorCode.SYSTEM_ERROR,
"Position not eligible",
arrayListOf("This position is not eligible to proxy voting")
))
}

override fun onError(error: TradeItErrorResult) {
val errorResultParcelable = TradeItErrorResultParcelable(error)
callback.onError(errorResultParcelable)
}
}
)
}

private fun mapPositionsToPositionsParcelable(positions: List<TradeItPosition>): List<TradeItPositionParcelable> {
val positionsParcelable = ArrayList<TradeItPositionParcelable>()
for (position in positions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package it.trade.android.sdk.model

import android.os.Parcel
import android.os.Parcelable

import it.trade.model.reponse.TradeItPosition

class TradeItPositionParcelable : TradeItPosition, Parcelable {
Expand All @@ -22,6 +21,7 @@ class TradeItPositionParcelable : TradeItPosition, Parcelable {
this.totalGainLossAbsolute = position.totalGainLossAbsolute
this.exchange = position.exchange
this.currency = position.currency
this.isProxyVoteEligible = position.isProxyVoteEligible
}

constructor() : super() {}
Expand All @@ -45,6 +45,7 @@ class TradeItPositionParcelable : TradeItPosition, Parcelable {
dest.writeValue(this.totalGainLossAbsolute)
dest.writeString(this.exchange)
dest.writeString(this.currency)
dest.writeByte((if (isProxyVoteEligible) 1 else 0).toByte())
}

protected constructor(`in`: Parcel) {
Expand All @@ -62,6 +63,7 @@ class TradeItPositionParcelable : TradeItPosition, Parcelable {
this.totalGainLossAbsolute = `in`.readValue(Double::class.java.getClassLoader()) as? Double
this.exchange = `in`.readString()
this.currency = `in`.readString()
this.isProxyVoteEligible = `in`.readByte().toInt() != 0
}

companion object {
Expand Down