百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

binance-futures-connector-java

> 编程语言
开源

一个简单的 Java 连接器,用于连接 Binance Futures API

187 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个简单的 Java 连接器,用于连接 Binance Futures API

Binance Futures Public API connector Java - DEPRECATED

This repository is deprecated. Please use the new modular connector repository: binance-connector-java

This is a lightweight library that works as a connector to the Binance Futures API

  • Supported APIs:
    • /fapi/*
    • /dapi/*
    • /futures/*
    • USD-M Futures Websocket Market Stream
    • COIN-M Futures Websocket Market Stream
    • USD-M Futures User Data Stream
    • COIN-M Futures User Data Stream
  • Test cases and examples

Installation

Replace LATEST_VERSION with the latest version number and paste the snippet below in pom.xml


    io.github.binance
    binance-futures-connector-java
    LATEST_VERSION

Run mvn install where pom.xml is located to install the dependency.

Run Example

The examples are located under src/test/java/examples. Before running the examples, set up your API_KEY and SECRET_KEY in PrivateConfig.java. This configuration file is only used for examples, you should reconfigure the API_KEY and SECRET_KEY when using the library.

RESTful APIs

The endpoints are categorized according to the following API documentations:

  • Binance USDⓈ-M Futures
  • Binance COIN-M Futures

Each object corresponds to its category which will be used to call its respective endpoints.

Category Object
Account/Trades account
Market Data market
User Data userData
Portfolio Margin portfolioMargin

Market Endpoint: Exchange Information

java
// UM-Futures
UMFuturesClientImpl client = new UMFuturesClientImpl();
String result = client.market().exchangeInfo();

// CM-Futures
CMFuturesClientImpl client = new CMFuturesClientImpl();
String result = client.market().exchangeInfo();

Trade Endpoint: Testing a new order

java
LinkedHashMap parameters = new LinkedHashMap();

UMFuturesClientImpl client = new UMFuturesClientImpl(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY);

parameters.put("symbol","BTCUSDT");
parameters.put("side", "SELL");
parameters.put("type", "LIMIT");
parameters.put("timeInForce", "GTC");
parameters.put("quantity", 0.01);
parameters.put("price", 9500);

String result = client.trade().testNewOrder(parameters);

Testnet

/fapi/* and /dapi/* endpoints can be tested in Futures Testnet. You can use it by changing the base URL:

java
LinkedHashMap parameters = new LinkedHashMap<>();

UMFuturesClientImpl client = new UMFuturesClientImpl(PrivateConfig.TESTNET_API_KEY, PrivateConfig.TESTNET_SECRET_KEY);
String result = client.market().time();

Base URL

It's recommended to pass in the baseUrl parameter. If not provided, the default baseUrl for USD-M Futures is https://fapi.binance.com

If not provided, the default baseUrl for COIN-M Futures is https://dapi.binance.com

Optional parameters

All parameters are read from a LinkedHashMap object where String is the name of the parameter and Object is the value of the parameter. The parameters should follow their exact naming as in the API documentation.

java
LinkedHashMap parameters = new LinkedHashMap();

parameters.put("symbol","BTCUSDT");
parameters.put("side", "SELL");
parameters.put("type", "LIMIT");
parameters.put("timeInForce", "GTC");
parameters.put("quantity", 0.01);
parameters.put("price", 9500);

Response MetaData

The Binance API server provides weight usages in the headers of each response. This value can be return by calling setShowLimitUsage and setting it to true.

java
UMFuturesClientImpl client = new UMFuturesClientImpl();
client.setShowLimitUsage(true);
String result = client.market().time();
logger.info(result);

output:

INFO: {"data":"{"serverTime":1633434339494}","x-mbx-used-weight":"1","x-mbx-used-weight-1m":"1"}

Proxy

HTTP Proxy is supported.

To set it up, call setProxy() with ProxyAuth and before submitting requests to binance:

java
CMFuturesClientImpl client = new CMFuturesClientImpl();
Proxy proxyConn = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080));
ProxyAuth proxy = new ProxyAuth(proxyConn, null);

client.setProxy(proxy);
logger.info(client.market().time());

For authenticated Proxy, define ProxyAuth with Authenticator from okhttp3:

…

To undo Proxy, use unsetProxy() before submitting requests to binance:

java
client.unsetProxy();
logger.info(client.market().time());

Complete examples are available to the following folders:

  • test/java/examples/cm_futures/proxy
  • test/java/examples/um_futures/proxy

Logging

ch.qos.logback is used for logging in this connector. The configuration xml file can be found under src/main/resources.

Error

There are 3 types of error which may be thrown by this library.

  • BinanceConnectorException
    • This is thrown when there is a validation error for parameters.For instance, mandatory parameter not sent. This error will be thrown before the request is sent to the server.
  • BinanceClientException
    • This is thrown when server returns 4XX, it's an issue from client side.
    • The error consists of these 3 objects which will help in debugging the error:
      • httpStatusCode - HTTP status code
      • errorCode - API Server's error code, e.g. -1102
      • errMsg - API Server's error message, e.g. Unknown order sent.
  • BinanceServerException
    • This is thrown when server returns 5XX, it's an issue from server side.
java
try {
      String result = client.trade().newOrder(parameters);
      logger.info(result);
    } catch (BinanceConnectorException e) {
      logger.error("fullErrMessage: {}", e.getMessage(), e);
    } catch (BinanceClientException e) {
      logger.error("fullErrMessage: {} \nerrMessage: {} \nerrCode: {} \nHTTPStatusCode: {}",
      e.getMessage(), e.getErrMsg(), e.getErrorCode(), e.getHttpStatusCode(), e);
    }

Websocket

…

More websocket examples are available in the test/examples folder

Test

mvn clean test

Contributing

Contributions are welcome.

If you've found a bug within this project, please open an issue to discuss what you would like to change.

If it's an issue with the API, please open a topic at Binance Developer Community

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javabinance-apiconnectorcryptofutures-market

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言