Crypto WS API connector for ASYNC requests
Project description
Crypto WS API connector for ASYNC requests
Full coverage of all methods provided by the interface
Provides of connection management, keepalive and rate limits control
Badges place here
For :heavy_check_mark:Binance,
Features
Lightweight and efficient solution to utilize of all available methods provided through the:
Session management layer for:
- Credentials
- Connection
- Keepalive
- Error handling
- Limits control
- Methods construction
- Generating session request id by default
- Creating request on-the-fly from method name and params: {}
- Generating signature if necessary
- Response handling
User interface layer
- Start session instance
- Getting session operational status
- Send async request
- Get response or raised exception
- Stop session instance
Get started
Install use PIP
pip install crypto_ws_api
For upgrade to latest versions use:
pip install -U crypto_ws_api
After first install create environment by run crypto_ws_api_init
in terminal window.
The config directory will be created. You get path to config ws_api.toml
Prepare exchange account
- For test purpose log in at Binance Spot Test Network
- Create API Key
- After install and create environment specify api_key and api_secret to the config file
Start demo
- Run in terminal window
crypto_ws_api_demo
Useful tips (see demo.py
for reference)
Get credentials and create user session
session = aiohttp.ClientSession()
exchange, test_net, api_key, api_secret, ws_api_endpoint = get_credentials(account_name)
user_session = UserWSSession(
api_key,
api_secret,
session=session,
endpoint=ws_api_endpoint
)
await user_session.start()
print(f"Operational status: {user_session.operational_status}")
Demo method's calling
await account_information(user_session)
Stop user session and close aiohttp session
await user_session.stop()
await session.close()
print(f"Operational status: {user_session.operational_status}")
Method call example
async def account_information(user_session: UserWSSession):
# https://developers.binance.com/docs/binance-trading-api/websocket_api#account-information-user_data
try:
res = {}
ws_status = bool(user_session and user_session.operational_status)
if ws_status:
res = await user_session.handle_request(
"account.status",
api_key=True,
signed=True
)
if not ws_status or res is None:
pass # Handling out of service state
except asyncio.CancelledError:
pass # Task cancellation should not be logged as an error
except Exception as _ex:
print(f"Handling exception: {_ex}")
else:
print(f"Account information (USER_DATA) response: {res}")
Limits control
Upon reaching the limit threshold of each type, the session switches to the Out-of-Service state. Monitor the values
of the variables user_session.operational_status
and user_session.order_handling
If you send a request in this state, the answer will be None
In any case, you are protected from exceeding limits and blocking for this reason
Donate
BNB, BUSD, USDT (BEP20) 0x5b52c6ba862b11318616ee6cef64388618318b92
USDT (TRC20) TP1Y43dpY7rrRyTSLaSKDZmFirqvRcpopC
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file crypto-ws-api-1.0.0b1.tar.gz
.
File metadata
- Download URL: crypto-ws-api-1.0.0b1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c9a49c650fdac6e57094801757f81365a74c8124bee5e678453bbfaeb9ec6ff |
|
MD5 | b088b3ee1919f20ac841872f34769b73 |
|
BLAKE2b-256 | 34d73cd2bfc9138a0462f3cf438f36a7792caf5e4dc3441365ffeaa0d00e465e |
File details
Details for the file crypto_ws_api-1.0.0b1-py3-none-any.whl
.
File metadata
- Download URL: crypto_ws_api-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12e3c18064373472608f59d5e3669a35d6fd39a3ef599b0879a2ec0bcfa18e74 |
|
MD5 | 070abac5635767d6b14943ade51d35dc |
|
BLAKE2b-256 | 62c0cca2db24e75fcd67c82ecad7868dc8f7b13f9a746a1f159b022c8228d056 |