Binance Java Connectors
Collection of auto-generated java connectors for Binance APIs.
Prerequisites
Before using the connectors, ensure you have:
- Java (version >= 11)
Available Connectors
- binance-algo - Algo Trading connector
- binance-alpha - Alpha connector
- binance-c2c - C2C connector
- binance-convert - Convert connector
- binance-copy-trading - Copy Trading connector
- binance-crypto-loan - Crypto Loan connector
- binance-derivatives-trading-coin-futures - Derivatives Trading (COIN-M Futures) connector
- binance-derivatives-trading-options - Derivatives Trading (Options) connector
- binance-derivatives-trading-portfolio-margin - Derivatives Trading (Portfolio Margin) connector
- binance-derivatives-trading-portfolio-margin-pro - Derivatives Trading (Portfolio Margin Pro) connector
- binance-derivatives-trading-usds-futures - Derivatives Trading (USDS-M Futures) connector
- binance-dual-investment - Dual Investment connector
- binance-fiat - Fiat connector
- binance-gift-card - Gift Card connector
- binance-margin-trading - Margin Trading connector
- binance-mining - Mining connector
- binance-nft - NFT connector
- binance-pay - Pay connector
- binance-rebate - Rebate connector
- binance-simple-earn - Simple Earn connector
- binance-spot - Spot Trading connector
- binance-staking - Staking connector
- binance-sub-account - Sub Account connector
- binance-vip-loan - VIP Loan connector
- binance-wallet - Wallet connector
Documentation
For detailed information, refer to the Binance API Documentation.
Installation
Each connector is published as a separate maven dependency. For example:
<dependency> <groupId>io.github.binance</groupId> <artifactId>binance-spot</artifactId> <version>10.0.0</version> </dependency>
Contributing
Since this repository contains auto-generated code using OpenAPI Generator, we encourage you to:
- Open a GitHub issue to discuss your ideas or report bugs
- Allow maintainers to implement necessary changes through the code generation process
Types of Signature Generator
When creating REST clients (such as SpotRestApi), you use one of the following types of Signature Generator to create signatures (for SIGNED endpoints) based on your security preference:
HMAC- Use of API Key and Secret Key.
SignatureConfiguration signatureConfiguration = new SignatureConfiguration(); signatureConfiguration.setApiKey("apiKey"); signatureConfiguration.setSecretKey("secretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setSignatureConfiguration(signatureConfiguration); SpotRestApi spotRestApi = new SpotRestApi(clientConfiguration);
RSAorED25519- use of API Key and RSA/Ed25519 algorithm keys.
SignatureConfiguration signatureConfiguration = new SignatureConfiguration(); signatureConfiguration.setApiKey("apiKey"); signatureConfiguration.setPrivateKey("path/to/private.key"); // if the private key is protected by a password signatureConfiguration.setPrivateKeyPass("privateKeyPass"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setSignatureConfiguration(signatureConfiguration); SpotRestApi spotRestApi = new SpotRestApi(clientConfiguration);
When creating WebSocket API clients (such as SpotWebSocketApi), you can follow:
HMAC
SignatureConfiguration signatureConfiguration = new SignatureConfiguration(); signatureConfiguration.setApiKey("apiKey"); signatureConfiguration.setSecretKey("secretKey"); WebSocketClientConfiguration clientConfiguration = new WebSocketClientConfiguration(); clientConfiguration.setSignatureConfiguration(signatureConfiguration); SpotWebSocketApi spotRestApi = new SpotWebSocketApi(clientConfiguration);
Ed25519orRSA
SignatureConfiguration signatureConfiguration = new SignatureConfiguration(); signatureConfiguration.setApiKey("apiKey"); signatureConfiguration.setPrivateKey("path/to/private.key"); // if the private key is protected by a password signatureConfiguration.setPrivateKeyPass("privateKeyPass"); WebSocketClientConfiguration clientConfiguration = new WebSocketClientConfiguration(); clientConfiguration.setSignatureConfiguration(signatureConfiguration); SpotWebSocketApi spotRestApi = new SpotWebSocketApi(clientConfiguration);
How to use WebSocket connection pool
Websocket API
// Basic client config WebSocketClientConfiguration clientConfiguration = SpotWebSocketApiUtil.getClientConfiguration(); // set usePool flag to true clientConfiguration.setUsePool(true); // Use the api SpotWebSocketApi spotWebSocketApi = new SpotWebSocketApi(connectionWrapper);
Websocket Streams
// Basic client config WebSocketClientConfiguration clientConfiguration = SpotWebSocketStreamsUtil.getClientConfiguration(); // set usePool flag to true clientConfiguration.setUsePool(true); // Use the api SpotWebSocketStreams api = new SpotWebSocketStreams(clientConfiguration);
How to use a proxy
Rest Api
// Basic client config ClientConfiguration clientConfiguration = SpotRestApiUtil.getClientConfiguration(); // Create the HTTP proxy Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", 123)); // Add the proxy to the configuration clientConfiguration.setProxy(proxy); // Create the Proxy Authenticator Authenticator proxyAuthenticator = new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic("username", "password"); return response.request().newBuilder() .header("Proxy-Authorization", credential) .build(); } }; // Add the proxy authenticator to the configuration clientConfiguration.setProxyAuthenticator(proxyAuthenticator); // Use with API SpotRestApi spotRestApi = new SpotRestApi(clientConfiguration);
Websocket API
// Basic client config WebSocketClientConfiguration clientConfiguration = SpotWebSocketApiUtil.getClientConfiguration(); // Create the HTTP proxy HttpProxy proxy = new HttpProxy("host", 123); // Add the proxy to the configuration clientConfiguration.setWebSocketProxy(proxy); // Create the Proxy Authentication BasicAuthentication basicAuthentication = new BasicAuthentication( URI.create("http://host:123"), Authentication.ANY_REALM, "username", "password" ); // Add the Proxy Authentication to the configuration clientConfiguration.setWebSocketProxyAuthentication(basicAuthentication); // Use with API SpotWebSocketApi spotWebSocketApi = new SpotWebSocketApi(clientConfiguration);
Websocket Streams
// Basic client config WebSocketClientConfiguration clientConfiguration = SpotWebSocketStreamsUtil.getClientConfiguration(); // Create the HTTP proxy HttpProxy proxy = new HttpProxy("host", 123); // Add the proxy to the configuration clientConfiguration.setWebSocketProxy(proxy); // Create the Proxy Authentication BasicAuthentication basicAuthentication = new BasicAuthentication( URI.create("http://host:123"), Authentication.ANY_REALM, "username", "password" ); // Add the Proxy Authentication to the configuration clientConfiguration.setWebSocketProxyAuthentication(basicAuthentication); // Use with API SpotWebSocketStreams spotWebSocketApi = new SpotWebSocketStreams(clientConfiguration);
Examples
Algo: Rest API
Alpha: Rest API
C2c: Rest API
Convert: Rest API
Copy Trading: Rest API
Crypto Loan: Rest API
Derivatives Trading Coin Futures: Rest API - WebSocket API - WebSocket Streams
Derivatives Trading Options: Rest API - WebSocket Streams
Derivatives Trading Portfolio Margin: Rest API
Derivatives Trading Portfolio Margin Pro: Rest API
Derivatives Trading Usds Futures: Rest API - WebSocket API - WebSocket Streams
Dual Investment: Rest API
Fiat: Rest API
Gift Card: Rest API
Margin Trading: Rest API
Mining: Rest API
Nft: Rest API
Pay: Rest API
Rebate: Rest API
Simple Earn: Rest API
Spot: Rest API - WebSocket API - WebSocket Streams
Staking: Rest API
Sub Account: Rest API
Vip Loan: Rest API
Wallet: Rest API
License
This project is licensed under the MIT License - see the LICENSE file for details.