-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from 15 commits
d3d0936
08c53f1
83efb26
b39c794
b770676
aff438f
36e08ee
75b8b06
6b8b9ad
26838d9
995347c
c80ede1
84dc18a
bba3088
8706437
6241cb6
5a0bde5
103dbce
9e4edc2
1b7263f
a392954
8451a9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -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 { | ||
|
@@ -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; | ||
|
||
|
@@ -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) { | ||
|
@@ -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(); | ||
|
@@ -499,6 +516,84 @@ private void previewTradeFirstLinkedBroker() { | |
} | ||
} | ||
|
||
private void previewCryptoTradeFirstCryptoBrokerAccount() { | ||
final MainActivity mainActivity = this; | ||
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers(); | ||
if (linkedBrokers.isEmpty()) { | ||
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!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this into a guard-style 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to extract these to a |
||
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()); | ||
|
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 |
---|---|---|
@@ -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> |
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> |
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()) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done