@Test public void getAccountInfo_success() throws Exception { when(mockAuthApi.makeRequest(eq(GET_INFO), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\n" + "\t\"success\":1,\n" + "\t\t\"return\":{\n" + "\t\t\"funds\":{\n" + "\t\t\t\"usd\":325,\n" + "\t\t\t\"btc\":23.998,\n" + "\t\t\t\"sc\":121.998,\n" + "\t\t\t\"ltc\":0,\n" + "\t\t\t\"ruc\":0,\n" + "\t\t\t\"nmc\":0\n" + "\t\t},\n" + "\t\t\"rights\":{\n" + "\t\t\t\"info\":1,\n" + "\t\t\t\"trade\":1\n" + "\t\t},\n" + "\t\t\"transaction_count\":80,\n" + "\t\t\"open_orders\":1,\n" + "\t\t\"server_time\":1342123547\n" + "\t}\n" + "}").getAsJsonObject()); CallResult<AccountInfo> callResult = testable.getAccountInfo(); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); AccountInfo accountInfo = callResult.getPayload(); assertNotNull(accountInfo); assertEquals(80, accountInfo.getTransactionCount()); assertEquals(1, accountInfo.getOpenOrdersCount()); assertEquals(1342123547, accountInfo.getServerTime()); assertEquals(new BigDecimal("23.998"), accountInfo.getFunds().get("BTC")); }
@NonNull @WorkerThread public CallResult<AccountInfo> getAccountInfo() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.GET_INFO, null); CallResult<AccountInfo> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = AccountInfo.create(response.getAsJsonObject(RETURN_KEY)); return result; }
Api { @NonNull @WorkerThread public CallResult<AccountInfo> getAccountInfo() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.GET_INFO, null); CallResult<AccountInfo> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = AccountInfo.create(response.getAsJsonObject(RETURN_KEY)); return result; } }
Api { @NonNull @WorkerThread public CallResult<AccountInfo> getAccountInfo() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.GET_INFO, null); CallResult<AccountInfo> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = AccountInfo.create(response.getAsJsonObject(RETURN_KEY)); return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); }
Api { @NonNull @WorkerThread public CallResult<AccountInfo> getAccountInfo() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.GET_INFO, null); CallResult<AccountInfo> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = AccountInfo.create(response.getAsJsonObject(RETURN_KEY)); return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); void setCredentials(@NonNull String apiKey, @NonNull String apiSecret); void setHostUrl(@NonNull String hostUrl); @WorkerThread @NonNull CallResult<ExchangeInfo> getExchangeInfo(); @WorkerThread @NonNull CallResult<List<Ticker>> getPairInfo(@NonNull Set<String> pairs); @NonNull @WorkerThread CallResult<Depth> depth(@NonNull String pair); @NonNull @WorkerThread CallResult<AccountInfo> getAccountInfo(); @NonNull @WorkerThread CallResult<List<Transaction>> getTransactionsHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<TradeHistoryEntry>> getTradeHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<ActiveOrder>> getActiveOrders(); @NonNull @WorkerThread CallResult<TradeResponse> trade(@NonNull String pair, @TradeType @NonNull String type,
                                           @NonNull String rate, @NonNull String amount); @NonNull @WorkerThread CallResult<CancelOrderResponse> cancelOrder(long orderId); @NonNull @WorkerThread CallResult<WithdrawResponse> withdraw(@NonNull String coinName,
                                                 double amount, @NonNull String address); }
Api { @NonNull @WorkerThread public CallResult<AccountInfo> getAccountInfo() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.GET_INFO, null); CallResult<AccountInfo> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = AccountInfo.create(response.getAsJsonObject(RETURN_KEY)); return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); void setCredentials(@NonNull String apiKey, @NonNull String apiSecret); void setHostUrl(@NonNull String hostUrl); @WorkerThread @NonNull CallResult<ExchangeInfo> getExchangeInfo(); @WorkerThread @NonNull CallResult<List<Ticker>> getPairInfo(@NonNull Set<String> pairs); @NonNull @WorkerThread CallResult<Depth> depth(@NonNull String pair); @NonNull @WorkerThread CallResult<AccountInfo> getAccountInfo(); @NonNull @WorkerThread CallResult<List<Transaction>> getTransactionsHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<TradeHistoryEntry>> getTradeHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<ActiveOrder>> getActiveOrders(); @NonNull @WorkerThread CallResult<TradeResponse> trade(@NonNull String pair, @TradeType @NonNull String type,
                                           @NonNull String rate, @NonNull String amount); @NonNull @WorkerThread CallResult<CancelOrderResponse> cancelOrder(long orderId); @NonNull @WorkerThread CallResult<WithdrawResponse> withdraw(@NonNull String coinName,
                                                 double amount, @NonNull String address);  }