Skip to content

Commit 40b73c4

Browse files
authored
feat(client): add futures_ticker_socket and futures_coin_ticker_socket (sammchardy#1458)
* feat(client): add futures_ticker_socket and futures_coin_ticker_socket * add channel option * fix docs * blank line * expose enums
1 parent 0781051 commit 40b73c4

2 files changed

Lines changed: 88 additions & 4 deletions

File tree

binance/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
from binance.client import Client, AsyncClient # noqa
1010
from binance.depthcache import DepthCacheManager, OptionsDepthCacheManager, ThreadedDepthCacheManager # noqa
11-
from binance.streams import BinanceSocketManager, ThreadedWebsocketManager # noqa
11+
from binance.streams import BinanceSocketManager, ThreadedWebsocketManager, BinanceSocketType # noqa
12+
from binance.enums import * # noqa

binance/streams.py

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,84 @@ def ticker_socket(self):
804804
"""
805805
return self._get_socket('!ticker@arr')
806806

807+
808+
def futures_ticker_socket(self):
809+
"""Start a websocket for all ticker data
810+
811+
By default all markets are included in an array.
812+
813+
https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams
814+
815+
:returns: connection key string if successful, False otherwise
816+
817+
Message Format
818+
819+
.. code-block:: python
820+
821+
[
822+
{
823+
"e": "24hrTicker", // Event type
824+
"E": 123456789, // Event time
825+
"s": "BTCUSDT", // Symbol
826+
"p": "0.0015", // Price change
827+
"P": "250.00", // Price change percent
828+
"w": "0.0018", // Weighted average price
829+
"c": "0.0025", // Last price
830+
"Q": "10", // Last quantity
831+
"o": "0.0010", // Open price
832+
"h": "0.0025", // High price
833+
"l": "0.0010", // Low price
834+
"v": "10000", // Total traded base asset volume
835+
"q": "18", // Total traded quote asset volume
836+
"O": 0, // Statistics open time
837+
"C": 86400000, // Statistics close time
838+
"F": 0, // First trade ID
839+
"L": 18150, // Last trade Id
840+
"n": 18151 // Total number of trades
841+
}
842+
]
843+
"""
844+
return self._get_futures_socket('!ticker@arr', FuturesType.USD_M)
845+
846+
847+
def futures_coin_ticker_socket(self):
848+
"""Start a websocket for all ticker data
849+
850+
By default all markets are included in an array.
851+
852+
https://binance-docs.github.io/apidocs/delivery/en/#all-market-tickers-streams
853+
854+
:returns: connection key string if successful, False otherwise
855+
856+
Message Format
857+
858+
.. code-block:: python
859+
860+
[
861+
{
862+
"e": "24hrTicker", // Event type
863+
"E": 123456789, // Event time
864+
"s": "BTCUSDT", // Symbol
865+
"p": "0.0015", // Price change
866+
"P": "250.00", // Price change percent
867+
"w": "0.0018", // Weighted average price
868+
"c": "0.0025", // Last price
869+
"Q": "10", // Last quantity
870+
"o": "0.0010", // Open price
871+
"h": "0.0025", // High price
872+
"l": "0.0010", // Low price
873+
"v": "10000", // Total traded base asset volume
874+
"q": "18", // Total traded quote asset volume
875+
"O": 0, // Statistics open time
876+
"C": 86400000, // Statistics close time
877+
"F": 0, // First trade ID
878+
"L": 18150, // Last trade Id
879+
"n": 18151 // Total number of trades
880+
}
881+
]
882+
"""
883+
return self._get_futures_socket('!ticker@arr', FuturesType.COIN_M)
884+
807885
def index_price_socket(self, symbol: str, fast: bool = True):
808886
"""Start a websocket for a symbol's futures mark price
809887
https://binance-docs.github.io/apidocs/delivery/en/#index-price-stream
@@ -919,11 +997,16 @@ def individual_symbol_ticker_futures_socket(self, symbol: str, futures_type: Fut
919997
"""
920998
return self._get_futures_socket(symbol.lower() + '@ticker', futures_type=futures_type)
921999

922-
def all_ticker_futures_socket(self, futures_type: FuturesType = FuturesType.USD_M):
1000+
def all_ticker_futures_socket(self, channel: str = '!bookTicker', futures_type: FuturesType = FuturesType.USD_M):
9231001
"""Start a websocket for all ticker data
9241002
By default all markets are included in an array.
1003+
9251004
https://binance-docs.github.io/apidocs/futures/en/#all-book-tickers-stream
926-
:param futures_type: use USD-M or COIN-M futures default USD-M
1005+
1006+
https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams
1007+
1008+
:param channel: optional channel type, default '!bookTicker', but '!ticker@arr' is also available
1009+
:param: futures_type: use USD-M or COIN-M futures default USD-M
9271010
:returns: connection key string if successful, False otherwise
9281011
Message Format
9291012
.. code-block:: python
@@ -939,7 +1022,7 @@ def all_ticker_futures_socket(self, futures_type: FuturesType = FuturesType.USD_
9391022
]
9401023
"""
9411024

942-
return self._get_futures_socket('!bookTicker', futures_type=futures_type)
1025+
return self._get_futures_socket(channel, futures_type=futures_type)
9431026

9441027
def symbol_book_ticker_socket(self, symbol: str):
9451028
"""Start a websocket for the best bid or ask's price or quantity for a specified symbol.

0 commit comments

Comments
 (0)