(String[] args)
| 18 | static int failed = 0; |
| 19 | |
| 20 | public static void main(String[] args) throws Exception { |
| 21 | String proxyHost = System.getenv("PROXY_HOST") != null ? System.getenv("PROXY_HOST") : "127.0.0.1"; |
| 22 | String proxyPort = System.getenv("PROXY_PORT") != null ? System.getenv("PROXY_PORT") : "18911"; |
| 23 | String proxyUrl = "http://" + proxyHost + ":" + proxyPort; |
| 24 | |
| 25 | System.out.println("Testing with httpProxy=" + proxyUrl + "\n"); |
| 26 | |
| 27 | // ── Test 1: fetchTicker via httpProxy ── |
| 28 | test("fetchTicker via httpProxy", () -> { |
| 29 | Map<String, Object> config = new HashMap<>(); |
| 30 | config.put("httpProxy", proxyUrl); |
| 31 | Exchange ex = Exchange.dynamicallyCreateInstance("binance", config); |
| 32 | ex.loadMarkets().get(30, TimeUnit.SECONDS); |
| 33 | @SuppressWarnings("unchecked") |
| 34 | Map<String, Object> ticker = (Map<String, Object>) ((java.util.concurrent.CompletableFuture<Object>) Helpers.callDynamically(ex, "fetchTicker", new Object[]{"BTC/USDT"})).get(15, TimeUnit.SECONDS); |
| 35 | assert ticker.get("symbol").equals("BTC/USDT") : "symbol mismatch"; |
| 36 | assert ticker.get("last") != null : "last price is null"; |
| 37 | return "symbol=" + ticker.get("symbol") + " last=" + ticker.get("last"); |
| 38 | }); |
| 39 | |
| 40 | // ── Test 2: fetchOrderBook via httpProxy ── |
| 41 | test("fetchOrderBook via httpProxy", () -> { |
| 42 | Map<String, Object> config = new HashMap<>(); |
| 43 | config.put("httpProxy", proxyUrl); |
| 44 | Exchange ex = Exchange.dynamicallyCreateInstance("binance", config); |
| 45 | ex.loadMarkets().get(30, TimeUnit.SECONDS); |
| 46 | @SuppressWarnings("unchecked") |
| 47 | Map<String, Object> ob = (Map<String, Object>) ((java.util.concurrent.CompletableFuture<Object>) Helpers.callDynamically(ex, "fetchOrderBook", new Object[]{"ETH/USDT"})).get(15, TimeUnit.SECONDS); |
| 48 | List<?> asks = (List<?>) ob.get("asks"); |
| 49 | List<?> bids = (List<?>) ob.get("bids"); |
| 50 | assert asks != null && !asks.isEmpty() : "no asks"; |
| 51 | assert bids != null && !bids.isEmpty() : "no bids"; |
| 52 | return "asks=" + asks.size() + " bids=" + bids.size(); |
| 53 | }); |
| 54 | |
| 55 | // ── Test 3: fetchTrades via httpProxy ── |
| 56 | test("fetchTrades via httpProxy", () -> { |
| 57 | Map<String, Object> config = new HashMap<>(); |
| 58 | config.put("httpProxy", proxyUrl); |
| 59 | Exchange ex = Exchange.dynamicallyCreateInstance("binance", config); |
| 60 | ex.loadMarkets().get(30, TimeUnit.SECONDS); |
| 61 | @SuppressWarnings("unchecked") |
| 62 | List<?> trades = (List<?>) ((java.util.concurrent.CompletableFuture<Object>) Helpers.callDynamically(ex, "fetchTrades", new Object[]{"BTC/USDT"})).get(15, TimeUnit.SECONDS); |
| 63 | assert trades != null && !trades.isEmpty() : "no trades"; |
| 64 | return "trades=" + trades.size(); |
| 65 | }); |
| 66 | |
| 67 | // ── Test 4: httpsProxy also works ── |
| 68 | test("fetchTicker via httpsProxy", () -> { |
| 69 | Map<String, Object> config = new HashMap<>(); |
| 70 | config.put("httpsProxy", proxyUrl); |
| 71 | Exchange ex = Exchange.dynamicallyCreateInstance("binance", config); |
| 72 | ex.loadMarkets().get(30, TimeUnit.SECONDS); |
| 73 | @SuppressWarnings("unchecked") |
| 74 | Map<String, Object> ticker = (Map<String, Object>) ((java.util.concurrent.CompletableFuture<Object>) Helpers.callDynamically(ex, "fetchTicker", new Object[]{"BTC/USDT"})).get(15, TimeUnit.SECONDS); |
| 75 | assert ticker.get("last") != null : "last price is null"; |
| 76 | return "last=" + ticker.get("last"); |
| 77 | }); |
nothing calls this directly
no test coverage detected