binance-connector-java

Binance Java Sub Account Connector

Open Issues Code Style: Spotless Maven Central Version Java Version Known Vulnerabilities License: MIT

This is a client library for the Binance Sub Account API, enabling developers to interact programmatically with Binance’s Sub Account trading platform. The library provides tools to trade through multiple accounts through the REST API:

Table of Contents

Supported Features

Installation

To use this library, ensure your environment is running Java version 11 or newer.

Then add dependency to pom.xml:

<dependency>
  <groupId>io.github.binance</groupId>
  <artifactId>binance-sub-account</artifactId>
  <version>2.0.0</version>
</dependency>

Documentation

For detailed information, refer to the Binance API Documentation.

REST APIs

All REST API endpoints are available through the rest module. Note that some endpoints require authentication using your Binance API credentials.

import com.binance.connector.client.sub_account.rest.SubAccountRestApiUtil;
import com.binance.connector.client.sub_account.rest.api.SubAccountRestApi;
import com.binance.connector.client.common.ApiException;
import com.binance.connector.client.common.ApiResponse;
import com.binance.connector.client.common.configuration.ClientConfiguration;
import com.binance.connector.client.common.configuration.SignatureConfiguration;

public static void main(String[] args) {
    ClientConfiguration clientConfiguration = SubAccountRestApiUtil.getClientConfiguration();
    SignatureConfiguration signatureConfiguration = new SignatureConfiguration();
    signatureConfiguration.setApiKey("apiKey");
    signatureConfiguration.setPrivateKey("path/to/private.key");
    clientConfiguration.setSignatureConfiguration(signatureConfiguration);
    SubAccountRestApi api = new SubAccountRestApi(clientConfiguration);
}

More examples can be found in the examples/rest folder.

Configuration Options

The REST API supports the following advanced configuration options:

Timeout

You can configure a timeout for requests in milliseconds. If the request exceeds the specified timeout, it will be aborted. See the Timeout example for detailed usage.

Proxy

The REST API supports HTTP/HTTPS proxy configurations. See the Proxy example for detailed usage.

Keep-Alive

Enable HTTP keep-alive for persistent connections. See the Keep-Alive example for detailed usage.

Compression

Enable or disable response compression. See the Compression example for detailed usage.

Retries

Configure the number of retry attempts and delay in milliseconds between retries for failed requests. See the Retries example for detailed usage.

Key Pair Based Authentication

The REST API supports key pair-based authentication for secure communication. You can use RSA or ED25519 keys for signing requests. See the Key Pair Based Authentication example for detailed usage.

Certificate Pinning

To enhance security, you can use certificate pinning with the httpsAgent option in the configuration. This ensures the client only communicates with servers using specific certificates. See the Certificate Pinning example for detailed usage.

Error Handling

The REST API provides detailed error types to help you handle issues effectively:

See the Error Handling example for detailed usage.

If basePath is not provided, it defaults to https://api.binance.com.

Testing

To run the tests:

mvn -f clients/pom.xml -pl sub-account test

The tests cover:

Migration Guide

If you are upgrading to the new modularized structure, refer to the Migration Guide for detailed steps.

Contributing

Contributions are welcome!

Since this repository contains auto-generated code, we encourage you to start by opening a GitHub issue to discuss your ideas or suggest improvements. This helps ensure that changes align with the project’s goals and auto-generation processes.

To contribute:

  1. Open a GitHub issue describing your suggestion or the bug you’ve identified.
  2. If it’s determined that changes are necessary, the maintainers will merge the changes into the main branch.

Please ensure that all tests pass if you’re making a direct contribution. Submit a pull request only after discussing and confirming the change.

Thank you for your contributions!

License

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