Skip to content

Enhance Binance adapter to allow unauthed use of public endpoints #2621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stastnypremysl opened this issue May 10, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@stastnypremysl
Copy link
Collaborator

Feature Request

Problem Statement

When running

#!/usr/bin/env python3

import asyncio

from nautilus_trader.model import InstrumentId

from nautilus_trader.common.component import LiveClock, Logger

from nautilus_trader.config import InstrumentProviderConfig

from nautilus_trader.adapters.binance.common.enums import BinanceAccountType
from nautilus_trader.adapters.binance.factories import get_cached_binance_http_client
from nautilus_trader.adapters.binance.futures.providers import BinanceFuturesInstrumentProvider


def binance_futures_provider():
    clock = LiveClock()

    client = get_cached_binance_http_client(
        clock=clock,
        account_type=BinanceAccountType.USDT_FUTURE,
    )

    binance_provider = BinanceFuturesInstrumentProvider(
        client=client,
        clock=clock,
        config=InstrumentProviderConfig(load_all=True, log_warnings=True)
    )

    asyncio.run(binance_provider.load_all_async())
    return binance_provider


def binance_futures_instrument_from_pair(provider, pair):
    full_name = InstrumentId.from_str(f"{pair}-PERP.BINANCE")
    return provider.find(full_name)


provider = binance_futures_provider()
binance_futures_instrument_from_pair(provider, "APTUSDT")

I got the following exception

Traceback (most recent call last):
  File "/home/tmp/p/p-dev/./binance_instrument_provider.py", line 39, in <module>
    provider = binance_futures_provider()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tmp/p/p-dev/./binance_instrument_provider.py", line 19, in binance_futures_provider
    client = get_cached_binance_http_client(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/p/p-dev/nautilus/venv/lib/python3.12/site-packages/nautilus_trader/adapters/binance/factories.py", line 86, in get_cached_binance_http_client
    api_key = api_key or get_api_key(account_type, is_testnet)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/p/p-dev/nautilus/venv/lib/python3.12/site-packages/nautilus_trader/adapters/binance/common/credentials.py", line 30, in get_api_key
    return get_env_key("BINANCE_FUTURES_API_KEY")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/p/p-dev/nautilus/venv/lib/python3.12/site-packages/nautilus_trader/adapters/env.py", line 21, in get_env_key
    raise RuntimeError(f"Environment variable '{key}' not set")
RuntimeError: Environment variable 'BINANCE_FUTURES_API_KEY' not set

With API key it works.

Proposed Solution

Disable the key checking on anonymous endpoints.

Alternatives Considered

Setting the API key. This is not preferred as added complexity.

@stastnypremysl stastnypremysl added the enhancement New feature or request label May 10, 2025
@cjdsellers cjdsellers changed the title Change Binance adaptor, so it doesn't require key authentication on anonymous endpoints Enhance Binance adapter to allow unauthed use of public endpoints May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant