Package: crypto-ws-api
Crypto WS API connector for ASYNC requestsFull coverage of all methods provided by the interfaceProvides of connection management, keepalive and rate limits controlFor :heavy_check_mark:Binance, :heavy_check_mark:OKX, :heavy_check_mark:BitfinexFeaturesLightweight and efficient solution to utilize of all available methods** provided through the:Binance Websocket API v3OKX Websocket API v5Bitfinex Websocket Inputs** Not for channel by one-way subscription, forrequest <-> responsemode onlySession management layer for:CredentialsConnectionKeepaliveError handlingLimits controlMethods constructionCreating request on-the-fly from method name and params: {}Generating signature if necessaryResponse handlingloggingUser interface layerStart session instanceSend async requestGet response or raised exceptionReuse instance for different type requestsStop session instanceGet startedInstall use PIPpip install crypto_ws_apiFor upgrade to latest versions use:pip install -U crypto_ws_apiAfter first install create environment by runcrypto_ws_api_initin terminal window.The config directory will be created. You get path to config:ubuntu@ubuntu:~$ crypto_ws_api_initCan't find config file! Creating it...Before first run set account(s) API key into /home/ubuntu/.config/crypto_ws_api/ws_api.tomlPrepare exchange accountFor test purpose log in atBinance Spot Test NetworkFor OKX and Bitfinex, unlike Binance, a limited number of methods are implemented at the WS API level,
such as creating, modifying, and deleting orders.
There are no public get-time (), ping-pong, etc., so this demo script is limited to calling Binance
to demonstrate capabilities.Create API KeyAfter install and create environment specify api_key and api_secret to the config fileStart demoRun in terminal windowcrypto_ws_api_demoUseful tipscrypto_ws_api/demo.py- complete and fully functional exampleGet credentials and create user sessionfrom crypto_ws_api.ws_session import UserWSSession

# Get credentials and create user session
# Can be omitted if you have credentials from other source
exchange, _test_net, api_key, api_secret, passphrase, ws_api_endpoint = get_credentials(account_name)

session = aiohttp.ClientSession()

trade_id = shortuuid.uuid()

user_session = UserWSSession(
    session,
    exchange,
    ws_api_endpoint,
    api_key,
    api_secret,
    passphrase
)Method exampleasync def account_information(user_session: UserWSSession, _trade_id):
    # https://developers.binance.com/docs/binance-trading-api/websocket_api#account-information-user_data
    try:
        res = await user_session.handle_request(
            _trade_id,
            "account.status",
            _api_key=True,
            _signed=True
        )
        if res is None:
            logger.warning("Here handling state Out-of-Service")
    except asyncio.CancelledError:
        pass  # Task cancellation should not be logged as an error
    except Exception as _ex:
        logger.error(f"Handling exception: {_ex}")
    else:
        logger.info(f"Account information (USER_DATA) response: {res}")Demo method's callingawait account_information(user_session, trade_id)Stop user session and close aiohttp sessionawait user_session.stop()
await session.close()Create limit order exampleif self.exchange == 'binance':
    params = {
        "symbol": "BTCUSDT",
        "side": "SELL",
        "type": "LIMIT",
        "timeInForce": "GTC",
        "price": "23416.10000000",
        "quantity": "0.00847000",
    }
    binance_res = await user_session.handle_request(trade_id, "order.place", params, _api_key=True, _signed=True)

elif self.exchange == 'bitfinex':
    params = {
        "type": "EXCHANGE LIMIT",
        "symbol": "tBTCUSDT",
        "price": "23416.10000000",
        "amount": ('' if side == 'BUY' else '-') + "0.00847000",
    }
    bitfnex_res = await user_session.handle_request(trade_id, "on", params)

elif self.exchange == 'okx':
    params = {
        "instId": "BTC-USDT",
        "tdMode": "cash",
        "clOrdId": "client_order_id",
        "side": "buy",
        "ordType": "limit",
        "sz": "0.00847000",
        "px": "23416.10000000",
    }
    okx_res = await user_session.handle_request(trade_id, "order", params)Logging setupFor configure logging in multi-module project use next snippet for yoursmain():import logging.handlers

logger = logging.getLogger(__name__)
formatter = logging.Formatter(fmt="[%(asctime)s: %(levelname)s] %(message)s")
#
sh = logging.StreamHandler()
sh.setFormatter(formatter)
sh.setLevel(logging.DEBUG)
#
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(sh)Limits control:link:Upon reaching the limit threshold of each type, the session switches to the Out-of-Service state.
If you send a request in this state, the answer will beNoneIn any case, you are protected from exceeding limits and blocking for this reasonDonateBNB,BUSD,USDT(BEP20) 0x5b52c6ba862b11318616ee6cef64388618318b92USDT(TRC20) TP1Y43dpY7rrRyTSLaSKDZmFirqvRcpopC