Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<module>simple-earn</module>
<module>spot</module>
<module>staking</module>
<module>stocks</module>
<module>sub-account</module>
<module>vip-loan</module>
<module>w3w-prediction</module>
Expand Down
5 changes: 5 additions & 0 deletions clients/stocks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 1.0.0 - 2026-08-17

- Initial release
162 changes: 162 additions & 0 deletions clients/stocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Binance Java Stocks Connector

[![Open Issues](https://img.shields.io/github/issues/binance/binance-connector-java)](https://github.com/binance/binance-connector-java/issues)
[![Code Style: Spotless](https://img.shields.io/badge/code%20style-spotless-ff69b4)](https://github.com/diffplug/spotless)
[![Maven Central Version](https://img.shields.io/maven-central/v/io.github.binance/binance-stocks)](https://central.sonatype.com/artifact/io.github.binance/binance-stocks)
![Java Version](https://img.shields.io/badge/Java-%3E=11-brightgreen)
[![Known Vulnerabilities](https://snyk.io/test/github/binance/binance-connector-java/badge.svg)](https://snyk.io/test/github/binance/binance-connector-java)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This is a client library for the Binance Stocks API, enabling developers to interact programmatically with Binance Stocks. The library provides tools to access trade U.S.-listed stocks and ETFs programmatically through a secure and developer-friendly REST API.

- [REST API](./src/main/java/com/binance/connector/client/stocks/rest/api)

## Table of Contents

- [Supported Features](#supported-features)
- [Installation](#installation)
- [Documentation](#documentation)
- [REST APIs](#rest-apis)
- [Testing](#testing)
- [Migration Guide](#migration-guide)
- [Contributing](#contributing)
- [License](#license)

## Supported Features

- REST API Endpoints:
- `/sapi/v1/equity/*`
- Inclusion of test cases and examples for quick onboarding.

## Installation

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

Then add dependency to pom.xml:

```xml
<dependency>
<groupId>io.github.binance</groupId>
<artifactId>binance-stocks</artifactId>
<version>1.0.0</version>
</dependency>
```

## Documentation

For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/stocks).

### REST APIs

All REST API endpoints are available through the [`rest`](./src/main/java/com/binance/connector/client/stocks/rest) module. Note that some endpoints require authentication using your Binance API credentials.

```java
import com.binance.connector.client.stocks.rest.StocksRestApiUtil;
import com.binance.connector.client.stocks.rest.api.StocksRestApi;
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 = StocksRestApiUtil.getClientConfiguration();
SignatureConfiguration signatureConfiguration = new SignatureConfiguration();
signatureConfiguration.setApiKey("apiKey");
signatureConfiguration.setPrivateKey("path/to/private.key");
clientConfiguration.setSignatureConfiguration(signatureConfiguration);
StocksRestApi api = new StocksRestApi(clientConfiguration);
}
```

More examples can be found in the [`examples/rest`](./../../examples/stocks/src/main/java/com/binance/connector/client/stocks/rest) folder.

#### Configuration Options

The REST API supports the following advanced configuration options:

- `proxy`: Proxy configuration for http client.
- `certificatePinner`: Certificate Pinner configuration for http client.
- `connectTimeout`: Timeout for requests in milliseconds (default: 1000 ms).
- `readTimeout`: Timeout for requests in milliseconds (default: 5000 ms).
- `compression`: Enable response compression (default: true).
- `retries`: Number of retry attempts for failed requests (default: 3).
- `backoff`: Delay in milliseconds between retries (default: 200 ms).
- `timeUnit`: TimeUnit to be returned by API (default MILLISECOND).
- `apiKey`: Binance API Key
- `secretKey`: Binance Secret Key, if using HMAC algorithm
- `privateKey`: RSA or ED25519 private key for authentication.
- `privateKeyPass`: Passphrase for the private key, if encrypted.

##### 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](./docs/rest-api/timeout.md) for detailed usage.

##### Proxy

The REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest-api/proxy.md) for detailed usage.

##### Keep-Alive

Enable HTTP keep-alive for persistent connections.

##### Compression

Enable or disable response compression. See the [Compression example](./docs/rest-api/compression.md) for detailed usage.

##### Retries

Configure the number of retry attempts and delay in milliseconds between retries for failed requests. See the [Retries example](./docs/rest-api/retries.md) 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](./docs/rest-api/key-pair-authentication.md) 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](./docs/rest-api/certificate-pinning.md) for detailed usage.

#### Error Handling

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

- `ConnectorClientError`: General client error.

See the [Error Handling example](./docs/rest-api/error-handling.md) for detailed usage.

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

## Testing

To run the tests:

```bash
mvn -f clients/pom.xml -pl stocks test
```

The tests cover:

- REST API endpoints
- Signature generation

## Migration Guide

If you are upgrading to the new modularized structure, refer to the [Migration Guide](./docs/rest-api/migration-guide.md) 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](../../LICENSE) file for details.
71 changes: 71 additions & 0 deletions clients/stocks/docs/AccountApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# AccountApi

All URIs are relative to *https://api.binance.com*

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**signUsEquityDisclaimer**](AccountApi.md#signUsEquityDisclaimer) | **POST** /sapi/v1/equity/account/disclaimer | Sign US Equity Disclaimer (TRADE) |


<a id="signUsEquityDisclaimer"></a>
# **signUsEquityDisclaimer**
> SignUsEquityDisclaimerResponse signUsEquityDisclaimer(recvWindow)

Sign US Equity Disclaimer (TRADE)

Records the user&#39;s acknowledgement and acceptance of the US equity disclaimer. This must be completed before the account can access certain US equity trading features. The acceptance is tied to the account associated with the API key. Weight: 1 Security Type: TRADE

### Example
```java
// Import classes:
import com.binance.connector.client.stocks.ApiClient;
import com.binance.connector.client.stocks.ApiException;
import com.binance.connector.client.stocks.Configuration;
import com.binance.connector.client.stocks.models.*;
import com.binance.connector.client.stocks.rest.api.AccountApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.binance.com");

AccountApi apiInstance = new AccountApi(defaultClient);
Long recvWindow = 5000L; // Long | The value cannot be greater than `60000`.
try {
SignUsEquityDisclaimerResponse result = apiInstance.signUsEquityDisclaimer(recvWindow);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AccountApi#signUsEquityDisclaimer");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```

### Parameters

| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **recvWindow** | **Long**| The value cannot be greater than &#x60;60000&#x60;. | [optional] |

### Return type

[**SignUsEquityDisclaimerResponse**](SignUsEquityDisclaimerResponse.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/x-www-form-urlencoded
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Sign US Equity Disclaimer | - |

16 changes: 16 additions & 0 deletions clients/stocks/docs/CalendarStreamResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


# CalendarStreamResponse


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**ELowerCase** | **String** | Event type, always &#x60;\&quot;calendar\&quot;&#x60;. | [optional] |
|**from** | **String** | Previous market phase. | [optional] |
|**to** | **String** | New market phase. | [optional] |
|**ts** | **Long** | Event timestamp (epoch milliseconds UTC) when the transition was detected. | [optional] |



13 changes: 13 additions & 0 deletions clients/stocks/docs/CancelAllEquityOrdersResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# CancelAllEquityOrdersResponse


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**success** | **Boolean** | &#x60;true&#x60; when the cancel-all request was accepted by upstream. Per-order outcomes live in &#x60;/order/history&#x60;. | [optional] |



14 changes: 14 additions & 0 deletions clients/stocks/docs/CancelEquityOrderResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# CancelEquityOrderResponse


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**orderId** | **String** | Echoes the requested order id. | [optional] |
|**status** | **String** | Acknowledgement code: &#x60;S&#x60; &#x3D; cancel accepted by upstream, &#x60;F&#x60; &#x3D; cancel failed. Not an order lifecycle status — use &#x60;/order/detail&#x60; for lifecycle poll. | [optional] |



13 changes: 13 additions & 0 deletions clients/stocks/docs/ConvertType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# ConvertType

## Enum


* `MINT` (value: `"MINT"`)

* `REDEEM` (value: `"REDEEM"`)



13 changes: 13 additions & 0 deletions clients/stocks/docs/CreateRenewListenKeyResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# CreateRenewListenKeyResponse


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**listenKey** | **String** | Session identifier for the stock user data stream. | [optional] |



13 changes: 13 additions & 0 deletions clients/stocks/docs/CurrentOpenOrdersResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# CurrentOpenOrdersResponse

Array of open order objects. Fields are identical to the order rows in Equity Order History.

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|



28 changes: 28 additions & 0 deletions clients/stocks/docs/CurrentOpenOrdersResponseInner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


# CurrentOpenOrdersResponseInner


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**orderId** | **String** | Equity order id. | [optional] |
|**symbol** | **String** | US-equity ticker. | [optional] |
|**quote** | **String** | Quote asset (e.g. &#x60;USDC&#x60;). | [optional] |
|**side** | **String** | &#x60;BUY&#x60; / &#x60;SELL&#x60;. | [optional] |
|**orderType** | **String** | &#x60;MARKET&#x60; / &#x60;LIMIT&#x60;. | [optional] |
|**limitPrice** | **String** | Limit price (USD). Non-null for &#x60;LIMIT&#x60; orders, &#x60;null&#x60; for &#x60;MARKET&#x60;. | [optional] |
|**avgFilledPrice** | **String** | Average fill price (USD). &#x60;null&#x60; until the first fill. | [optional] |
|**qty** | **String** | Requested quantity. &#x60;null&#x60; for &#x60;BUY MARKET&#x60; (use &#x60;notional&#x60; instead). | [optional] |
|**notional** | **String** | Requested notional. Non-null for &#x60;BUY MARKET&#x60;; &#x60;null&#x60; otherwise. | [optional] |
|**filledQty** | **String** | Cumulative filled quantity. | [optional] |
|**filledTotal** | **String** | Cumulative filled notional. Populated only for &#x60;BUY MARKET&#x60;. | [optional] |
|**fee** | **String** | Total commission fee (USD). | [optional] |
|**session** | **String** | Trading session the order was placed under: &#x60;RTH&#x60; / &#x60;EXTENDED&#x60; / &#x60;24H&#x60;. &#x60;null&#x60; for &#x60;MARKET&#x60; orders. | [optional] |
|**status** | **String** | Order lifecycle status — one of &#x60;NEW&#x60; / &#x60;ACCEPTED&#x60; / &#x60;PARTIALLY_FILLED&#x60; / &#x60;FILLED&#x60; / &#x60;CANCELED&#x60; / &#x60;EXPIRED&#x60; / &#x60;REJECTED&#x60;. | [optional] |
|**createdAt** | **Long** | Order creation time (ms epoch). | [optional] |
|**updatedAt** | **Long** | Last update time (ms epoch). | [optional] |



31 changes: 31 additions & 0 deletions clients/stocks/docs/EquityOrderDetailResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


# EquityOrderDetailResponse

Top-level fields mirror an order row from `/order/history` (orderId, symbol, quote, side, orderType, limitPrice, avgFilledPrice, qty, notional, filledQty, filledTotal, fee, session, status, createdAt, updatedAt), plus a `trades` array. `clientOrderId` is present only in Order Detail, not in Order History.

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**orderId** | **String** | Equity order id. | [optional] |
|**clientOrderId** | **String** | Client-supplied order id. Present only in Order Detail, not in Order History. | [optional] |
|**symbol** | **String** | US-equity ticker. | [optional] |
|**quote** | **String** | Quote asset. | [optional] |
|**side** | **String** | &#x60;BUY&#x60; / &#x60;SELL&#x60;. | [optional] |
|**orderType** | **String** | &#x60;MARKET&#x60; / &#x60;LIMIT&#x60;. | [optional] |
|**limitPrice** | **String** | Limit price (USD). Non-null for &#x60;LIMIT&#x60;, &#x60;null&#x60; for &#x60;MARKET&#x60;. | [optional] |
|**avgFilledPrice** | **String** | Average fill price (USD). Only present when the order has at least one fill. | [optional] |
|**qty** | **String** | Requested quantity. | [optional] |
|**notional** | **String** | Requested notional. | [optional] |
|**filledQty** | **String** | Cumulative filled quantity. | [optional] |
|**filledTotal** | **String** | Cumulative filled notional. | [optional] |
|**fee** | **String** | Total commission fee (USD). | [optional] |
|**session** | **String** | Trading session. | [optional] |
|**status** | **String** | Order lifecycle status. | [optional] |
|**createdAt** | **Long** | Order creation time (ms epoch). | [optional] |
|**updatedAt** | **Long** | Last update time (ms epoch). | [optional] |
|**trades** | [**List&lt;EquityOrderDetailResponseTradesInner&gt;**](EquityOrderDetailResponseTradesInner.md) | Trade executions for this order, most recent first. Empty array when no fills. | [optional] |



Loading
Loading