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/sdk supports crypto/160078379 #104

Merged
merged 22 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3d0936
Update java api version
guillaumedebavelaere Sep 5, 2018
08c53f1
Create TradeItCryptoOrderParcelable and Implements previewCryptoOrder
guillaumedebavelaere Sep 5, 2018
83efb26
Add PreviewCryptoOrderActivity to exampleApp and implements previewCr…
guillaumedebavelaere Sep 5, 2018
b39c794
Add a parcelable preview crypto response
guillaumedebavelaere Sep 6, 2018
b770676
Add unit test for previewCryptoOrder
guillaumedebavelaere Sep 6, 2018
aff438f
Add toString method
guillaumedebavelaere Sep 6, 2018
36e08ee
Update preview crypto order Test and Activity
guillaumedebavelaere Sep 6, 2018
75b8b06
implements placeCryptoTrade
guillaumedebavelaere Sep 6, 2018
6b8b9ad
Add unit test place crypto order
guillaumedebavelaere Sep 6, 2018
26838d9
implements getCryptoQuote
guillaumedebavelaere Sep 7, 2018
995347c
getCryptoQuote - Add unit test
guillaumedebavelaere Sep 7, 2018
c80ede1
Add getCryptoQuote menu to exampleApp
guillaumedebavelaere Sep 7, 2018
84dc18a
add parcelables tests
guillaumedebavelaere Sep 7, 2018
bba3088
Add crypto menus to exampleAppKotlin
guillaumedebavelaere Sep 7, 2018
8706437
Add quoteLastPrice property to TradeItCryptoOrderParcelable
guillaumedebavelaere Sep 7, 2018
6241cb6
TradeItCryptoTradeOrderDetailsParcelable - Add toString() method
guillaumedebavelaere Sep 11, 2018
5a0bde5
Extract logic to fetch the first crypto account to getFirstCryptoAcco…
guillaumedebavelaere Sep 11, 2018
103dbce
Extract logic to fetch the first crypto account to getFirstCryptoAcco…
guillaumedebavelaere Sep 11, 2018
9e4edc2
cleanup when expression
guillaumedebavelaere Sep 11, 2018
1b7263f
MainActivity.java - guard-style if statement
guillaumedebavelaere Sep 12, 2018
a392954
MainActivity.kt - guard-style if statement
guillaumedebavelaere Sep 12, 2018
8451a9c
Refactor TradeItCryptoOrderParcelable - Add SymbolPairParcelable object
guillaumedebavelaere Sep 12, 2018
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
9 changes: 8 additions & 1 deletion exampleApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@
<activity
android:name=".PreviewOrderActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".PreviewCryptoOrderActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".BrokersListActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".OrdersStatusActivity"
<activity
android:name=".OrdersStatusActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".GetCryptoQuoteActivity"
android:parentActivityName=".MainActivity" />
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package it.trade.android.exampleapp;

import android.content.Intent;
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.TradeItCryptoQuoteResponseParcelable;

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

public class GetCryptoQuoteActivity extends AppCompatActivity {

private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_crypto_quote);

textView = (TextView) this.findViewById(R.id.get_crypto_quote_textview);
textView.setMovementMethod(new ScrollingMovementMethod());
Intent intent = getIntent();
TradeItCryptoQuoteResponseParcelable cryptoQuoteResponseParcelable = intent
.getParcelableExtra(GET_CRYPTO_QUOTE_PARAMETER);
textView.setText(cryptoQuoteResponseParcelable.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@
import android.widget.TableRow;
import android.widget.TextView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import it.trade.android.sdk.TradeItConfigurationBuilder;
import it.trade.android.sdk.TradeItSDK;
import it.trade.android.sdk.enums.TradeItOrderAction;
import it.trade.android.sdk.enums.TradeItOrderExpirationType;
import it.trade.android.sdk.enums.TradeItOrderPriceType;
import it.trade.android.sdk.enums.TradeItOrderQuantityType;
import it.trade.android.sdk.exceptions.TradeItDeleteLinkedLoginException;
import it.trade.android.sdk.exceptions.TradeItSaveLinkedLoginException;
import it.trade.android.sdk.manager.TradeItLinkedBrokerManager;
import it.trade.android.sdk.model.TradeItCallBackCompletion;
import it.trade.android.sdk.model.TradeItCallbackWithSecurityQuestionAndCompletion;
import it.trade.android.sdk.model.TradeItCryptoOrderParcelable;
import it.trade.android.sdk.model.TradeItCryptoQuoteResponseParcelable;
import it.trade.android.sdk.model.TradeItLinkedBrokerAccountData;
import it.trade.android.sdk.model.TradeItLinkedBrokerAccountParcelable;
import it.trade.android.sdk.model.TradeItLinkedBrokerData;
Expand All @@ -40,6 +45,7 @@
import it.trade.model.TradeItSecurityQuestion;
import it.trade.model.callback.TradeItCallback;
import it.trade.model.callback.TradeItCallbackWithSecurityQuestionImpl;
import it.trade.model.reponse.Instrument;
import it.trade.model.request.TradeItEnvironment;

public class MainActivity extends AppCompatActivity {
Expand All @@ -53,6 +59,7 @@ public class MainActivity extends AppCompatActivity {
public final static String ORDERS_STATUS_PARAMETER = "it.trade.android.exampleapp.ORDERS_STATUS";
public final static String PREVIEW_ORDER_PARAMETER = "it.trade.android.exampleapp.PREVIEW_ORDER";
public final static String RELINK_OAUTH_PARAMETER = "it.trade.android.exampleapp.RELINK_OAUTH";
public final static String GET_CRYPTO_QUOTE_PARAMETER = "it.trade.android.exampleapp.GET_CRYPTO_QUOTE";

private TradeItLinkedBrokerManager linkedBrokerManager;

Expand All @@ -75,7 +82,9 @@ public enum MainActivityActions {
PARCEL_FIRST_LINKED_BROKER_ACCOUNT("Parcel first linked broker account"),
GET_POSITIONS_FIRST_LINKED_BROKER_ACCOUNT("Get positions for first linked broker account"),
REFRESH_ORDERS_STATUS_FIRST_LINKED_BROKER_ACCOUNT("Refresh orders status for first linked broker account"),
PREVIEW_TRADE_FIRST_LINKED_BROKER_ACCOUNT("Preview trade for first linked broker account");
PREVIEW_TRADE_FIRST_LINKED_BROKER_ACCOUNT("Preview trade for first linked broker account"),
PREVIEW_CRYPTO_TRADE_FIRST_CRYPTO_BROKER_ACCOUNT("Preview crypto trade for first crypto broker account"),
GET_CRYPTO_QUOTE_FIRST_CRYPTO_BROKER_ACCOUNT("Get crypto quote for first crypto broker account");

private String label;
MainActivityActions(String label) {
Expand Down Expand Up @@ -217,6 +226,14 @@ public void onClick(View view) {
Log.d(TAG, "preview trade first linked broker account was tapped!");
previewTradeFirstLinkedBroker();
break;
case PREVIEW_CRYPTO_TRADE_FIRST_CRYPTO_BROKER_ACCOUNT:
Log.d(TAG, "preview trade first crypto broker account was tapped!");
previewCryptoTradeFirstCryptoBrokerAccount();
break;
case GET_CRYPTO_QUOTE_FIRST_CRYPTO_BROKER_ACCOUNT:
Log.d(TAG, "getCryptoQuote first crypto broker account was tapped!");
getCryptoQuoteFirstCryptoBrokerAccount();
break;
case SYNC_LOCAL_LINKED_BROKERS:
Log.d(TAG, "synch local linked brokers was tapped!");
syncLocalLinkedBrokers();
Expand Down Expand Up @@ -499,6 +516,84 @@ private void previewTradeFirstLinkedBroker() {
}
}

private void previewCryptoTradeFirstCryptoBrokerAccount() {
final MainActivity mainActivity = this;
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
if (linkedBrokers.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a guard-style statement so that the corresponding else block isn't so large. Something like:

if (linkedBrokers.isEmpty()) {
    showAlert("previewTradeFirstLinkedBroker", "No linked broker!");
    return;
}

// Then you don't need the else clause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

showAlert("previewTradeFirstLinkedBroker", "No linked broker!");
} else {
TradeItLinkedBrokerAccountParcelable cryptoAccount = null;
for (TradeItLinkedBrokerParcelable linkedBroker: linkedBrokers) {
if (cryptoAccount != null) {
break;
}
for (TradeItLinkedBrokerAccountParcelable accountParcelable: linkedBroker.getAccounts()) {
if(accountParcelable.getOrderCapabilityForInstrument(Instrument.CRYPTO) != null) {
cryptoAccount = accountParcelable;
break;
}
}
}
if (cryptoAccount != null) {
final TradeItCryptoOrderParcelable cryptoOrderParcelable = new TradeItCryptoOrderParcelable(
cryptoAccount,
"BTC/USD",
TradeItOrderAction.BUY
);
cryptoOrderParcelable.setPriceType(TradeItOrderPriceType.LIMIT);
cryptoOrderParcelable.setExpiration(TradeItOrderExpirationType.GOOD_FOR_DAY);
cryptoOrderParcelable.setLimitPrice(new BigDecimal(2000.0));
cryptoOrderParcelable.setOrderQuantityType(TradeItOrderQuantityType.QUOTE_CURRENCY);
cryptoOrderParcelable.setQuantity(new BigDecimal(1.0));
Intent intent = new Intent(mainActivity, PreviewCryptoOrderActivity.class);
intent.putExtra(PREVIEW_ORDER_PARAMETER, cryptoOrderParcelable);
startActivity(intent);
} else {
showAlert("previewTradeFirstLinkedBroker", "No crypto account!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this into a guard-style if statement like above so that you don't need the giant if/else block.

if (cryptoAccount == null) {
    showAlert("previewTradeFirstLinkedBroker", "No crypto account!");
    return;
}

// Do other stuff here

}
}
}

private void getCryptoQuoteFirstCryptoBrokerAccount() {
final MainActivity mainActivity = this;
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
if (linkedBrokers.isEmpty()) {
showAlert("getCryptoQuoteFirstCryptoBrokerAccount", "No linked broker!");
} else {
TradeItLinkedBrokerAccountParcelable cryptoAccount = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to extract these to a getCrytoAccunt function instead?

for (TradeItLinkedBrokerParcelable linkedBroker: linkedBrokers) {
if (cryptoAccount != null) {
break;
}
for (TradeItLinkedBrokerAccountParcelable accountParcelable: linkedBroker.getAccounts()) {
if(accountParcelable.getOrderCapabilityForInstrument(Instrument.CRYPTO) != null) {
cryptoAccount = accountParcelable;
break;
}
}
}
if (cryptoAccount != null) {
cryptoAccount.getCryptoQuote("BTC/USD", new TradeItCallback<TradeItCryptoQuoteResponseParcelable>() {
@Override
public void onSuccess(TradeItCryptoQuoteResponseParcelable tradeItCryptoQuoteResponseParcelable) {
Intent intent = new Intent(mainActivity, GetCryptoQuoteActivity.class);
intent.putExtra(GET_CRYPTO_QUOTE_PARAMETER, tradeItCryptoQuoteResponseParcelable);
startActivity(intent);
}

@Override
public void onError(TradeItErrorResult tradeItErrorResult) {
showAlert(tradeItErrorResult.getShortMessage(),
tradeItErrorResult.getLongMessages().toString()
);
}
});
} else {
showAlert("getCryptoQuoteFirstCryptoBrokerAccount", "No crypto account!");
}
}
}

private void goToLinkedBrokersActivity() {
Intent intent = new Intent(this.getApplicationContext(), LinkedBrokersActivity.class);
intent.putParcelableArrayListExtra(LINKED_BROKERS_PARAMETER, (ArrayList<? extends Parcelable>) linkedBrokerManager.getLinkedBrokers());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package it.trade.android.exampleapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import it.trade.android.sdk.model.TradeItCryptoOrderParcelable;
import it.trade.android.sdk.model.TradeItPlaceCryptoOrderResponseParcelable;
import it.trade.android.sdk.model.TradeItPreviewCryptoOrderResponseParcelable;
import it.trade.android.sdk.model.orderstatus.TradeItOrderStatusParcelable;
import it.trade.model.TradeItErrorResult;
import it.trade.model.callback.TradeItCallback;

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

public class PreviewCryptoOrderActivity extends AppCompatActivity {
private static final String TAG = PreviewCryptoOrderActivity.class.getName();
private String orderId;
private TradeItCryptoOrderParcelable order;
private TextView textView;
private Button cancelOrderButton;
String orderNumber = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview_order);
textView = (TextView) this.findViewById(R.id.preview_order_textview);
textView.setMovementMethod(new ScrollingMovementMethod());
Intent intent = getIntent();
order = intent.getParcelableExtra(PREVIEW_ORDER_PARAMETER);
final Button placeOrderButton = (Button) this.findViewById(R.id.place_trade_button);
cancelOrderButton = (Button) this.findViewById(R.id.cancel_order_button);
order.previewCryptoOrder(new TradeItCallback<TradeItPreviewCryptoOrderResponseParcelable>() {
@Override
public void onSuccess(TradeItPreviewCryptoOrderResponseParcelable response) {
textView.setText(response.toString());
orderId = response.getOrderId();
placeOrderButton.setEnabled(true);
}

@Override
public void onError(TradeItErrorResult error) {
Log.e(TAG, "ERROR previewCryptoOrder: " + error);
textView.setText("ERROR previewCryptoOrder: " + error);
}
});
}

public void placeTrade(View view) {
order.placeCryptoOrder(orderId, new TradeItCallback<TradeItPlaceCryptoOrderResponseParcelable>() {
@Override
public void onSuccess(TradeItPlaceCryptoOrderResponseParcelable placeOrderResponse) {
textView.append(placeOrderResponse.toString());
cancelOrderButton.setEnabled(true);
orderNumber = placeOrderResponse.getOrderNumber();
}

@Override
public void onError(TradeItErrorResult error) {
Log.e(TAG, "ERROR placeOrder: " + error.toString());
textView.setText("ERROR placeOrder: " + error);
}
});
}

public void cancelOrder(View view) {
order.getLinkedBrokerAccount().cancelOrder(orderNumber, new TradeItCallback<TradeItOrderStatusParcelable>() {
@Override
public void onSuccess(TradeItOrderStatusParcelable orderStatusParcelable) {
textView.append(orderStatusParcelable.toString());
}

@Override
public void onError(TradeItErrorResult error) {
Log.e(TAG, "ERROR cancelOrder: " + error.toString());
textView.setText("ERROR cancelOrder: " + error);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static it.trade.android.exampleapp.MainActivity.PREVIEW_ORDER_PARAMETER;

public class PreviewOrderActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getName();
private static final String TAG = PreviewOrderActivity.class.getName();
private String orderId;
private TradeItOrderParcelable order;
private TextView textView;
Expand Down
25 changes: 25 additions & 0 deletions exampleApp/src/main/res/layout/activity_get_crypto_quote.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_get_crypto_quote"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="it.trade.android.exampleapp.GetCryptoQuoteActivity">

<TextView
android:id="@+id/get_crypto_quote_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="10dp"
android:gravity="bottom"
android:scrollbars="vertical"
android:text="..."
android:textSize="10sp"
android:typeface="monospace" />

</RelativeLayout>
1 change: 1 addition & 0 deletions exampleApp/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">10dp</dimen>
<dimen name="activity_vertical_margin">10dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
1 change: 1 addition & 0 deletions exampleApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">AndroidExampleApp</string>
<string name="title_activity_get_crypto_quote">GetCryptoQuoteActivity</string>
</resources>
6 changes: 6 additions & 0 deletions exampleAppKotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@
<activity
android:name=".PreviewOrderActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".PreviewCryptoOrderActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".BrokersListActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".OrdersStatusActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".GetCryptoQuoteActivity"
android:parentActivityName=".MainActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.trade.android.exampleapp

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.TradeItCryptoQuoteResponseParcelable

class GetCryptoQuoteActivity : AppCompatActivity() {

private var textView: TextView? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_get_crypto_quote)

textView = this.findViewById(R.id.get_crypto_quote_textview) as TextView
textView!!.movementMethod = ScrollingMovementMethod()
val intent = intent
val cryptoQuoteResponseParcelable = intent
.getParcelableExtra(MainActivity.GET_CRYPTO_QUOTE_PARAMETER) as TradeItCryptoQuoteResponseParcelable
textView!!.setText(cryptoQuoteResponseParcelable.toString())
}

}
Loading