binance-sdk-derivatives-trading-coin-futures


Namebinance-sdk-derivatives-trading-coin-futures JSON
Version 2.0.0 PyPI version JSON
download
home_pageNone
SummaryOfficial Binance Derivatives Trading Coin Futures SDK - A lightweight library that provides a convenient interface to Binance's DerivativesTradingCoinFutures REST API, WebSocket API and WebSocket Streams.
upload_time2025-08-22 14:42:38
maintainerNone
docs_urlNone
authorBinance
requires_python<3.14,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Binance Python Derivatives Trading (COIN-M Futures) SDK

[![Build Status](https://img.shields.io/github/actions/workflow/status/binance/binance-connector-python/ci.yaml)](https://github.com/binance/binance-connector-python/actions)
[![Open Issues](https://img.shields.io/github/issues/binance/binance-connector-python)](https://github.com/binance/binance-connector-python/issues)
[![Code Style: Black](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
[![PyPI version](https://img.shields.io/pypi/v/binance-sdk-derivatives-trading-coin-futures)](https://pypi.python.org/pypi/binance-sdk-derivatives-trading-coin-futures)
[![PyPI Downloads](https://img.shields.io/pypi/dm/binance-sdk-derivatives-trading-coin-futures.svg)](https://pypi.org/project/binance-sdk-derivatives-trading-coin-futures/)
[![Python version](https://img.shields.io/pypi/pyversions/binance-sdk-derivatives-trading-coin-futures)](https://www.python.org/downloads/)
[![Known Vulnerabilities](https://img.shields.io/badge/security-scanned-brightgreen)](https://github.com/binance/binance-connector-python/security)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This is a client library for the Binance Derivatives Trading COIN-M Futures API SDK, enabling developers to interact programmatically with Binance's API to suit their derivative trading needs, through three distinct endpoints:
- [REST API](./src/binance_sdk_derivatives_trading_coin_futures/rest_api/rest_api.py)
- [WebSocket API](./src/binance_sdk_derivatives_trading_coin_futures/websocket_api/websocket_api.py)
- [User Data Stream API](./src/binance_sdk_derivatives_trading_coin_futures/websocket_streams/websocket_streams.py)

## Table of Contents

- [Supported Features](#supported-features)
- [Installation](#installation)
- [Documentation](#documentation)
- [REST APIs](#rest-apis)
- [Websocket APIs](#websocket-apis)
- [Websocket Streams](#websocket-streams)
- [Testing](#testing)
- [Migration Guide](#migration-guide)
- [Contributing](#contributing)
- [Licence](#licence)

## Supported Features

- REST API Endpoints:
  - `/dapi/*`
- WebSocket Endpoints: Real-time data streaming and request-response communication.
- Inclusion of test cases and examples for quick onboarding.

## Installation

To use this library, ensure your environment is running Python version **3.9** or later.

```bash
pip install binance-sdk-derivatives-trading-coin-futures
```

## Documentation

For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/general-info).

### REST APIs

All REST API endpoints are available through the [`rest_api`](./src/binance_sdk_derivatives_trading_coin_futures/rest_api/rest_api.py) module. The REST API enables you to fetch market data, manage trades, and access account information. Note that some endpoints require authentication using your Binance API credentials.

```python
from binance_common.configuration import ConfigurationRestAPI
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures
from binance_sdk_derivatives_trading_coin_futures.rest_api.models import ExchangeInformationResponse

logging.basicConfig(level=logging.INFO)
configuration = ConfigurationRestAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL)

client = DerivativesTradingCoinFutures(config_rest_api=configuration)

try:
    response = client.rest_api.exchange_information()

    data: ExchangeInformationResponse = response.data()
    logging.info(f"exchange_information() response: {data}")
except Exception as e:
    logging.error(f"exchange_information() error: {e}")
```

More examples can be found in the [`examples/rest_api`](./examples/rest_api/) folder.

#### Configuration Options

The REST API supports the following advanced configuration options:

- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).
- `proxy`: Proxy configuration:
  - `host`: Proxy server hostname.
  - `port`: Proxy server port.
  - `protocol`: Proxy protocol (http or https).
  - `auth`: Proxy authentication credentials:
    - `username`: Proxy username.
    - `password`: Proxy password.
- `keep_alive`: Enable HTTP keep-alive (default: true).
- `compression`: Enable response compression (default: true).
- `retries`: Number of retry attempts for failed requests (default: 3).
- `backoff`: Delay in milliseconds between retries (default: 1000 ms).
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
- `private_key`: RSA or ED25519 private key for authentication.
- `private_key_passphrase`: 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. See the [Keep-Alive example](./docs/rest_api/keepAlive.md) for detailed usage.

##### 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.

##### HTTPS Agent

Customize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest_api/httpsAgent.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 `https_agent` 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:

- `ClientError`: Represents an error that occurred in the SDK client.
- `RequiredError`: Thrown when a required parameter is missing or undefined.
- `UnauthorizedError`: Indicates missing or invalid authentication credentials.
- `ForbiddenError`: Access to the requested resource is forbidden.
- `TooManyRequestsError`: Rate limit exceeded.
- `RateLimitBanError`: IP address banned for exceeding rate limits.
- `ServerError`: Internal server error, optionally includes a status code.
- `NetworkError`: Issues with network connectivity.
- `NotFoundError`: Resource not found.
- `BadRequestError`: Invalid request or one that cannot be served.

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

#### Testnet

For testing purposes, `/dapi/*` endpoints can be used in the [Futures Testnet](https://testnet.binancefuture.com/). Update the `base_path` in your configuration:

```python
from binance_common.configuration import ConfigurationRestAPI
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

configuration = ConfigurationRestAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL)
client = DerivativesTradingCoinFutures(config_rest_api=configuration)
```

If `base_path` is not provided, it defaults to `https://dapi.binance.com`.

### Websocket APIs

The WebSocket API provides request-response communication for market data and trading actions. Use the [`websocket_api`](./src/binance_sdk_derivatives_trading_coin_futures/websocket_api/websocket_api.py) module to interact with these endpoints.

```python
from binance_common.configuration import ConfigurationWebSocketAPI
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

configuration = ConfigurationWebsocketAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL)
client = DerivativesTradingCoinFutures(configuration_websocket_api=configuration)
```

More examples are available in the [`examples/websocket_api`](./examples/websocket_api/) folder.

#### Configuration Options

The WebSocket API supports the following advanced configuration options:

- `timeout`: Set the timeout for WebSocket requests (default: 5000 ms).
- `reconnect_delay`: Delay (ms) between reconnections.
- `compression`: Enable response compression.
- `proxy`: Proxy configuration:
  - `host`: Proxy server hostname.
  - `port`: Proxy server port.
  - `protocol`: Proxy protocol (http or https).
  - `auth`: Proxy authentication credentials:
    - `username`: Proxy username.
    - `password`: Proxy password.
- `mode`: Choose between `single` and `pool` connection modes.
  - `single`: A single WebSocket connection.
  - `pool`: A pool of WebSocket connections.
- `pool_size`: Define the number of WebSocket connections in pool mode.
- `private_key`: RSA or ED25519 private key for authentication.
- `private_key_passphrase`: Passphrase for the private key, if encrypted.
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
- `user_agent`: Custom user agent string for WebSocket Streams.

##### Timeout

Set the timeout for WebSocket API requests in milliseconds. See the [Timeout example](./docs/websocket_api/timeout.md) for detailed usage.

##### Reconnect Delay

Specify the delay in milliseconds between WebSocket reconnection attempts. See the [Reconnect Delay example](./docs/websocket_api/reconnect-delay.md) for detailed usage.

##### Compression

Enable or disable compression for WebSocket messages. See the [Compression example](./docs/websocket_api/compression.md) for detailed usage.

##### Proxy

The WebSocket API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/websocket_api/proxy.md) for detailed usage.


##### Connection Mode

Choose between `single` and `pool` connection modes for WebSocket connections. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket_api/connection-mode.md) for detailed usage.

##### Key Pair Based Authentication

Use RSA or ED25519 private keys for WebSocket API authentication. See the [Key Pair Authentication example](./docs/websocket_api/key-pair-authentication.md) for detailed usage.

##### WebSocket Http Agent

Customize the agent for advanced configurations. See the [WebSocket Http Agent example](./docs/websocket_api/agent.md) for detailed usage.

#### Testnet

For testing purposes, the Websocket API also supports a testnet environment. Update the `wsURL` in your configuration:

```python
from binance_common.configuration import ConfigurationWebSocketAPI
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

configuration_ws_api = ConfigurationWebSocketAPI(
    api_key="your-api-key",
    api_secret="your-api-secret",
    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL
)
client = DerivativesTradingCoinFutures(config_ws_api=configuration_ws_api)
```

If `wsURL` is not provided, it defaults to `wss://ws-api.binance.com:443/ws-api/v3`.

### Websocket Streams

WebSocket Streams provide real-time data feeds for market trades, candlesticks, and more. Use the [websocket-streams](./src/binance_sdk_derivatives_trading_coin_futures/websocket_streams/websocket_streams.py) module to subscribe to these streams.

```python
import asyncio
import logging

from binance_common.configuration import ConfigurationWebSocketStreams
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

logging.basicConfig(level=logging.INFO)

configuration_ws_streams = ConfigurationWebSocketStreams(
    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL,
)

client = DerivativesTradingCoinFutures(config_ws_streams=configuration_ws_streams)
```

More examples are available in the [`examples/websocket-streams`](./examples/websocket_streams/) folder.

#### Configuration Options

The WebSocket Streams API supports the following advanced configuration options:

- `reconnect_delay`: Delay (ms) between reconnections.
- `compression`: Enable response compression.
- `proxy`: Proxy configuration:
  - `host`: Proxy server hostname.
  - `port`: Proxy server port.
  - `protocol`: Proxy protocol (http or https).
  - `auth`: Proxy authentication credentials:
    - `username`: Proxy username.
    - `password`: Proxy password.
- `mode`: Choose between `single` and `pool` connection modes.
  - `single`: A single WebSocket connection.
  - `pool`: A pool of WebSocket connections.
- `pool_size`: Define the number of WebSocket connections in pool mode.
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
- `user_agent`: Custom user agent string for WebSocket Streams.

##### Reconnect Delay

Specify the delay in milliseconds between WebSocket reconnection attempts for streams. See the [Reconnect Delay example](./docs/websocket_streams/reconnect-delay.md) for detailed usage.

##### Compression

Enable or disable compression for WebSocket Streams messages. See the [Compression example](./docs/websocket_streams/compression.md) for detailed usage.

##### Proxy

The WebSocket Streams supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/websocket_streams/proxy.md) for detailed usage.

##### Connection Mode

Choose between `single` and `pool` connection modes for WebSocket Streams. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket_streams/connection-mode.md) for detailed usage.

##### WebSocket Http Agent

Customize the agent for advanced configurations. See the [WebSocket Http Agent example](./docs/websocket_streams/agent.md) for detailed usage.

#### Unsubscribing from Streams

You can unsubscribe from specific WebSocket streams using the `unsubscribe` method. This is useful for managing active subscriptions without closing the connection.

```python
import asyncio
import logging

from binance_common.configuration import ConfigurationWebSocketStreams
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

logging.basicConfig(level=logging.INFO)

client = DerivativesTradingCoinFutures(config_ws_streams=ConfigurationWebSocketStreams())


async def all_book_tickers_stream():
    connection = None
    try:
        connection = await client.websocket_streams.create_connection()

        stream = await connection.all_book_tickers_stream()
        stream.on("message", lambda data: print(f"{data}"))

        await asyncio.sleep(5)
        await stream.unsubscribe()
    except Exception as e:
        logging.error(f"all_book_tickers_stream() error: {e}")
    finally:
        if connection:
            await connection.close_connection(close_session=True)


if __name__ == "__main__":
    asyncio.run(all_book_tickers_stream())
```

#### Testnet

Websocket Streams also support a testnet environment for development and testing. Update the `wsURL` in your configuration:

```python
from binance_common.configuration import ConfigurationWebSocketStreams
from binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL
from binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures

config_ws_streams = ConfigurationWebSocketStreams(
    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL
)

client = DerivativesTradingCoinFutures(config_ws_streams=config_ws_streams)
```

If `wsURL` is not provided, it defaults to `wss://dstream.binance.com`.

### Automatic Connection Renewal

The WebSocket connection is automatically renewed for both WebSocket API and WebSocket Streams connections, before the 24 hours expiration of the API key. This ensures continuous connectivity.

## Testing

To run the tests, ensure you have [Poetry](https://python-poetry.org/) installed, then execute the following commands:

```bash
poetry install
poetry run pytest ./tests
```

The tests cover:
* REST API endpoints
* WebSocket API endpoints
* WebSocket Streams endpoints
* Error handling
* Edge cases

## Migration Guide

If you are upgrading to the new modularized structure, refer to the [Migration Guide](./docs/migration_guide_derivatives_trading_coin_futures_sdk.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!

## Licence

This project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "binance-sdk-derivatives-trading-coin-futures",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.14,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Binance",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/08/5e/cec6138fbad6f5f518a2fb7a7ea6149db4e31380702c5a5841a143f44cd5/binance_sdk_derivatives_trading_coin_futures-2.0.0.tar.gz",
    "platform": null,
    "description": "# Binance Python Derivatives Trading (COIN-M Futures) SDK\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/binance/binance-connector-python/ci.yaml)](https://github.com/binance/binance-connector-python/actions)\n[![Open Issues](https://img.shields.io/github/issues/binance/binance-connector-python)](https://github.com/binance/binance-connector-python/issues)\n[![Code Style: Black](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)\n[![PyPI version](https://img.shields.io/pypi/v/binance-sdk-derivatives-trading-coin-futures)](https://pypi.python.org/pypi/binance-sdk-derivatives-trading-coin-futures)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/binance-sdk-derivatives-trading-coin-futures.svg)](https://pypi.org/project/binance-sdk-derivatives-trading-coin-futures/)\n[![Python version](https://img.shields.io/pypi/pyversions/binance-sdk-derivatives-trading-coin-futures)](https://www.python.org/downloads/)\n[![Known Vulnerabilities](https://img.shields.io/badge/security-scanned-brightgreen)](https://github.com/binance/binance-connector-python/security)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis is a client library for the Binance Derivatives Trading COIN-M Futures API SDK, enabling developers to interact programmatically with Binance's API to suit their derivative trading needs, through three distinct endpoints:\n- [REST API](./src/binance_sdk_derivatives_trading_coin_futures/rest_api/rest_api.py)\n- [WebSocket API](./src/binance_sdk_derivatives_trading_coin_futures/websocket_api/websocket_api.py)\n- [User Data Stream API](./src/binance_sdk_derivatives_trading_coin_futures/websocket_streams/websocket_streams.py)\n\n## Table of Contents\n\n- [Supported Features](#supported-features)\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [REST APIs](#rest-apis)\n- [Websocket APIs](#websocket-apis)\n- [Websocket Streams](#websocket-streams)\n- [Testing](#testing)\n- [Migration Guide](#migration-guide)\n- [Contributing](#contributing)\n- [Licence](#licence)\n\n## Supported Features\n\n- REST API Endpoints:\n  - `/dapi/*`\n- WebSocket Endpoints: Real-time data streaming and request-response communication.\n- Inclusion of test cases and examples for quick onboarding.\n\n## Installation\n\nTo use this library, ensure your environment is running Python version **3.9** or later.\n\n```bash\npip install binance-sdk-derivatives-trading-coin-futures\n```\n\n## Documentation\n\nFor detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/general-info).\n\n### REST APIs\n\nAll REST API endpoints are available through the [`rest_api`](./src/binance_sdk_derivatives_trading_coin_futures/rest_api/rest_api.py) module. The REST API enables you to fetch market data, manage trades, and access account information. Note that some endpoints require authentication using your Binance API credentials.\n\n```python\nfrom binance_common.configuration import ConfigurationRestAPI\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\nfrom binance_sdk_derivatives_trading_coin_futures.rest_api.models import ExchangeInformationResponse\n\nlogging.basicConfig(level=logging.INFO)\nconfiguration = ConfigurationRestAPI(api_key=\"your-api-key\", api_secret=\"your-api-secret\", base_path=DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL)\n\nclient = DerivativesTradingCoinFutures(config_rest_api=configuration)\n\ntry:\n    response = client.rest_api.exchange_information()\n\n    data: ExchangeInformationResponse = response.data()\n    logging.info(f\"exchange_information() response: {data}\")\nexcept Exception as e:\n    logging.error(f\"exchange_information() error: {e}\")\n```\n\nMore examples can be found in the [`examples/rest_api`](./examples/rest_api/) folder.\n\n#### Configuration Options\n\nThe REST API supports the following advanced configuration options:\n\n- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).\n- `proxy`: Proxy configuration:\n  - `host`: Proxy server hostname.\n  - `port`: Proxy server port.\n  - `protocol`: Proxy protocol (http or https).\n  - `auth`: Proxy authentication credentials:\n    - `username`: Proxy username.\n    - `password`: Proxy password.\n- `keep_alive`: Enable HTTP keep-alive (default: true).\n- `compression`: Enable response compression (default: true).\n- `retries`: Number of retry attempts for failed requests (default: 3).\n- `backoff`: Delay in milliseconds between retries (default: 1000 ms).\n- `https_agent`: Custom HTTPS agent for advanced TLS configuration.\n- `private_key`: RSA or ED25519 private key for authentication.\n- `private_key_passphrase`: Passphrase for the private key, if encrypted.\n\n##### Timeout\n\nYou 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.\n\n##### Proxy\n\nThe REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest_api/proxy.md) for detailed usage.\n\n##### Keep-Alive\n\nEnable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/rest_api/keepAlive.md) for detailed usage.\n\n##### Compression\n\nEnable or disable response compression. See the [Compression example](./docs/rest_api/compression.md) for detailed usage.\n\n##### Retries\n\nConfigure 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.\n\n##### HTTPS Agent\n\nCustomize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest_api/httpsAgent.md) for detailed usage.\n\n##### Key Pair Based Authentication\n\nThe 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.\n\n##### Certificate Pinning\n\nTo enhance security, you can use certificate pinning with the `https_agent` 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.\n\n#### Error Handling\n\nThe REST API provides detailed error types to help you handle issues effectively:\n\n- `ClientError`: Represents an error that occurred in the SDK client.\n- `RequiredError`: Thrown when a required parameter is missing or undefined.\n- `UnauthorizedError`: Indicates missing or invalid authentication credentials.\n- `ForbiddenError`: Access to the requested resource is forbidden.\n- `TooManyRequestsError`: Rate limit exceeded.\n- `RateLimitBanError`: IP address banned for exceeding rate limits.\n- `ServerError`: Internal server error, optionally includes a status code.\n- `NetworkError`: Issues with network connectivity.\n- `NotFoundError`: Resource not found.\n- `BadRequestError`: Invalid request or one that cannot be served.\n\nSee the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage.\n\n#### Testnet\n\nFor testing purposes, `/dapi/*` endpoints can be used in the [Futures Testnet](https://testnet.binancefuture.com/). Update the `base_path` in your configuration:\n\n```python\nfrom binance_common.configuration import ConfigurationRestAPI\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nconfiguration = ConfigurationRestAPI(api_key=\"your-api-key\", api_secret=\"your-api-secret\", base_path=DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL)\nclient = DerivativesTradingCoinFutures(config_rest_api=configuration)\n```\n\nIf `base_path` is not provided, it defaults to `https://dapi.binance.com`.\n\n### Websocket APIs\n\nThe WebSocket API provides request-response communication for market data and trading actions. Use the [`websocket_api`](./src/binance_sdk_derivatives_trading_coin_futures/websocket_api/websocket_api.py) module to interact with these endpoints.\n\n```python\nfrom binance_common.configuration import ConfigurationWebSocketAPI\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nconfiguration = ConfigurationWebsocketAPI(api_key=\"your-api-key\", api_secret=\"your-api-secret\", base_path=DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL)\nclient = DerivativesTradingCoinFutures(configuration_websocket_api=configuration)\n```\n\nMore examples are available in the [`examples/websocket_api`](./examples/websocket_api/) folder.\n\n#### Configuration Options\n\nThe WebSocket API supports the following advanced configuration options:\n\n- `timeout`: Set the timeout for WebSocket requests (default: 5000 ms).\n- `reconnect_delay`: Delay (ms) between reconnections.\n- `compression`: Enable response compression.\n- `proxy`: Proxy configuration:\n  - `host`: Proxy server hostname.\n  - `port`: Proxy server port.\n  - `protocol`: Proxy protocol (http or https).\n  - `auth`: Proxy authentication credentials:\n    - `username`: Proxy username.\n    - `password`: Proxy password.\n- `mode`: Choose between `single` and `pool` connection modes.\n  - `single`: A single WebSocket connection.\n  - `pool`: A pool of WebSocket connections.\n- `pool_size`: Define the number of WebSocket connections in pool mode.\n- `private_key`: RSA or ED25519 private key for authentication.\n- `private_key_passphrase`: Passphrase for the private key, if encrypted.\n- `https_agent`: Custom HTTPS agent for advanced TLS configuration.\n- `user_agent`: Custom user agent string for WebSocket Streams.\n\n##### Timeout\n\nSet the timeout for WebSocket API requests in milliseconds. See the [Timeout example](./docs/websocket_api/timeout.md) for detailed usage.\n\n##### Reconnect Delay\n\nSpecify the delay in milliseconds between WebSocket reconnection attempts. See the [Reconnect Delay example](./docs/websocket_api/reconnect-delay.md) for detailed usage.\n\n##### Compression\n\nEnable or disable compression for WebSocket messages. See the [Compression example](./docs/websocket_api/compression.md) for detailed usage.\n\n##### Proxy\n\nThe WebSocket API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/websocket_api/proxy.md) for detailed usage.\n\n\n##### Connection Mode\n\nChoose between `single` and `pool` connection modes for WebSocket connections. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket_api/connection-mode.md) for detailed usage.\n\n##### Key Pair Based Authentication\n\nUse RSA or ED25519 private keys for WebSocket API authentication. See the [Key Pair Authentication example](./docs/websocket_api/key-pair-authentication.md) for detailed usage.\n\n##### WebSocket Http Agent\n\nCustomize the agent for advanced configurations. See the [WebSocket Http Agent example](./docs/websocket_api/agent.md) for detailed usage.\n\n#### Testnet\n\nFor testing purposes, the Websocket API also supports a testnet environment. Update the `wsURL` in your configuration:\n\n```python\nfrom binance_common.configuration import ConfigurationWebSocketAPI\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nconfiguration_ws_api = ConfigurationWebSocketAPI(\n    api_key=\"your-api-key\",\n    api_secret=\"your-api-secret\",\n    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL\n)\nclient = DerivativesTradingCoinFutures(config_ws_api=configuration_ws_api)\n```\n\nIf `wsURL` is not provided, it defaults to `wss://ws-api.binance.com:443/ws-api/v3`.\n\n### Websocket Streams\n\nWebSocket Streams provide real-time data feeds for market trades, candlesticks, and more. Use the [websocket-streams](./src/binance_sdk_derivatives_trading_coin_futures/websocket_streams/websocket_streams.py) module to subscribe to these streams.\n\n```python\nimport asyncio\nimport logging\n\nfrom binance_common.configuration import ConfigurationWebSocketStreams\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nlogging.basicConfig(level=logging.INFO)\n\nconfiguration_ws_streams = ConfigurationWebSocketStreams(\n    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL,\n)\n\nclient = DerivativesTradingCoinFutures(config_ws_streams=configuration_ws_streams)\n```\n\nMore examples are available in the [`examples/websocket-streams`](./examples/websocket_streams/) folder.\n\n#### Configuration Options\n\nThe WebSocket Streams API supports the following advanced configuration options:\n\n- `reconnect_delay`: Delay (ms) between reconnections.\n- `compression`: Enable response compression.\n- `proxy`: Proxy configuration:\n  - `host`: Proxy server hostname.\n  - `port`: Proxy server port.\n  - `protocol`: Proxy protocol (http or https).\n  - `auth`: Proxy authentication credentials:\n    - `username`: Proxy username.\n    - `password`: Proxy password.\n- `mode`: Choose between `single` and `pool` connection modes.\n  - `single`: A single WebSocket connection.\n  - `pool`: A pool of WebSocket connections.\n- `pool_size`: Define the number of WebSocket connections in pool mode.\n- `https_agent`: Custom HTTPS agent for advanced TLS configuration.\n- `user_agent`: Custom user agent string for WebSocket Streams.\n\n##### Reconnect Delay\n\nSpecify the delay in milliseconds between WebSocket reconnection attempts for streams. See the [Reconnect Delay example](./docs/websocket_streams/reconnect-delay.md) for detailed usage.\n\n##### Compression\n\nEnable or disable compression for WebSocket Streams messages. See the [Compression example](./docs/websocket_streams/compression.md) for detailed usage.\n\n##### Proxy\n\nThe WebSocket Streams supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/websocket_streams/proxy.md) for detailed usage.\n\n##### Connection Mode\n\nChoose between `single` and `pool` connection modes for WebSocket Streams. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket_streams/connection-mode.md) for detailed usage.\n\n##### WebSocket Http Agent\n\nCustomize the agent for advanced configurations. See the [WebSocket Http Agent example](./docs/websocket_streams/agent.md) for detailed usage.\n\n#### Unsubscribing from Streams\n\nYou can unsubscribe from specific WebSocket streams using the `unsubscribe` method. This is useful for managing active subscriptions without closing the connection.\n\n```python\nimport asyncio\nimport logging\n\nfrom binance_common.configuration import ConfigurationWebSocketStreams\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nlogging.basicConfig(level=logging.INFO)\n\nclient = DerivativesTradingCoinFutures(config_ws_streams=ConfigurationWebSocketStreams())\n\n\nasync def all_book_tickers_stream():\n    connection = None\n    try:\n        connection = await client.websocket_streams.create_connection()\n\n        stream = await connection.all_book_tickers_stream()\n        stream.on(\"message\", lambda data: print(f\"{data}\"))\n\n        await asyncio.sleep(5)\n        await stream.unsubscribe()\n    except Exception as e:\n        logging.error(f\"all_book_tickers_stream() error: {e}\")\n    finally:\n        if connection:\n            await connection.close_connection(close_session=True)\n\n\nif __name__ == \"__main__\":\n    asyncio.run(all_book_tickers_stream())\n```\n\n#### Testnet\n\nWebsocket Streams also support a testnet environment for development and testing. Update the `wsURL` in your configuration:\n\n```python\nfrom binance_common.configuration import ConfigurationWebSocketStreams\nfrom binance_common.constants import DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL\nfrom binance_sdk_derivatives_trading_coin_futures.derivatives_trading_coin_futures import DerivativesTradingCoinFutures\n\nconfig_ws_streams = ConfigurationWebSocketStreams(\n    stream_url=DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL\n)\n\nclient = DerivativesTradingCoinFutures(config_ws_streams=config_ws_streams)\n```\n\nIf `wsURL` is not provided, it defaults to `wss://dstream.binance.com`.\n\n### Automatic Connection Renewal\n\nThe WebSocket connection is automatically renewed for both WebSocket API and WebSocket Streams connections, before the 24 hours expiration of the API key. This ensures continuous connectivity.\n\n## Testing\n\nTo run the tests, ensure you have [Poetry](https://python-poetry.org/) installed, then execute the following commands:\n\n```bash\npoetry install\npoetry run pytest ./tests\n```\n\nThe tests cover:\n* REST API endpoints\n* WebSocket API endpoints\n* WebSocket Streams endpoints\n* Error handling\n* Edge cases\n\n## Migration Guide\n\nIf you are upgrading to the new modularized structure, refer to the [Migration Guide](./docs/migration_guide_derivatives_trading_coin_futures_sdk.md) for detailed steps.\n\n## Contributing\n\nContributions are welcome!\n\nSince 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.\n\nTo contribute:\n\n1. Open a GitHub issue describing your suggestion or the bug you've identified.\n2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.\n\nPlease ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.\n\nThank you for your contributions!\n\n## Licence\n\nThis project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Official Binance Derivatives Trading Coin Futures SDK - A lightweight library that provides a convenient interface to Binance's DerivativesTradingCoinFutures REST API, WebSocket API and WebSocket Streams.",
    "version": "2.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "72462f6bc097dcba1e854ac872eaf0ebbe744d4a2229e96d98eac85e9a1385bc",
                "md5": "aecc672cd53eb39a6daf9294dba12e69",
                "sha256": "91070cc99f66bcaa9c743eb6abc795a8e3331edb7aeed3267aa3374c3b0cb866"
            },
            "downloads": -1,
            "filename": "binance_sdk_derivatives_trading_coin_futures-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aecc672cd53eb39a6daf9294dba12e69",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.14,>=3.9",
            "size": 375131,
            "upload_time": "2025-08-22T14:42:26",
            "upload_time_iso_8601": "2025-08-22T14:42:26.027412Z",
            "url": "https://files.pythonhosted.org/packages/72/46/2f6bc097dcba1e854ac872eaf0ebbe744d4a2229e96d98eac85e9a1385bc/binance_sdk_derivatives_trading_coin_futures-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "085ecec6138fbad6f5f518a2fb7a7ea6149db4e31380702c5a5841a143f44cd5",
                "md5": "3ad8e5cb1a9dd6518987b2db6685cae4",
                "sha256": "cdd08bf16614d1c71c694553ac0b039d32d7ee398008de32031d78459992f1ca"
            },
            "downloads": -1,
            "filename": "binance_sdk_derivatives_trading_coin_futures-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3ad8e5cb1a9dd6518987b2db6685cae4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.14,>=3.9",
            "size": 101652,
            "upload_time": "2025-08-22T14:42:38",
            "upload_time_iso_8601": "2025-08-22T14:42:38.622741Z",
            "url": "https://files.pythonhosted.org/packages/08/5e/cec6138fbad6f5f518a2fb7a7ea6149db4e31380702c5a5841a143f44cd5/binance_sdk_derivatives_trading_coin_futures-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-22 14:42:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "binance-sdk-derivatives-trading-coin-futures"
}
        
Elapsed time: 3.25665s