-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
ImplicitApi
github-actions[bot] edited this page Jun 11, 2026
·
1 revision
package examples;
import io.github.ccxt.exchanges.Binance;
import io.github.ccxt.types.Ticker;
import io.github.ccxt.types.Trade;
import io.github.ccxt.types.OrderBook;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Demonstrates both the typed unified API and exchange-specific implicit API methods.
*
* The unified API (fetchTicker, fetchTrades, etc.) returns typed objects directly.
* The implicit API (publicGetTicker24hr, sapiGetAccount, etc.) provides access to
* exchange-specific endpoints that may not have a unified wrapper.
*
* Usage:
* cd java && ./gradlew :examples:run -PmainClass=examples.ImplicitApi
*/
public class ImplicitApi {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
// Create a concrete exchange class to access exchange-specific methods
Binance exchange = new Binance();
exchange.loadMarkets(false);
String symbol = "BTC/USDT";
// ==========================================
// 1. Unified API — typed methods on Binance
// ==========================================
System.out.println("=== Unified Typed API ===\n");
// fetchTicker returns Ticker directly
Ticker ticker = exchange.fetchTicker(symbol);
System.out.println("Ticker: " + ticker.symbol + " last=" + ticker.last
+ " bid=" + ticker.bid + " ask=" + ticker.ask);
// fetchTrades returns List<Trade> directly
List<Trade> trades = exchange.fetchTrades(symbol, null, 3L, null);
System.out.println("\nRecent trades:");
for (Trade t : trades) {
System.out.printf(" %s %-4s price=%-12.2f amount=%.6f%n",
t.datetime, t.side, t.price, t.amount);
}
// fetchOrderBook returns OrderBook directly
OrderBook ob = exchange.fetchOrderBook(symbol, 5L, null);
System.out.println("\nOrder book (top 5):");
System.out.println(" Bids:");
for (List<Double> bid : ob.bids) {
System.out.printf(" %.2f x %.6f%n", bid.get(0), bid.get(1));
}
System.out.println(" Asks:");
for (List<Double> ask : ob.asks) {
System.out.printf(" %.2f x %.6f%n", ask.get(0), ask.get(1));
}
// ==========================================
// 2. Implicit API — exchange-specific endpoints
// ==========================================
System.out.println("\n=== Implicit (Exchange-Specific) API ===\n");
// Binance publicGetTicker24hr — returns raw exchange response as Object
Map<String, Object> params = new HashMap<>();
params.put("symbol", "BTCUSDT"); // Binance uses native symbol format
Object rawTicker = exchange.publicGetTicker24hr(params).join();
Map<String, Object> tickerMap = (Map<String, Object>) rawTicker;
System.out.println("publicGetTicker24hr (raw Binance response):");
System.out.println(" symbol: " + tickerMap.get("symbol"));
System.out.println(" lastPrice: " + tickerMap.get("lastPrice"));
System.out.println(" volume: " + tickerMap.get("volume"));
System.out.println(" priceChange: " + tickerMap.get("priceChange"));
// Binance publicGetDepth — raw order book
params.clear();
params.put("symbol", "BTCUSDT");
params.put("limit", 3);
Object rawDepth = exchange.publicGetDepth(params).join();
Map<String, Object> depthMap = (Map<String, Object>) rawDepth;
List<Object> bids = (List<Object>) depthMap.get("bids");
System.out.println("\npublicGetDepth (raw Binance response):");
System.out.println(" top bid: " + bids.get(0));
// Binance publicGetExchangeInfo — server info
Object rawInfo = exchange.publicGetExchangeInfo(null).join();
Map<String, Object> infoMap = (Map<String, Object>) rawInfo;
System.out.println("\npublicGetExchangeInfo:");
System.out.println(" timezone: " + infoMap.get("timezone"));
System.out.println(" serverTime: " + infoMap.get("serverTime"));
List<Object> symbols = (List<Object>) infoMap.get("symbols");
System.out.println(" symbols: " + symbols.size() + " trading pairs");
System.out.println("\nDone!");
}
}(If the page is not being rendered for you, you can refer to the mirror at https://docs.ccxt.com/)
- Install
- Examples
- Manual
- CCXT Pro
- Contributing
- Supported Exchanges
- Exchanges By Country
- API Spec By Method
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- fetchCurrencies
- alpaca
- apex
- ascendex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmart
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- coinmate
- coinmetro
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- exmo
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- fetchBidsAsks
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- ndax
- novadax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- fetchStatus