@Test public void info_success() throws Exception { when(mockGuestApi.call(anyString())) .thenReturn(JSON_PARSER.parse("{\"server_time\":1505766539," + "\"pairs\":{\"btc_usd\":{\"decimal_places\":3,\"min_price\":0.1," + "\"max_price\":10000,\"min_amount\":0.001,\"hidden\":0,\"fee\":0.2}," + "\"btc_rur\":{\"decimal_places\":5,\"min_price\":1,\"max_price\":1000000," + "\"min_amount\":0.001,\"hidden\":0,\"fee\":0.2}}}").getAsJsonObject()); CallResult<ExchangeInfo> callResult = testable.getExchangeInfo(); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); ExchangeInfo exchangeInfo = callResult.getPayload(); assertNotNull(exchangeInfo); assertEquals(1505766539L, exchangeInfo.getServerTime()); assertNotNull(exchangeInfo.getPairs()); assertEquals(2, exchangeInfo.getPairs().size()); ExchangePairInfo pairInfo = findByKey(exchangeInfo.getPairs(), new Predicate<ExchangePairInfo>() { @Override public boolean check(ExchangePairInfo element) { return "BTC/RUR".equals(element.getPair()); } }); assertNotNull(pairInfo); assertEquals("BTC/RUR", pairInfo.getPair()); assertEquals(5, pairInfo.getDecimalPlaces()); assertEquals(new BigDecimal("1"), pairInfo.getMinPrice()); assertEquals(new BigDecimal("1000000").toPlainString(), pairInfo.getMaxPrice().toPlainString()); assertEquals(new BigDecimal("0.001"), pairInfo.getMinAmount()); assertFalse(pairInfo.isHidden()); assertEquals(new BigDecimal("0.2"), pairInfo.getFee()); }
@WorkerThread @NonNull public CallResult<ExchangeInfo> getExchangeInfo() { JsonObject response = guestApi.call(hostUrl + "/api/3/info"); CallResult<ExchangeInfo> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = ExchangeInfo.create(response); return result; }
Api { @WorkerThread @NonNull public CallResult<ExchangeInfo> getExchangeInfo() { JsonObject response = guestApi.call(hostUrl + "/api/3/info"); CallResult<ExchangeInfo> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = ExchangeInfo.create(response); return result; } }
Api { @WorkerThread @NonNull public CallResult<ExchangeInfo> getExchangeInfo() { JsonObject response = guestApi.call(hostUrl + "/api/3/info"); CallResult<ExchangeInfo> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = ExchangeInfo.create(response); 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 { @WorkerThread @NonNull public CallResult<ExchangeInfo> getExchangeInfo() { JsonObject response = guestApi.call(hostUrl + "/api/3/info"); CallResult<ExchangeInfo> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = ExchangeInfo.create(response); 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 { @WorkerThread @NonNull public CallResult<ExchangeInfo> getExchangeInfo() { JsonObject response = guestApi.call(hostUrl + "/api/3/info"); CallResult<ExchangeInfo> result = new CallResult<>(); if (response == null || response.has(SUCCESS_KEY)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; result.payload = ExchangeInfo.create(response); 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);  }