diff --git a/CHANGELOG.md b/CHANGELOG.md index 9237694..35f9aaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html ## [Pending release] +## [5.1.1] - 2021-05-26 + +### Fixed + +- `binance` COIN-M futures websockets listen on correct address + ## [5.1.0] - 2021-05-25 ### Added @@ -157,7 +163,8 @@ bitvavo.enums.CandelstickInterval -> bitvavo.enums.CandlestickInterval The official release of `cryptoxlib-aio`. -[Pending release]: https://github.com/nardew/cryptoxlib-aio/compare/5.1.0...HEAD +[Pending release]: https://github.com/nardew/cryptoxlib-aio/compare/5.1.1...HEAD +[5.1.1]: https://github.com/nardew/cryptoxlib-aio/compare/5.1.0...5.1.1 [5.1.0]: https://github.com/nardew/cryptoxlib-aio/compare/5.0.0...5.1.0 [5.0.0]: https://github.com/nardew/cryptoxlib-aio/compare/4.1.0...5.0.0 [4.1.0]: https://github.com/nardew/cryptoxlib-aio/compare/4.0.0...4.1.0 diff --git a/README.md b/README.md index 64b6129..5ad2d82 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# cryptoxlib-aio 5.1.0 +# cryptoxlib-aio 5.1.1 ![](https://img.shields.io/badge/python-3.6-blue.svg) ![](https://img.shields.io/badge/python-3.7-blue.svg) ![](https://img.shields.io/badge/python-3.8-blue.svg) ![](https://img.shields.io/badge/python-3.9-blue.svg) diff --git a/cryptoxlib/WebsocketMgr.py b/cryptoxlib/WebsocketMgr.py index 45ebdd7..ea05789 100644 --- a/cryptoxlib/WebsocketMgr.py +++ b/cryptoxlib/WebsocketMgr.py @@ -269,13 +269,19 @@ def get_websocket(self) -> Websocket: return self.get_full_websocket() def get_full_websocket(self) -> Websocket: - return FullWebsocket(websocket_uri = self.websocket_uri + self.get_websocket_uri_variable_part(), + uri = self.websocket_uri + self.get_websocket_uri_variable_part() + LOG.debug(f"Websocket URI: {uri}") + + return FullWebsocket(websocket_uri = uri, builtin_ping_interval = self.builtin_ping_interval, max_message_size = self.max_message_size, ssl_context = self.ssl_context) def get_aiohttp_websocket(self) -> Websocket: - return AiohttpWebsocket(websocket_uri = self.websocket_uri + self.get_websocket_uri_variable_part(), + uri = self.websocket_uri + self.get_websocket_uri_variable_part() + LOG.debug(f"Websocket URI: {uri}") + + return AiohttpWebsocket(websocket_uri = uri, builtin_ping_interval = self.builtin_ping_interval, max_message_size = self.max_message_size, ssl_context = self.ssl_context) diff --git a/cryptoxlib/clients/binance/BinanceFuturesClient.py b/cryptoxlib/clients/binance/BinanceFuturesClient.py index c40e859..70dddda 100644 --- a/cryptoxlib/clients/binance/BinanceFuturesClient.py +++ b/cryptoxlib/clients/binance/BinanceFuturesClient.py @@ -399,7 +399,7 @@ async def get_commission_rate(self, symbol: PairSymbolType, recv_window_ms: Opti async def get_listen_key(self): return await self._create_post("listenKey", headers = self._get_header(), api_variable_path = self.get_api_v1()) - async def keep_alive_listen_key(self, listen_key: str): + async def keep_alive_listen_key(self): return await self._create_put("listenKey", headers = self._get_header(), api_variable_path = self.get_api_v1()) diff --git a/cryptoxlib/clients/binance/BinanceFuturesWebsocket.py b/cryptoxlib/clients/binance/BinanceFuturesWebsocket.py index 9fd7265..465afb0 100644 --- a/cryptoxlib/clients/binance/BinanceFuturesWebsocket.py +++ b/cryptoxlib/clients/binance/BinanceFuturesWebsocket.py @@ -38,7 +38,7 @@ class BinanceCOINMFuturesWebsocket(BinanceCommonWebsocket): def __init__(self, subscriptions: List[Subscription], binance_client, api_key: str = None, sec_key: str = None, ssl_context = None) -> None: super().__init__(subscriptions = subscriptions, binance_client = binance_client, api_key = api_key, - sec_key = sec_key, websocket_uri = BinanceUSDSMFuturesWebsocket.WEBSOCKET_URI, + sec_key = sec_key, websocket_uri = BinanceCOINMFuturesWebsocket.WEBSOCKET_URI, ssl_context = ssl_context) @@ -48,7 +48,7 @@ class BinanceCOINMFuturesTestnetWebsocket(BinanceCommonWebsocket): def __init__(self, subscriptions: List[Subscription], binance_client, api_key: str = None, sec_key: str = None, ssl_context = None) -> None: super().__init__(subscriptions = subscriptions, binance_client = binance_client, api_key = api_key, - sec_key = sec_key, websocket_uri = BinanceUSDSMFuturesTestnetWebsocket.WEBSOCKET_URI, + sec_key = sec_key, websocket_uri = BinanceCOINMFuturesTestnetWebsocket.WEBSOCKET_URI, ssl_context = ssl_context) diff --git a/examples/binance_coin_m_futures_ws.py b/examples/binance_coin_m_futures_ws.py index 8a99a72..1fa1a2a 100644 --- a/examples/binance_coin_m_futures_ws.py +++ b/examples/binance_coin_m_futures_ws.py @@ -42,8 +42,8 @@ async def run(): # Bundle several subscriptions into a single websocket client.compose_subscriptions([ OrderBookTickerSubscription(callbacks = [orderbook_ticker_update]), - OrderBookSymbolTickerSubscription(symbol = Pair("BTC", "USDT"), callbacks = [orderbook_ticker_update]), - CandlestickSubscription(interval = Interval.I_1MIN, symbol = Pair('BTC', 'USDT'), callbacks = [candlestick_update]) + OrderBookSymbolTickerSubscription(symbol = "BTCUSD_PERP", callbacks = [orderbook_ticker_update]), + CandlestickSubscription(interval = Interval.I_1MIN, symbol = "BTCUSD_PERP", callbacks = [candlestick_update]) ]) # Bundle another subscriptions into a separate websocket diff --git a/setup.py b/setup.py index c0c2961..76af9cc 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setuptools.setup( name="cryptoxlib-aio", - version="5.1.0", + version="5.1.1", author="nardew", author_email="cryptoxlib.aio@gmail.com", description="Cryptoexchange asynchronous python client", diff --git a/tests/e2e/binance_coin_m_futures.py b/tests/e2e/binance_coin_m_futures.py index ba96b6a..1fd722b 100644 --- a/tests/e2e/binance_coin_m_futures.py +++ b/tests/e2e/binance_coin_m_futures.py @@ -9,7 +9,7 @@ AllMarketTickersSubscription, MiniTickerSubscription, OrderBookTickerSubscription, \ OrderBookSymbolTickerSubscription, LiquidationOrdersSubscription, BlvtCandlestickSubscription, \ BlvtSubscription, CompositeIndexSubscription, DepthSubscription, CandlestickSubscription, \ - ContContractCandlestickSubscription, TickerSubscription, AccountSubscription + ContContractCandlestickSubscription, TickerSubscription from cryptoxlib.clients.binance.exceptions import BinanceRestException from cryptoxlib.Pair import Pair @@ -138,10 +138,6 @@ def check_positive_response(self, response): def check_error_code(self, e: BinanceRestException, status: str, code: str): return str(e.status_code) == status and str(e.body['code']) == code - async def test_get_ping(self): - response = await self.client.ping() - self.assertTrue(self.check_positive_response(response)) - async def test_change_position_type(self): # make sure some position exists in order for the change of position to fail await self.client.create_order(symbol = "BTCUSD_PERP", side = enums.OrderSide.BUY, @@ -304,7 +300,7 @@ async def init_test(self): async def test_aggregate_trade(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - AggregateTradeSubscription(symbol = "BTCUSDT", callbacks = [message_counter.generate_callback(1)]) + AggregateTradeSubscription(symbol = "BTCUSD_PERP", callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -312,7 +308,7 @@ async def test_aggregate_trade(self): async def test_mark_price(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - MarkPriceSubscription(symbol = Pair("BTC", "USDT"), frequency1sec = True, callbacks = [message_counter.generate_callback(1)]) + MarkPriceSubscription(symbol = "BTCUSD_PERP", frequency1sec = True, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -328,7 +324,7 @@ async def test_mark_price_all(self): async def test_candlestick(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - CandlestickSubscription(symbol = Pair("BTC", "USDT"), interval = enums.Interval.I_1MIN, callbacks = [message_counter.generate_callback(1)]) + CandlestickSubscription(symbol = "BTCUSD_PERP", interval = enums.Interval.I_1MIN, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -336,7 +332,7 @@ async def test_candlestick(self): async def test_cont_contract_candlestick(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - ContContractCandlestickSubscription(Pair("BTC", "USDT"), enums.Interval.I_1MIN, enums.ContractType.PERPETUAL, + ContContractCandlestickSubscription(Pair("BTC", "USD"), enums.Interval.I_1MIN, enums.ContractType.PERPETUAL, callbacks = [message_counter.generate_callback(1)]) ]) @@ -353,7 +349,7 @@ async def test_all_market_mini_ticker(self): async def test_mini_ticker(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - MiniTickerSubscription(Pair('BTC', 'USDT'), callbacks = [message_counter.generate_callback(1)]) + MiniTickerSubscription(symbol = "BTCUSD_PERP", callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -369,7 +365,7 @@ async def test_all_market_ticker(self): async def test_ticker(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - TickerSubscription(Pair('BTC', 'USDT'), callbacks = [message_counter.generate_callback(1)]) + TickerSubscription(symbol = "BTCUSD_PERP", callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -385,20 +381,21 @@ async def test_best_orderbook_ticker(self): async def test_best_orderbook_symbol_ticker(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - OrderBookSymbolTickerSubscription(Pair('BTC', 'USDT'), callbacks = [message_counter.generate_callback(1)]) + OrderBookSymbolTickerSubscription(symbol = "BTCUSD_PERP", callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) # fails since normally there are no liquidation orders - async def liquidation_orders(self): + async def test_liquidation_orders(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - LiquidationOrdersSubscription(Pair('BTC', 'USDT'), callbacks = [message_counter.generate_callback(1)]) + LiquidationOrdersSubscription(symbol = "BTCUSD_PERP", callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) + # fails since normally there are no liquidation orders async def test_all_liquidation_orders(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ @@ -410,7 +407,7 @@ async def test_all_liquidation_orders(self): async def test_partial_detph(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - DepthSubscription(symbol = Pair('BTC', 'USDT'), level = 5, frequency = 100, callbacks = [message_counter.generate_callback(1)]) + DepthSubscription(symbol = "BTCUSD_PERP", level = 5, frequency = 100, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -418,7 +415,7 @@ async def test_partial_detph(self): async def test_partial_detph2(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - DepthSubscription(symbol = Pair('BTC', 'USDT'), level = 5, callbacks = [message_counter.generate_callback(1)]) + DepthSubscription(symbol = "BTCUSD_PERP", level = 5, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -426,7 +423,7 @@ async def test_partial_detph2(self): async def test_detph(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - DepthSubscription(symbol = Pair('BTC', 'USDT'), level = 0, frequency = 100, callbacks = [message_counter.generate_callback(1)]) + DepthSubscription(symbol = "BTCUSD_PERP", level = 0, frequency = 100, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter) @@ -434,34 +431,7 @@ async def test_detph(self): async def test_detph2(self): message_counter = WsMessageCounter() self.client.compose_subscriptions([ - DepthSubscription(symbol = Pair('BTC', 'USDT'), level = 0, callbacks = [message_counter.generate_callback(1)]) - ]) - - await self.assertWsMessageCount(message_counter) - - async def test_blvt(self): - message_counter = WsMessageCounter() - self.client.compose_subscriptions([ - BlvtSubscription(Pair('BTC', 'UP'), callbacks = [message_counter.generate_callback(1)]) - ]) - - await self.assertWsMessageCount(message_counter) - - # typically no data are received - async def blvt_candlesticks(self): - message_counter = WsMessageCounter() - self.client.compose_subscriptions([ - BlvtCandlestickSubscription(Pair('BTC', 'UP'), enums.Interval.I_1MIN, - callbacks = [message_counter.generate_callback(1)]) - ]) - - await self.assertWsMessageCount(message_counter, timeout = 60) - - async def test_composite_index(self): - message_counter = WsMessageCounter() - self.client.compose_subscriptions([ - CompositeIndexSubscription(Pair('DEFI', 'USDT'), - callbacks = [message_counter.generate_callback(1)]) + DepthSubscription(symbol = "BTCUSD_PERP", level = 0, callbacks = [message_counter.generate_callback(1)]) ]) await self.assertWsMessageCount(message_counter)