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
33 changes: 16 additions & 17 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
build:
needs: lint
runs-on: ubuntu-22.04
timeout-minutes: 60
timeout-minutes: 40
env:
PROXY: "http://51.83.140.52:16301"
TEST_TESTNET: "true"
Expand Down Expand Up @@ -67,19 +67,18 @@ jobs:
run: pyright
- name: Test with tox
run: tox -e py
# comment due to coveralls maintenance of April 6 2025: https://status.coveralls.io/
# - name: Coveralls Parallel
# uses: coverallsapp/github-action@v2
# with:
# flag-name: run-${{ join(matrix.*, '-') }}
# parallel: true
# finish:
# needs: build
# if: ${{ always() }}
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - name: Coveralls Finished
# uses: coverallsapp/github-action@v2
# with:
# parallel-finished: true
- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
parallel: true
finish:
needs: build
if: ${{ always() }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
2 changes: 1 addition & 1 deletion binance/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BaseClient:
OPTIONS_TESTNET_URL = "https://testnet.binanceops.{}/eapi"
PAPI_URL = "https://papi.binance.{}/papi"
WS_API_URL = "wss://ws-api.binance.{}/ws-api/v3"
WS_API_TESTNET_URL = "wss://testnet.binance.vision/ws-api/v3"
WS_API_TESTNET_URL = "wss://ws-api.testnet.binance.vision/ws-api/v3"
WS_FUTURES_URL = "wss://ws-fapi.binance.{}/ws-fapi/v1"
WS_FUTURES_TESTNET_URL = "wss://testnet.binancefuture.com/ws-fapi/v1"
PUBLIC_API_VERSION = "v1"
Expand Down
2 changes: 1 addition & 1 deletion binance/ws/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BinanceSocketType(str, Enum):

class BinanceSocketManager:
STREAM_URL = "wss://stream.binance.{}:9443/"
STREAM_TESTNET_URL = "wss://testnet.binance.vision/"
STREAM_TESTNET_URL = "wss://stream.testnet.binance.vision/"
FSTREAM_URL = "wss://fstream.binance.{}/"
FSTREAM_TESTNET_URL = "wss://stream.binancefuture.com/"
DSTREAM_URL = "wss://dstream.binance.{}/"
Expand Down
25 changes: 16 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import pytest_asyncio
from binance.client import Client
from binance.async_client import AsyncClient
import os
Expand Down Expand Up @@ -61,21 +62,27 @@ def futuresClient():
)


@pytest.fixture(scope="function")
def clientAsync():
return AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=testnet)
@pytest_asyncio.fixture(scope="function")
async def clientAsync():
client = AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=testnet)
yield client
await client.close_connection()


@pytest.fixture(scope="function")
def futuresClientAsync():
return AsyncClient(
@pytest_asyncio.fixture(scope="function")
async def futuresClientAsync():
client = AsyncClient(
futures_api_key, futures_api_secret, https_proxy=proxy, testnet=testnet
)
yield client
await client.close_connection()


@pytest.fixture(scope="function")
def liveClientAsync():
return AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=False)
@pytest_asyncio.fixture(scope="function")
async def liveClientAsync():
client = AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=False)
yield client
await client.close_connection()

@pytest.fixture(scope="function")
def manager():
Expand Down
134 changes: 49 additions & 85 deletions tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,117 +18,94 @@ async def test_clientAsync_initialization(clientAsync):
@pytest.mark.skip(reason="Endpoint not documented")
async def test_get_products(clientAsync):
await clientAsync.get_products()


async def test_get_exchange_info(clientAsync):
await clientAsync.get_exchange_info()



async def test_get_symbol_info(clientAsync):
await clientAsync.get_symbol_info("BTCUSDT")


async def test_ping(clientAsync):
await clientAsync.ping()



async def test_get_server_time(clientAsync):
await clientAsync.get_server_time()



async def test_get_all_tickers(clientAsync):
await clientAsync.get_all_tickers()


async def test_get_orderbook_tickers(clientAsync):
await clientAsync.get_orderbook_tickers()



async def test_get_order_book(clientAsync):
await clientAsync.get_order_book(symbol="BTCUSDT")



async def test_get_recent_trades(clientAsync):
await clientAsync.get_recent_trades(symbol="BTCUSDT")


async def test_get_historical_trades(clientAsync):
await clientAsync.get_historical_trades(symbol="BTCUSDT")


async def test_get_aggregate_trades(clientAsync):
await clientAsync.get_aggregate_trades(symbol="BTCUSDT")



async def test_get_klines(clientAsync):
await clientAsync.get_klines(symbol="BTCUSDT", interval="1d")



async def test_get_uiklines(clientAsync):
await clientAsync.get_ui_klines(symbol="BTCUSDT", interval="1d")



async def test_futures_mark_price_klines(clientAsync):
await clientAsync.futures_mark_price_klines(symbol="BTCUSDT", interval="1h")



async def test_futures_index_price_klines(clientAsync):
await clientAsync.futures_index_price_klines(pair="BTCUSDT", interval="1h")



async def test_futures_premium_index_klines(clientAsync):
await clientAsync.futures_premium_index_klines(symbol="BTCUSDT", interval="1h")



@pytest.mark.skip(reason="network error")
async def test_futures_coin_premium_index_klines(clientAsync):
await clientAsync.futures_coin_premium_index_klines(symbol="BTCUSD", interval="1h")



async def test_get_avg_price(clientAsync):
await clientAsync.get_avg_price(symbol="BTCUSDT")



async def test_get_ticker(clientAsync):
await clientAsync.get_ticker(symbol="BTCUSDT")



async def test_get_symbol_ticker(clientAsync):
await clientAsync.get_symbol_ticker(symbol="BTCUSDT")



async def test_get_orderbook_ticker(clientAsync):
await clientAsync.get_orderbook_ticker(symbol="BTCUSDT")



async def test_get_account(clientAsync):
await clientAsync.get_account()



async def test_get_asset_balance(clientAsync):
await clientAsync.get_asset_balance(asset="BTC")



async def test_get_asset_balance_no_asset_provided(clientAsync):
await clientAsync.get_asset_balance()



async def test_get_my_trades(clientAsync):
await clientAsync.get_my_trades(symbol="BTCUSDT")



async def test_get_system_status(clientAsync):
await clientAsync.get_system_status()



# User Stream Endpoints


async def test_stream_get_listen_key_and_close(clientAsync):
listen_key = await clientAsync.stream_get_listen_key()
await clientAsync.stream_close(listen_key)



# Quoting interface endpoints


Expand All @@ -139,76 +116,62 @@ async def test_stream_get_listen_key_and_close(clientAsync):

async def test_ws_get_order_book(clientAsync):
await clientAsync.ws_get_order_book(symbol="BTCUSDT")



async def test_ws_get_recent_trades(clientAsync):
await clientAsync.ws_get_recent_trades(symbol="BTCUSDT")



async def test_ws_get_historical_trades(clientAsync):
await clientAsync.ws_get_historical_trades(symbol="BTCUSDT")



async def test_ws_get_aggregate_trades(clientAsync):
await clientAsync.ws_get_aggregate_trades(symbol="BTCUSDT")



async def test_ws_get_klines(clientAsync):
await clientAsync.ws_get_klines(symbol="BTCUSDT", interval="1m")



async def test_ws_get_uiKlines(clientAsync):
await clientAsync.ws_get_uiKlines(symbol="BTCUSDT", interval="1m")



async def test_ws_get_avg_price(clientAsync):
await clientAsync.ws_get_avg_price(symbol="BTCUSDT")



async def test_ws_get_ticker(clientAsync):
ticker = await clientAsync.ws_get_ticker(symbol="BTCUSDT")



async def test_ws_get_trading_day_ticker(clientAsync):
await clientAsync.ws_get_trading_day_ticker(symbol="BTCUSDT")



async def test_ws_get_symbol_ticker_window(clientAsync):
await clientAsync.ws_get_symbol_ticker_window(symbol="BTCUSDT")



async def test_ws_get_symbol_ticker(clientAsync):
await clientAsync.ws_get_symbol_ticker(symbol="BTCUSDT")



async def test_ws_get_orderbook_ticker(clientAsync):
await clientAsync.ws_get_orderbook_ticker(symbol="BTCUSDT")



async def test_ws_ping(clientAsync):
await clientAsync.ws_ping()



async def test_ws_get_time(clientAsync):
await clientAsync.ws_get_time()



async def test_ws_get_exchange_info(clientAsync):
await clientAsync.ws_get_exchange_info(symbol="BTCUSDT")

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_next_hourly_interest_rate(clientAsync):
await clientAsync.margin_next_hourly_interest_rate(
assets="BTC",
isIsolated="FALSE"
)

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_interest_history(clientAsync):
await clientAsync.margin_interest_history(
asset="BTC",
)

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_borrow_repay(clientAsync):
await clientAsync.margin_borrow_repay(
Expand All @@ -218,27 +181,26 @@ async def test_margin_borrow_repay(clientAsync):
symbol="BTCUSDT",
type="BORROW"
)

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_get_borrow_repay_records(clientAsync):
await clientAsync.margin_get_borrow_repay_records(
asset="BTC",
isolatedSymbol="BTCUSDT",
)

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_interest_rate_history(clientAsync):
await clientAsync.margin_interest_rate_history(
asset="BTC",
)

@pytest.mark.skip(reason="can't test margin endpoints")
async def test_margin_max_borrowable(clientAsync):
await clientAsync.margin_max_borrowable(
asset="BTC",
)



async def test_time_unit_microseconds():
micro_client = AsyncClient(
api_key, api_secret, https_proxy=proxy, testnet=testnet, time_unit="MICROSECOND"
Expand All @@ -247,7 +209,7 @@ async def test_time_unit_microseconds():
assert len(str(micro_trades[0]["time"])) >= 16, (
"Time should be in microseconds (16+ digits)"
)

await micro_client.close_connection()

async def test_time_unit_milloseconds():
milli_client = AsyncClient(
Expand All @@ -257,6 +219,7 @@ async def test_time_unit_milloseconds():
assert len(str(milli_trades[0]["time"])) == 13, (
"Time should be in milliseconds (13 digits)"
)
await milli_client.close_connection()


async def test_handle_response(clientAsync):
Expand Down Expand Up @@ -295,3 +258,4 @@ async def test_handle_response(clientAsync):
mock_response._body = b'error message'
with pytest.raises(BinanceAPIException):
await clientAsync._handle_response(mock_response)

Loading
Loading