Added support for the GetLimitOrders API call in the single connection mode
This commit is contained in:
parent
119a7cafba
commit
81d61986ea
6 changed files with 101 additions and 1 deletions
|
@ -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){
|
||||
|
|
|
@ -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<JsonRpcResponse<List<Asset>>>(){}.getType();
|
||||
parsedResponse = gson.fromJson(text, LisAssetsResponse);
|
||||
}else if(requestClass == GetLimitOrders.class){
|
||||
Type GetLimitOrdersResponse = new TypeToken<JsonRpcResponse<List<LimitOrder>>>() {}.getType();
|
||||
parsedResponse = gson.fromJson(text, GetLimitOrdersResponse);
|
||||
}else{
|
||||
Log.w(TAG,"Unknown request class");
|
||||
}
|
||||
|
|
|
@ -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 <a href="https://goo.gl/5sRTRq">get_limit_orders API doc</a>
|
||||
*
|
||||
*/
|
||||
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<Serializable> 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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -40,4 +40,9 @@
|
|||
|
||||
<!-- Get account by name fields -->
|
||||
<string name="get_accounts_by_name_arg1">Account name</string>
|
||||
|
||||
<!-- GetLimitOrders input fields -->
|
||||
<string name="get_limit_orders_arg1">Asset A</string>
|
||||
<string name="get_limit_orders_arg2">Asset B</string>
|
||||
<string name="get_limit_orders_arg3">Number of orders</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue