Skip to content

Latest commit

History

138 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Binance Java Connectors

Build StatusOpen IssuesCode Style: SpotlessJava VersionKnown VulnerabilitiesLicense: MIT

Collection of auto-generated java connectors for Binance APIs.

Prerequisites

Before using the connectors, ensure you have:

  • Java (version >= 11)

Available Connectors

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>11.0.1</version>
</dependency>

Contributing

Since this repository contains auto-generated code using OpenAPI Generator, we encourage you to:

  1. Open a GitHub issue to discuss your ideas or report bugs
  2. 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.
SignatureConfigurationsignatureConfiguration = newSignatureConfiguration();
signatureConfiguration.setApiKey("apiKey");
signatureConfiguration.setSecretKey("secretKey");
ClientConfigurationclientConfiguration = newClientConfiguration();
clientConfiguration.setSignatureConfiguration(signatureConfiguration);
SpotRestApispotRestApi = newSpotRestApi(clientConfiguration);
  • RSA or ED25519 - use of API Key and RSA/Ed25519 algorithm keys.
SignatureConfigurationsignatureConfiguration = newSignatureConfiguration();
signatureConfiguration.setApiKey("apiKey");
signatureConfiguration.setPrivateKey("path/to/private.key");
// if the private key is protected by a passwordsignatureConfiguration.setPrivateKeyPass("privateKeyPass");
ClientConfigurationclientConfiguration = newClientConfiguration();
clientConfiguration.setSignatureConfiguration(signatureConfiguration);
SpotRestApispotRestApi = newSpotRestApi(clientConfiguration);

When creating WebSocket API clients (such as SpotWebSocketApi), you can follow:

  • HMAC
SignatureConfigurationsignatureConfiguration = newSignatureConfiguration();
signatureConfiguration.setApiKey("apiKey");
signatureConfiguration.setSecretKey("secretKey");
WebSocketClientConfigurationclientConfiguration = newWebSocketClientConfiguration();
clientConfiguration.setSignatureConfiguration(signatureConfiguration);
SpotWebSocketApispotRestApi = newSpotWebSocketApi(clientConfiguration);
  • Ed25519 or RSA
SignatureConfigurationsignatureConfiguration = newSignatureConfiguration();
signatureConfiguration.setApiKey("apiKey");
signatureConfiguration.setPrivateKey("path/to/private.key");
// if the private key is protected by a passwordsignatureConfiguration.setPrivateKeyPass("privateKeyPass");
WebSocketClientConfigurationclientConfiguration = newWebSocketClientConfiguration();
clientConfiguration.setSignatureConfiguration(signatureConfiguration);
SpotWebSocketApispotRestApi = newSpotWebSocketApi(clientConfiguration);

How to use WebSocket connection pool

Websocket API

// Basic client configWebSocketClientConfigurationclientConfiguration = SpotWebSocketApiUtil.getClientConfiguration();
// set usePool flag to trueclientConfiguration.setUsePool(true);
// Use the apiSpotWebSocketApispotWebSocketApi = newSpotWebSocketApi(connectionWrapper);

Websocket Streams

// Basic client configWebSocketClientConfigurationclientConfiguration = SpotWebSocketStreamsUtil.getClientConfiguration();
// set usePool flag to trueclientConfiguration.setUsePool(true);
// Use the apiSpotWebSocketStreamsapi = newSpotWebSocketStreams(clientConfiguration);

How to use a proxy

Rest Api

// Basic client configClientConfigurationclientConfiguration = SpotRestApiUtil.getClientConfiguration();
// Create the HTTP proxyProxyproxy = newProxy(Proxy.Type.HTTP, newInetSocketAddress("host", 123));
// Add the proxy to the configurationclientConfiguration.setProxy(proxy);
// Create the Proxy AuthenticatorAuthenticatorproxyAuthenticator = newAuthenticator() {
@OverridepublicRequestauthenticate(Routeroute, Responseresponse) throwsIOException {
Stringcredential = Credentials.basic("username", "password");
returnresponse.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
};
// Add the proxy authenticator to the configurationclientConfiguration.setProxyAuthenticator(proxyAuthenticator);
// Use with APISpotRestApispotRestApi = newSpotRestApi(clientConfiguration);

Websocket API

// Basic client configWebSocketClientConfigurationclientConfiguration = SpotWebSocketApiUtil.getClientConfiguration();
// Create the HTTP proxyHttpProxyproxy = newHttpProxy("host", 123);
// Add the proxy to the configurationclientConfiguration.setWebSocketProxy(proxy);
// Create the Proxy AuthenticationBasicAuthenticationbasicAuthentication = newBasicAuthentication(
URI.create("http://host:123"),
Authentication.ANY_REALM,
"username",
"password"
);
// Add the Proxy Authentication to the configurationclientConfiguration.setWebSocketProxyAuthentication(basicAuthentication);
// Use with APISpotWebSocketApispotWebSocketApi = newSpotWebSocketApi(clientConfiguration);

Websocket Streams

// Basic client configWebSocketClientConfigurationclientConfiguration = SpotWebSocketStreamsUtil.getClientConfiguration();
// Create the HTTP proxyHttpProxyproxy = newHttpProxy("host", 123);
// Add the proxy to the configurationclientConfiguration.setWebSocketProxy(proxy);
// Create the Proxy AuthenticationBasicAuthenticationbasicAuthentication = newBasicAuthentication(
URI.create("http://host:123"),
Authentication.ANY_REALM,
"username",
"password"
);
// Add the Proxy Authentication to the configurationclientConfiguration.setWebSocketProxyAuthentication(basicAuthentication);
// Use with APISpotWebSocketStreamsspotWebSocketApi = newSpotWebSocketStreams(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

W3W Prediction: Rest API

Wallet: Rest API

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Simple Java connector to Binance Spot API

Topics

Resources

Stars

577 stars

Watchers

25 watching

Forks

Packages

Used by

Contributors

Languages