ccxt-java
它能做什么
这个技能是在 Java 应用中使用 CCXT 库构建加密交易所功能的指南。适合用 Java 开发交易系统或金融软件的开发者。
适用场景
- ✓当你正在构建从交易所读取加密货币价格的 Java 应用的时候。
- ✓当你需要从 Java 交易系统下单的时候。
- ✓当你想在 Java 项目中获取实时行情更新的时候。
技能链接
https://github.com/ccxt/ccxt/blob/master/.claude/skills/ccxt-java/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Java 类,打印 Kraken 上当前的 ETH/USDT 价格?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会使用 CCXT Java 包,创建一个有类型的交易所类,并根据任务调用 REST 或 WebSocket 方法。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
CCXT for Java
A comprehensive guide to using CCXT in Java projects for cryptocurrency exchange integration.
Installation
Via Gradle
// build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'io.github.ccxt:ccxt:latest.release'
}
Via Maven
<dependency>
<groupId>io.github.ccxt</groupId>
<artifactId>ccxt</artifactId>
<version>LATEST</version>
</dependency>
Requirements
- Java 21 or higher (uses virtual threads)
Quick Start
REST API
import io.github.ccxt.exchanges.Binance;
import io.github.ccxt.types.Ticker;
Binance exchange = new Binance();
exchange.loadMarkets(false);
Ticker ticker = exchange.fetchTicker("BTC/USDT");
System.out.println(ticker.last);
WebSocket API - Real-time Updates
import io.github.ccxt.exchanges.pro.Binance;
var exchange = new Binance();
exchange.loadMarkets(false);
while (true) {
Ticker ticker = exchange.watchTicker("BTC/USDT"); // typed sync, blocks for one update
System.out.println(ticker.last);
}
Architecture: Typed Subclasses
Each exchange has two classes following the Go pattern:
BinanceCore- transpiled untyped class (internal, extendsBinanceApiextendsExchange)Binance- typed wrapper extending Core with typed overloads (user-facing)
// User-facing typed class (recommended)
Binance exchange = new Binance();
Ticker ticker = exchange.fetchTicker("BTC/USDT"); // returns Ticker
List<Trade> trades = exchange.fetchTrades("BTC/USDT"); // returns List<Trade>
// Exchange-specific implicit API methods are also accessible
Object raw = exchange.publicGetTicker24hr(params).join(); // Binance-specific endpoint
// Properties accessible directly
exchange.apiKey = "...";
exchange.secret = "...";
The typed methods use Java method overloading. They coexist safely with untyped methods because Java resolves overloads at compile time: BinanceCore.java is compiled without knowledge of Binance.java's typed overloads, so internal calls always bind to untyped varargs.
REST vs WebSocket
| Feature | REST API | WebSocket API |
|---|---|---|
| Use for | One-time queries, placing orders | Real-time monitoring, live price feeds |
| Import | io.github.ccxt.exchanges.Binance |
io.github.ccxt.exchanges.pro.Binance |
| Methods | fetch* (fetchTicker, fetchOrderBook) |
watch* (watchTicker, watchOrderBook) |
| Returns | Typed objects (Ticker, List<Trade>) | CompletableFuture<Object> (call .join()) |
| Speed | Slower (HTTP request/response) | Faster (persistent connection) |
| Rate limits | Strict (1-2 req/sec) | More lenient (continuous stream) |
| Best for | Trading, account management | Price monitoring, arbitrage detection |
Creating Exchange Instance
REST API
import io.github.ccxt.exchanges.Binance;
import java.util.Map;
import java.util.HashMap;
// Public API (no authentication)
Binance exchange = new Binance();
// Private API (with authentication)
Map<String, Object> config = new HashMap<>();
config.put("apiKey", "YOUR_API_KEY");
config.put("secret", "YOUR_SECRET");
Binance exchange = new Binance(config);
WebSocket API
import io.github.ccxt.exchanges.pro.Binance;
// Public WebSocket
var exchange = new Binance();
// Private WebSocket (with authentication)
Map<String, Object> config = new HashMap<>();
config.put("apiKey", "YOUR_API_KEY");
config.put("secret", "YOUR_SECRET");
var exchange = new Binance(config);
Dynamic Instantiation (generic, untyped)
import io.github.ccxt.Exchange;
// Returns Exchange type - no typed methods, but works for any exchange
Exchange exchange = Exchange.dynamicallyCreateInstance("binance", config);
Object ticker = exchange.fetchTicker("BTC/USDT").join(); // untyped, returns CompletableFuture
Common REST Operations
Loading Markets
// Load all available trading pairs (typed)
Map<String, MarketInterface> markets = exchange.loadMarkets(false);
// Access market information
MarketInterface btcMarket = markets.get("BTC/USDT");
System.out.println(btcMarket.base); // "BTC"
System.out.println(btcMarket.quote); // "USDT"
System.out.println(btcMarket.active); // true
Fetching Ticker
// Single ticker (typed)
Ticker ticker = exchange.fetchTicker("BTC/USDT");
System.out.println(ticker.last); // Last price
System.out.println(ticker.bid); // Best bid
System
常见问题
需要哪个 Java 版本?
技能说明需要 Java 21 或更高版本,因为它使用了虚拟线程。
如何把这个库添加到项目中?
技能展示了 Gradle 和 Maven 的配置示例。
什么是有类型的交易所类?
技能解释,每个交易所都有一个有类型的类,使你的代码获得具名的返回类型,而不是泛型数据。
详情
作者的原始描述
CCXT cryptocurrency exchange library for Java developers. Covers both REST API (standard) and WebSocket API (real-time). Helps install CCXT, connect to exchanges, fetch market data, place orders, stream live tickers/orderbooks, handle authentication, and manage errors in Java projects. Use when working with crypto exchanges in Java applications, trading systems, or financial software. Requires Java 21+.
repo: ccxt/ccxt
热度
- GitHub 星标
- 45k
- 排名
- #6382
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
binance-agentic-wallet
45k帮你的智能体通过 baw 命令行管理 Binance Web3 钱包,包括登录、查询余额、转账、代币兑换和限价订单。
binance-sports-ai-analyzer
45k帮你的智能体查询世界杯比赛的预测、AI 分析和新闻洞察,并在你调整信号后重新计算胜率。
binance-tokenized-securities-info
45k帮你的智能体在 Binance Web3 上查询 Ondo 代币化美股,包括代币列表、公司信息、交易状态和链上价格。
binance
45k帮你的智能体通过 binance-cli 工具使用 Binance 现货、USD-M 合约和 Convert 功能。使用前需先完成身份验证设置。