diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java index d3ed6e6..3fedb42 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java @@ -13,11 +13,14 @@ import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; import cy.agorise.graphenej.AssetOptions; import cy.agorise.graphenej.Authority; +import cy.agorise.graphenej.LimitOrder; import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.UserAccount; import cy.agorise.graphenej.api.calls.GetAccountByName; import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetBlock; import cy.agorise.graphenej.api.calls.GetBlockHeader; +import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetMarketHistory; import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; @@ -127,6 +130,15 @@ public class DeserializationMap { .registerTypeAdapter(AccountOptions.class, new AccountOptions.AccountOptionsDeserializer()) .create(); mGsonMap.put(GetAccountByName.class, getAccountByNameGson); + + // GetLimitOrders + mClassMap.put(GetLimitOrders.class, List.class); + Gson getLimitOrdersGson = new GsonBuilder() + .registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()) + .registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()) + .registerTypeAdapter(LimitOrder.class, new LimitOrder.LimitOrderDeserializer()) + .create(); + mGsonMap.put(GetLimitOrders.class, getLimitOrdersGson); } public Class getReceivedClass(Class _class){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index 6c04789..58f69d1 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -20,12 +20,14 @@ import java.util.List; import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.LimitOrder; import cy.agorise.graphenej.RPC; import cy.agorise.graphenej.api.ApiAccess; import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.bitshares.Nodes; import cy.agorise.graphenej.api.calls.ApiCallable; import cy.agorise.graphenej.api.calls.GetAccounts; +import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetMarketHistory; import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory; @@ -333,6 +335,9 @@ public class NetworkService extends Service { }else if(requestClass == ListAssets.class){ Type LisAssetsResponse = new TypeToken>>(){}.getType(); parsedResponse = gson.fromJson(text, LisAssetsResponse); + }else if(requestClass == GetLimitOrders.class){ + Type GetLimitOrdersResponse = new TypeToken>>() {}.getType(); + parsedResponse = gson.fromJson(text, GetLimitOrdersResponse); }else{ Log.w(TAG,"Unknown request class"); } diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetLimitOrders.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetLimitOrders.java new file mode 100644 index 0000000..9061b8c --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetLimitOrders.java @@ -0,0 +1,41 @@ +package cy.agorise.graphenej.api.calls; + +import java.io.Serializable; +import java.util.ArrayList; + +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.api.ApiAccess; +import cy.agorise.graphenej.models.ApiCall; + +/** Class that implements get_limit_orders request handler. + * + * Get limit orders in a given market. + * + * The request returns the limit orders, ordered from least price to greatest + * + * @see get_limit_orders API doc + * + */ +public class GetLimitOrders implements ApiCallable { + + public static final int REQUIRED_API = ApiAccess.API_DATABASE; + + private String a; + private String b; + private int limit; + + public GetLimitOrders(String a, String b, int limit){ + this.a = a; + this.b = b; + this.limit = limit; + } + + @Override + public ApiCall toApiCall(int apiId, long sequenceId) { + ArrayList parameters = new ArrayList<>(); + parameters.add(a); + parameters.add(b); + parameters.add(limit); + return new ApiCall(apiId, RPC.CALL_GET_LIMIT_ORDERS, parameters, RPC.VERSION, sequenceId); + } +} diff --git a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java index 2faa8bb..37df8fa 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java @@ -44,7 +44,8 @@ public class CallsActivity extends AppCompatActivity { RPC.CALL_GET_REQUIRED_FEES, RPC.CALL_LOOKUP_ASSET_SYMBOLS, RPC.CALL_LIST_ASSETS, - RPC.CALL_GET_ACCOUNT_BY_NAME + RPC.CALL_GET_ACCOUNT_BY_NAME, + RPC.CALL_GET_LIMIT_ORDERS }; @NonNull diff --git a/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java b/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java index f8a8927..8df6dd1 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/PerformCallActivity.java @@ -30,6 +30,7 @@ import cy.agorise.graphenej.api.android.RxBus; import cy.agorise.graphenej.api.calls.GetAccountByName; import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetBlock; +import cy.agorise.graphenej.api.calls.GetLimitOrders; import cy.agorise.graphenej.api.calls.GetObjects; import cy.agorise.graphenej.api.calls.ListAssets; import cy.agorise.graphenej.models.JsonRpcResponse; @@ -120,8 +121,12 @@ public class PerformCallActivity extends ConnectedActivity { break; case RPC.CALL_LIST_ASSETS: setupListAssets(); + break; case RPC.CALL_GET_ACCOUNT_BY_NAME: setupAccountByName(); + break; + case RPC.CALL_GET_LIMIT_ORDERS: + setupGetLimitOrders(); default: Log.d(TAG,"Default called"); } @@ -205,6 +210,17 @@ public class PerformCallActivity extends ConnectedActivity { param1.setInputType(InputType.TYPE_CLASS_TEXT); } + private void setupGetLimitOrders(){ + requiredInput(3); + Resources resources = getResources(); + mParam1View.setHint(resources.getString(R.string.get_limit_orders_arg1)); + mParam2View.setHint(resources.getString(R.string.get_limit_orders_arg2)); + mParam3View.setHint(resources.getString(R.string.get_limit_orders_arg3)); + param1.setInputType(InputType.TYPE_CLASS_TEXT); + param2.setInputType(InputType.TYPE_CLASS_TEXT); + param3.setInputType(InputType.TYPE_CLASS_NUMBER); + } + private void requiredInput(int inputCount){ if(inputCount == 1){ mParam1View.setVisibility(View.VISIBLE); @@ -252,8 +268,12 @@ public class PerformCallActivity extends ConnectedActivity { break; case RPC.CALL_LIST_ASSETS: sendListAssets(); + break; case RPC.CALL_GET_ACCOUNT_BY_NAME: getAccountByName(); + break; + case RPC.CALL_GET_LIMIT_ORDERS: + getLimitOrders(); default: Log.d(TAG,"Default called"); } @@ -302,6 +322,18 @@ public class PerformCallActivity extends ConnectedActivity { responseMap.put(id, mRPC); } + private void getLimitOrders(){ + String assetA = param1.getText().toString(); + String assetB = param2.getText().toString(); + try{ + int limit = Integer.parseInt(param3.getText().toString()); + long id = mNetworkService.sendMessage(new GetLimitOrders(assetA, assetB, limit), GetLimitOrders.REQUIRED_API); + }catch(NumberFormatException e){ + Toast.makeText(this, getString(R.string.error_number_format), Toast.LENGTH_SHORT).show(); + Log.e(TAG,"NumberFormatException while trying to read limit value. Msg: "+e.getMessage()); + } + } + /** * Internal method that will decide what to do with each JSON-RPC response * @@ -341,6 +373,10 @@ public class PerformCallActivity extends ConnectedActivity { break; case RPC.CALL_GET_ACCOUNT_BY_NAME: mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); + break; + case RPC.CALL_GET_LIMIT_ORDERS: + mResponseView.setText(mResponseView.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n"); + break; default: Log.w(TAG,"Case not handled"); mResponseView.setText(mResponseView.getText() + response.result.toString()); diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 112c1f6..fce56cc 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -40,4 +40,9 @@ Account name + + + Asset A + Asset B + Number of orders