From 90fed07a4639647001105a0b9db719067c91e6b6 Mon Sep 17 00:00:00 2001 From: alplabin <122352306+alplabin@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:51:11 +0900 Subject: [PATCH] v4.1.0 release --- CHANGELOG.md | 46 ++++ binance/__version__.py | 2 +- binance/cm_futures/__init__.py | 5 +- binance/cm_futures/account.py | 32 ++- binance/cm_futures/market.py | 17 ++ binance/cm_futures/portfolio_margin.py | 15 -- binance/um_futures/__init__.py | 18 ++ binance/um_futures/account.py | 223 ++++++++++++++++-- binance/um_futures/convert.py | 89 +++++++ binance/um_futures/market.py | 66 +++++- binance/websocket/binance_socket_manager.py | 15 +- .../websocket/um_futures/websocket_client.py | 18 +- .../query_index_price_constituents.py} | 3 +- .../get_download_id_transaction_history.py | 24 ++ .../convert/accept_offered_quote.py | 22 ++ .../convert/list_all_convert_pairs.py | 22 ++ examples/um_futures/convert/order_status.py | 22 ++ .../um_futures/convert/send_quote_request.py | 24 ++ examples/um_futures/market/funding_info.py | 9 + .../market/index_price_constituents.py | 9 + .../quarterly_contract_settlement_price.py | 10 + .../trade/async_download_order_id.py | 22 ++ .../trade/async_download_trade_id.py | 22 ++ .../um_futures/trade/download_order_asyn.py | 24 ++ .../um_futures/trade/download_trade_asyn.py | 24 ++ .../trade/futures_account_configuration.py | 22 ++ examples/um_futures/trade/get_bnb_burn.py | 22 ++ .../um_futures/trade/query_user_rate_limit.py | 22 ++ .../um_futures/trade/symbol_configuration.py | 22 ++ examples/um_futures/trade/toggle_bnb_burn.py | 22 ++ .../um_futures/mark_price_all_market.py | 25 ++ setup.py | 2 +- 32 files changed, 867 insertions(+), 53 deletions(-) delete mode 100644 binance/cm_futures/portfolio_margin.py create mode 100644 binance/um_futures/convert.py rename examples/cm_futures/{portfolio_margin/pm_exchange_info.py => market/query_index_price_constituents.py} (71%) create mode 100644 examples/cm_futures/trade/get_download_id_transaction_history.py create mode 100644 examples/um_futures/convert/accept_offered_quote.py create mode 100644 examples/um_futures/convert/list_all_convert_pairs.py create mode 100644 examples/um_futures/convert/order_status.py create mode 100644 examples/um_futures/convert/send_quote_request.py create mode 100644 examples/um_futures/market/funding_info.py create mode 100644 examples/um_futures/market/index_price_constituents.py create mode 100644 examples/um_futures/market/quarterly_contract_settlement_price.py create mode 100644 examples/um_futures/trade/async_download_order_id.py create mode 100644 examples/um_futures/trade/async_download_trade_id.py create mode 100644 examples/um_futures/trade/download_order_asyn.py create mode 100644 examples/um_futures/trade/download_trade_asyn.py create mode 100644 examples/um_futures/trade/futures_account_configuration.py create mode 100644 examples/um_futures/trade/get_bnb_burn.py create mode 100644 examples/um_futures/trade/query_user_rate_limit.py create mode 100644 examples/um_futures/trade/symbol_configuration.py create mode 100644 examples/um_futures/trade/toggle_bnb_burn.py create mode 100644 examples/websocket/um_futures/mark_price_all_market.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c18c726..ca65cc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,51 @@ # Changelog +## 4.1.0 - 2024-10-31 + +### Added +- UM_Futures: + - `GET /fapi/v1/fundingInfo` + - `GET /futures/data/delivery-price` + - `GET /fapi/v1/constituents` + - `GET /fapi/v1/accountConfig` + - `GET /fapi/v1/symbolConfig` + - `GET /fapi/v1/rateLimit/order` + - `GET /fapi/v1/order/asyn` + - `GET /fapi/v1/order/asyn/id` + - `GET /fapi/v1/trade/asyn` + - `GET /fapi/v1/trade/asyn/id` + - `POST /fapi/v1/feeBurn` + - `GET /fapi/v1/feeBurn` + - `GET /fapi/v1/convert/exchangeInfo` + - `POST /fapi/v1/convert/getQuote` + - `POST /fapi/v1/convert/acceptQuote` + - `GET /fapi/v1/convert/orderStatus` + - Websocket Stream `mark_price_all_market` + +- CM_Futures: + - `GET /dapi/v1/income/asyn` + - `GET /dapi/v1/constituents` + +### Changed +- UM_Futures: + - `GET /fapi/v1/income`: Add parameter `page` for pagination + - `POST /fapi/v1/order`: Add parameters `selfTradePreventionMode`, `priceMatch` and `goodTillDate` + - `POST /fapi/v1/batchOrders`: Add parameters `priceMatch`, `selfTradePreventionMode` and `goodTillDate` + - `GET /fapi/v1/ticker/price`: deprecated, replaced by `GET /fapi/v2/ticker/price` + - `GET /fapi/v2/balance`: deprecated, replaced by `GET /fapi/v3/balance` + - `GET /fapi/v2/account`: deprecated, replaced by `GET /fapi/v3/account` + - `GET /fapi/v2/positionRisk`: deprecated, replaced by `GET /fapi/v3/positionRisk` + +- CM_Futures: + - `GET /dapi/v1/income`: Add parameter `page` for pagination + - `POST /dapi/v1/order`: Add parameters `priceMatch` and `selfTradePreventionMode` + +- Update Websocket connection exceptions: Add `_handle_exception` method to handle exceptions + +### Removed +- CM_Futures: + - `/dapi/v1/pmExchangeInfo` + ## 4.0.1 - 2024-10-03 ### Removed diff --git a/binance/__version__.py b/binance/__version__.py index 76ad18b..7039708 100644 --- a/binance/__version__.py +++ b/binance/__version__.py @@ -1 +1 @@ -__version__ = "4.0.1" +__version__ = "4.1.0" diff --git a/binance/cm_futures/__init__.py b/binance/cm_futures/__init__.py index 3651413..ea845e0 100644 --- a/binance/cm_futures/__init__.py +++ b/binance/cm_futures/__init__.py @@ -24,6 +24,7 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.cm_futures.market import ticker_24hr_price_change from binance.cm_futures.market import ticker_price from binance.cm_futures.market import book_ticker + from binance.cm_futures.market import query_index_price_constituents from binance.cm_futures.market import open_interest from binance.cm_futures.market import open_interest_hist from binance.cm_futures.market import top_long_short_account_ratio @@ -57,6 +58,7 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.cm_futures.account import get_position_risk from binance.cm_futures.account import get_account_trades from binance.cm_futures.account import get_income_history + from binance.cm_futures.account import get_download_id_transaction_history from binance.cm_futures.account import leverage_brackets from binance.cm_futures.account import adl_quantile from binance.cm_futures.account import force_orders @@ -66,6 +68,3 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.cm_futures.data_stream import new_listen_key from binance.cm_futures.data_stream import renew_listen_key from binance.cm_futures.data_stream import close_listen_key - - # PORTFOLIO MARGIN - from binance.cm_futures.portfolio_margin import pm_exchange_info diff --git a/binance/cm_futures/account.py b/binance/cm_futures/account.py index 7eae8f1..aefa1be 100644 --- a/binance/cm_futures/account.py +++ b/binance/cm_futures/account.py @@ -64,7 +64,9 @@ def new_order(self, symbol: str, side: str, type: str, **kwargs): :parameter callbackRate: optional float. Use with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1%. :parameter workingType: optional string. stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE". :parameter priceProtect: optional string. "TRUE" or "FALSE", default "FALSE". Use with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders. - :parameter newOrderRespType: optional float. "ACK" or "RESULT", default "ACK". + :parameter newOrderRespType: optional string. "ACK" or "RESULT", default "ACK". + :parameter priceMatch: optional string. only avaliable for "LIMIT"/"STOP"/"TAKE_PROFIT" order; can be set to "OPPONENT"/"OPPONENT_5"/"OPPONENT_10"/"OPPONENT_20": /"QUEUE"/"QUEUE_5"/"QUEUE_10"/"QUEUE_20"; Can't be passed together with price. + :parameter selfTradePreventionMode: optional string. "NONE":No STP /"EXPIRE_TAKER":expire taker order when STP triggers/"EXPIRE_MAKER":expire taker order when STP triggers/"EXPIRE_BOTH":expire both orders when STP triggers; default "NONE". :parameter recvWindow: optional int | """ @@ -88,7 +90,7 @@ def modify_order( | **Modify Order (TRADE)** | *Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.* - :API endpoint: ``POST /dapi/v1/order`` + :API endpoint: ``PUT /dapi/v1/order`` :API doc: https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/Modify-Order :parameter symbol: string @@ -673,6 +675,7 @@ def get_income_history(self, **kwargs): :parameter incomeType: optional string; "TRANSFER", "WELCOME_BONUS", "REALIZED_PNL", "FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR" :parameter startTime: optional string; timestamp in ms to get funding from INCLUSIVE. :parameter endTime: optional string; timestamp in ms to get funding from INCLUSIVE. + :parameter page: optional int :parameter limit: optional int; default 50, max 100 :parameter recvWindow: optional int @@ -688,6 +691,31 @@ def get_income_history(self, **kwargs): return self.sign_request("GET", url_path, params) +def get_download_id_transaction_history(self, startTime: int, endTime: int, **kwargs): + """ + | + | **Get Download Id For Futures Transaction History (USER_DATA)** + | *Get download ID transaction history.* + | *Request Limitation is 5 times per month, shared by front end download page and rest api* + | *The time between startTime and endTime can not be longer than 1 year* + + :API endpoint: ``GET /dapi/v1/income/asyn`` + :API doc: https://developers.binance.com/docs/derivatives/coin-margined-futures/account/Get-Download-Id-For-Futures-Transaction-History + + :parameter startTime: int + :parameter endTime: int + :parameter recvWindow: optional int + | + """ + + check_required_parameter(startTime, "startTime") + check_required_parameter(endTime, "endTime") + url_path = "/dapi/v1/income/asyn" + params = {"startTime": startTime, "endTime": endTime, **kwargs} + + return self.sign_request("GET", url_path, params) + + def leverage_brackets(self, symbol: str = None, pair: str = None, **kwargs): """ | diff --git a/binance/cm_futures/market.py b/binance/cm_futures/market.py index 665490f..331fe39 100644 --- a/binance/cm_futures/market.py +++ b/binance/cm_futures/market.py @@ -352,6 +352,23 @@ def book_ticker(self, symbol: str = None, pair: str = None): return self.query("/dapi/v1/ticker/bookTicker", params) +def query_index_price_constituents(self, symbol: str): + """ + | + | **Query Index Price Constituents** + + :API endpoint: ``GET /dapi/v1/constituents`` + :API doc: https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Index-Constituents + + :parameter symbol: string; symbol underlying e.g BTCUSD + | + """ + + check_required_parameter(symbol, "symbol") + params = {"symbol": symbol} + return self.query("/dapi/v1/constituents", params) + + def open_interest(self, symbol: str): """ | diff --git a/binance/cm_futures/portfolio_margin.py b/binance/cm_futures/portfolio_margin.py deleted file mode 100644 index 279dbea..0000000 --- a/binance/cm_futures/portfolio_margin.py +++ /dev/null @@ -1,15 +0,0 @@ -def pm_exchange_info(self, symbol: str = None): - """ - | - | **Portfolio Margin Exchange Information** - | *Current Portfolio Margin exchange trading rules.* - - :API endpoint: ``GET /dapi/v1/pmExchangeInfo`` - :API doc: https://developers.binance.com/docs/derivatives/coin-margined-futures/portfolio-margin-endpoints/Query-Classic-Portfolio-Margin-Notional-Limit - - :parameter symbol: string; the trading pair. - | - """ - - params = {"symbol": symbol} - return self.query("/dapi/v1/pmExchangeInfo", params) diff --git a/binance/um_futures/__init__.py b/binance/um_futures/__init__.py index 0c153d4..a6690f3 100644 --- a/binance/um_futures/__init__.py +++ b/binance/um_futures/__init__.py @@ -21,9 +21,11 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.um_futures.market import mark_price_klines from binance.um_futures.market import mark_price from binance.um_futures.market import funding_rate + from binance.um_futures.market import funding_info from binance.um_futures.market import ticker_24hr_price_change from binance.um_futures.market import ticker_price from binance.um_futures.market import book_ticker + from binance.um_futures.market import quarterly_contract_settlement_price from binance.um_futures.market import open_interest from binance.um_futures.market import open_interest_hist from binance.um_futures.market import top_long_short_position_ratio @@ -33,6 +35,7 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.um_futures.market import blvt_kline from binance.um_futures.market import index_info from binance.um_futures.market import asset_Index + from binance.um_futures.market import index_price_constituents # ACCOUNT(including orders and trades) from binance.um_futures.account import change_position_mode @@ -65,8 +68,23 @@ def __init__(self, key=None, secret=None, **kwargs): from binance.um_futures.account import force_orders from binance.um_futures.account import api_trading_status from binance.um_futures.account import commission_rate + from binance.um_futures.account import futures_account_configuration + from binance.um_futures.account import symbol_configuration + from binance.um_futures.account import query_user_rate_limit from binance.um_futures.account import download_transactions_asyn from binance.um_futures.account import aysnc_download_info + from binance.um_futures.account import download_order_asyn + from binance.um_futures.account import async_download_order_id + from binance.um_futures.account import download_trade_asyn + from binance.um_futures.account import async_download_trade_id + from binance.um_futures.account import toggle_bnb_burn + from binance.um_futures.account import get_bnb_burn + + # CONVERT + from binance.um_futures.convert import list_all_convert_pairs + from binance.um_futures.convert import send_quote_request + from binance.um_futures.convert import accept_offered_quote + from binance.um_futures.convert import order_status # STREAMS from binance.um_futures.data_stream import new_listen_key diff --git a/binance/um_futures/account.py b/binance/um_futures/account.py index 1c303cb..019af09 100644 --- a/binance/um_futures/account.py +++ b/binance/um_futures/account.py @@ -85,7 +85,7 @@ def new_order(self, symbol: str, side: str, type: str, **kwargs): | *Send a new order* :API endpoint: ``POST /fapi/v1/order`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/New-Order + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api :parameter symbol: string :parameter side: string @@ -102,7 +102,10 @@ def new_order(self, symbol: str, side: str, type: str, **kwargs): :parameter callbackRate: optional float. Use with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1%. :parameter workingType: optional string. stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE". :parameter priceProtect: optional string. "TRUE" or "FALSE", default "FALSE". Use with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders. - :parameter newOrderRespType: optional float. "ACK" or "RESULT", default "ACK". + :parameter newOrderRespType: optional string. "ACK" or "RESULT", default "ACK". + :parameter priceMatch: optional string. only avaliable for "LIMIT"/"STOP"/"TAKE_PROFIT" order; can be set to "OPPONENT"/"OPPONENT_5"/"OPPONENT_10"/"OPPONENT_20": /"QUEUE"/"QUEUE_5"/"QUEUE_10"/"QUEUE_20"; Can't be passed together with price. + :parameter selfTradePreventionMode: optional string. "NONE":No STP /"EXPIRE_TAKER":expire taker order when STP triggers/"EXPIRE_MAKER":expire taker order when STP triggers/"EXPIRE_BOTH":expire both orders when STP triggers; default "NONE". + :parameter goodTillDate: optional int. order cancel time for timeInForce "GTD", mandatory when timeInforce set to "GTD"; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000. :parameter recvWindow: optional int | """ @@ -120,7 +123,7 @@ def new_order_test(self, symbol: str, side: str, type: str, **kwargs): | *Send a new test order* :API endpoint: ``POST /fapi/v1/order/test`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/New-Order + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order-Test :parameter symbol: string :parameter side: string @@ -164,7 +167,7 @@ def modify_order( | *Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue* :API endpoint: ``PUT /fapi/v1/order`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order :parameter symbol: string :parameter side: string @@ -236,7 +239,10 @@ def new_batch_order(self, batchOrders: list): :parameter callbackRate: optional float. Use with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1%. :parameter workingType: optional string. stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE". :parameter priceProtect: optional string. "TRUE" or "FALSE", default "FALSE". Use with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders. - :parameter newOrderRespType: optional float. "ACK" or "RESULT", default "ACK". + :parameter newOrderRespType: optional string. "ACK" or "RESULT", default "ACK". + :parameter priceMatch: optional string. only avaliable for "LIMIT"/"STOP"/"TAKE_PROFIT" order; can be set to "OPPONENT"/"OPPONENT_5"/"OPPONENT_10"/"OPPONENT_20": /"QUEUE"/"QUEUE_5"/"QUEUE_10"/"QUEUE_20"; Can't be passed together with price. + :parameter selfTradePreventionMode: optional string. "NONE":No STP /"EXPIRE_TAKER":expire taker order when STP triggers/"EXPIRE_MAKER":expire taker order when STP triggers/"EXPIRE_BOTH":expire both orders when STP triggers; default "NONE". + :parameter goodTillDate: optional int. order cancel time for timeInForce "GTD", mandatory when timeInforce set to "GTD"; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000. :parameter recvWindow: optional int | @@ -286,7 +292,7 @@ def query_order( | *Check an order's status* :API endpoint: ``GET /fapi/v1/order`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order :parameter symbol: string :parameter orderId: optional int @@ -321,7 +327,7 @@ def cancel_order( | *Cancel an active order.* :API endpoint: ``DELETE /fapi/v1/order`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order :parameter symbol: string :parameter orderId: optional int @@ -537,31 +543,31 @@ def balance(self, **kwargs): | **Futures Account Balance V2 (USER_DATA)** | *Get current account balance* - :API endpoint: ``GET /fapi/v2/balance`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V2 + :API endpoint: ``GET /fapi/v3/balance`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V3 :parameter recvWindow: optional int | """ - url_path = "/fapi/v2/balance" + url_path = "/fapi/v3/balance" return self.sign_request("GET", url_path, {**kwargs}) def account(self, **kwargs): """ | - | **Account Information V2 (USER_DATA)** + | **Account Information V3(USER_DATA)** | *Get current account information* - :API endpoint: ``GET /fapi/v2/account`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2 + :API endpoint: ``GET /fapi/v3/account`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V3 :parameter recvWindow: optional int | """ - url_path = "/fapi/v2/account" + url_path = "/fapi/v3/account" return self.sign_request("GET", url_path, {**kwargs}) @@ -663,15 +669,15 @@ def get_position_risk(self, **kwargs): | **Position Information V2 (USER_DATA)** | *Get current position information.* - :API endpoint: ``GET /fapi/v2/positionRisk`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information + :API endpoint: ``GET /fapi/v3/positionRisk`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3 :parameter symbol: string :parameter recvWindow: optional int | """ - url_path = "/fapi/v2/positionRisk" + url_path = "/fapi/v3/positionRisk" params = {**kwargs} return self.sign_request("GET", url_path, params) @@ -720,6 +726,7 @@ def get_income_history(self, **kwargs): :parameter incomeType: optional string; "TRANSFER", "WELCOME_BONUS", "REALIZED_PNL", "FUNDING_FEE", "COMMISSION" and "INSURANCE_CLEAR". :parameter startTime: optional int; timestamp in ms to get funding from INCLUSIVE. :parameter endTime: optional int; timestamp in ms to get funding from INCLUSIVE. + :parameter page: optional int :parameter limit: optional int; default: 100, max: 1000. :parameter recvWindow: optional int @@ -850,6 +857,59 @@ def commission_rate(self, symbol: str, **kwargs): return self.sign_request("GET", url_path, params) +def futures_account_configuration(self, **kwargs): + """ + | + | **Futures Account Configuration(USER_DATA)** + + :API endpoint: ``GET /fapi/v1/accountConfig`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Config + + :parameter recvWindow: optional int + | + """ + url_path = "/fapi/v1/accountConfig" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) + + +def symbol_configuration(self, **kwargs): + """ + | + | **Symbol Configuration(USER_DATA)** + | *Get current account symbol configuration.* + + :API endpoint: ``GET /fapi/v1/symbolConfig`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config + + :parameter symbol: optional string + :parameter recvWindow: optional int + | + """ + url_path = "/fapi/v1/symbolConfig" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) + + +def query_user_rate_limit(self, **kwargs): + """ + | + | **Query User Rate Limit (USER_DATA)** + + :API endpoint: ``GET /fapi/v1/rateLimit/order`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-Rate-Limit + + :parameter recvWindow: optional int + | + """ + url_path = "/fapi/v1/rateLimit/order" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) + + def download_transactions_asyn(self, startTime: int, endTime: int, **kwargs): """ | @@ -890,3 +950,132 @@ def aysnc_download_info(self, downloadId: str, **kwargs): params = {"downloadId": downloadId, **kwargs} return self.sign_request("GET", url_path, params) + + +def download_order_asyn(self, startTime: int, endTime: int, **kwargs): + """ + | + | **Get Download Id For Futures Order History (USER_DATA)** + | *Request Limitation is 10 times per month, shared by front end download page and rest api* + | *The time between startTime and endTime can not be longer than 1 year* + + :API endpoint: ``GET /fapi/v1/order/asyn`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History + + :parameter startTime: int + :parameter endTime: int + :parameter recvWindow: optional int + | + """ + + check_required_parameter(startTime, "startTime") + check_required_parameter(endTime, "endTime") + url_path = "/fapi/v1/order/asyn" + params = {"startTime": startTime, "endTime": endTime, **kwargs} + + return self.sign_request("GET", url_path, params) + + +def async_download_order_id(self, downloadId: str, **kwargs): + """ + | + | **Get Futures Order History Download Link by Id (USER_DATA)** + | *Download link expiration: 24h* + + :API endpoint: ``GET /fapi/v1/order/asyn/id`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id + + :parameter downloadId: string + :parameter recvWindow: optional int + | + """ + + check_required_parameter(downloadId, "downloadId") + url_path = "/fapi/v1/order/asyn/id" + params = {"downloadId": downloadId, **kwargs} + + return self.sign_request("GET", url_path, params) + + +def download_trade_asyn(self, startTime: int, endTime: int, **kwargs): + """ + | + | **Get Download Id For Futures Trade History (USER_DATA)** + | *Request Limitation is 5 times per month, shared by front end download page and rest api* + | *The time between startTime and endTime can not be longer than 1 year* + + :API endpoint: ``GET /fapi/v1/trade/asyn`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History + + :parameter startTime: int + :parameter endTime: int + :parameter recvWindow: optional int + | + """ + + check_required_parameter(startTime, "startTime") + check_required_parameter(endTime, "endTime") + url_path = "/fapi/v1/trade/asyn" + params = {"startTime": startTime, "endTime": endTime, **kwargs} + + return self.sign_request("GET", url_path, params) + + +def async_download_trade_id(self, downloadId: str, **kwargs): + """ + | + | **Get Futures Trade Download Link by Id(USER_DATA)** + | *Download link expiration: 24h* + + :API endpoint: ``GET /fapi/v1/trade/asyn/id`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id + + :parameter downloadId: string + :parameter recvWindow: optional int + | + """ + + check_required_parameter(downloadId, "downloadId") + url_path = "/fapi/v1/trade/asyn/id" + params = {"downloadId": downloadId, **kwargs} + + return self.sign_request("GET", url_path, params) + + +def toggle_bnb_burn(self, feeBurn: str, **kwargs): + """ + | + | **Toggle BNB Burn On Futures Trade (TRADE)** + | *Change user's BNB Fee Discount (Fee Discount On or Fee Discount Off ) on EVERY symbol* + + :API endpoint: ``POST /fapi/v1/feeBurn`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Toggle-BNB-Burn-On-Futures-Trade + + :parameter feeBurn: string; "true": Fee Discount On; "false": Fee Discount Off + :parameter recvWindow: optional int + | + """ + + check_required_parameter(feeBurn, "feeBurn") + url_path = "/fapi/v1/feeBurn" + params = {"feeBurn": feeBurn, **kwargs} + + return self.sign_request("POST", url_path, params) + + +def get_bnb_burn(self, **kwargs): + """ + | + | **Get BNB Burn Status (USER_DATA)** + + :API endpoint: ``GET /fapi/v1/feeBurn`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-BNB-Burn-Status + + :parameter recvWindow: optional int + | + """ + + url_path = "/fapi/v1/feeBurn" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) diff --git a/binance/um_futures/convert.py b/binance/um_futures/convert.py new file mode 100644 index 0000000..29b7876 --- /dev/null +++ b/binance/um_futures/convert.py @@ -0,0 +1,89 @@ +from binance.lib.utils import check_required_parameter + + +def list_all_convert_pairs(self, **kwargs): + """ + | + | **List All Convert Pairs** + | *User needs to supply either or both of the input parameter* + | *If not defined for both fromAsset and toAsset, only partial token pairs will be returned* + | *Asset BNFCR is only available to convert for MICA region users.* + + :API endpoint: ``GET /fapi/v1/convert/exchangeInfo`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/convert + + :parameter fromAsset: optional string; EITHER OR BOTH - User spends coin + :parameter toAsset: optional string; EITHER OR BOTH - User receives coin + | + """ + + url_path = "/sapi/v1/asset/assetDividend" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) + + +def send_quote_request(self, fromAsset: str, toAsset: str, **kwargs): + """ + | + | **Send Quote Request(USER_DATA)** + | *Either fromAmount or toAmount should be sent* + | *quoteId will be returned only if you have enough funds to convert* + + :API endpoint: ``POST /fapi/v1/convert/getQuote`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Send-quote-request + + :parameter fromAsset: string; the asset to convert from + :parameter toAsset: string; the asset to convert to + :parameter fromAmount: optional float; When specified, it is the amount you will be debited after the conversion + :parameter toAmount: optional float; When specified, it is the amount you will be credited after the conversion + :parameter validTime: optional string; 10s, default 10s + :parameter recvWindow: optional int + | + """ + + check_required_parameter(fromAsset, "fromAsset") + check_required_parameter(toAsset, "toAsset") + url_path = "/fapi/v1/convert/getQuote" + params = {"fromAsset": fromAsset, "toAsset": toAsset, **kwargs} + + return self.sign_request("POST", url_path, params) + + +def accept_offered_quote(self, quoteId: str, **kwargs): + """ + | + | **Accept the offered quote (USER_DATA)** + + :API endpoint: ``POST /fapi/v1/convert/acceptQuote`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Accept-Quote + + :parameter quoteId: string + :parameter recvWindow: optional int + | + """ + + check_required_parameter(quoteId, "quoteId") + url_path = "/fapi/v1/convert/acceptQuote" + params = {"quoteId": quoteId, **kwargs} + + return self.sign_request("POST", url_path, params) + + +def order_status(self, **kwargs): + """ + | + | **Order status(USER_DATA)** + + :API endpoint: ``GET /fapi/v1/convert/orderStatus`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Order-Status + + :parameter orderId: optional string; Either orderId or quoteId is required + :parameter quoteId: optional string; Either orderId or quoteId is required + | + """ + + url_path = "/fapi/v1/convert/orderStatus" + params = {**kwargs} + + return self.sign_request("GET", url_path, params) diff --git a/binance/um_futures/market.py b/binance/um_futures/market.py index 63b5ab8..4e6e4c1 100644 --- a/binance/um_futures/market.py +++ b/binance/um_futures/market.py @@ -53,7 +53,7 @@ def depth(self, symbol: str, **kwargs): | **Get Orderbook** :API endpoint: ``GET /fapi/v1/depth`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Order-Book + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book :parameter symbol: string; the trading symbol. :parameter limit: optional int; limit the results. Default 500, valid limits: [5, 10, 20, 50, 100, 500, 1000]. @@ -263,6 +263,20 @@ def funding_rate(self, symbol: str, **kwargs): return self.query("/fapi/v1/fundingRate", params) +def funding_info(self): + """ + | + | **Get Funding Rate Info** + | *Query funding rate info for symbols that had FundingRateCap/FundingRateFloor/fundingIntervalHours adjustment* + + :API endpoint: ``GET /fapi/v1/fundingInfo`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Info + | + """ + + return self.query("/fapi/v1/fundingRate") + + def ticker_24hr_price_change(self, symbol: str = None): """ | @@ -286,10 +300,11 @@ def ticker_24hr_price_change(self, symbol: str = None): def ticker_price(self, symbol: str = None): """ | - | **Latest price for a symbol or symbols.** + | **Symbol Price Ticker V2** + | *If the symbol is not sent, prices for all symbols will be returned in an array.* - :API endpoint: ``GET /fapi/v1/ticker/price`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker + :API endpoint: ``GET /fapi/v2/ticker/price`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Price-Ticker-v2 :parameter symbol: optional string; the trading symbol. @@ -301,7 +316,7 @@ def ticker_price(self, symbol: str = None): params = { "symbol": symbol, } - return self.query("/fapi/v1/ticker/price", params) + return self.query("/fapi/v2/ticker/price", params) def book_ticker(self, symbol: str = None): @@ -310,7 +325,7 @@ def book_ticker(self, symbol: str = None): | **Best price/qty on the order book for a symbol or symbols.** :API endpoint: ``GET /fapi/v1/ticker/bookTicker`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker :parameter symbol: optional string; the trading symbol. @@ -325,6 +340,24 @@ def book_ticker(self, symbol: str = None): return self.query("/fapi/v1/ticker/bookTicker", params) +def quarterly_contract_settlement_price(self, pair: str): + """ + | + | **Quarterly Contract Settlement Price** + | *Latest price for a symbol or symbols.* + + :API endpoint: ``GET /futures/data/delivery-price`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Delivery-Price + + :parameter pair: string; the trading pair. + | + """ + + check_required_parameter(pair, "pair") + params = {"pair": pair} + return self.query("/futures/data/delivery-price", params) + + def open_interest(self, symbol: str): """ | @@ -518,7 +551,7 @@ def asset_Index(self, symbol: str = None): | **Get asset index for Multi-Assets mode** :API endpoint: ``GET /fapi/v1/assetIndex`` - :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Multi-Assets-Mode-Asset-Index + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Multi-Assets-Mode-Asset-Index :parameter symbol: optional string; Asset pair in multi asset mode (ex: BTCUSD). | @@ -528,3 +561,22 @@ def asset_Index(self, symbol: str = None): "symbol": symbol, } return self.query("/fapi/v1/assetIndex", params) + + +def index_price_constituents(self, symbol: str = None): + """ + | + | **Query Index Price Constituents** + | *Query index price constituents* + + :API endpoint: ``GET /fapi/v1/constituents`` + :API doc: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Constituents + + :parameter symbol: string; the trading symbol. + | + """ + + params = { + "symbol": symbol, + } + return self.query("/fapi/v1/constituents", params) diff --git a/binance/websocket/binance_socket_manager.py b/binance/websocket/binance_socket_manager.py index 61567cf..15f33b3 100644 --- a/binance/websocket/binance_socket_manager.py +++ b/binance/websocket/binance_socket_manager.py @@ -71,10 +71,12 @@ def read_data(self): self.logger.error("Lost websocket connection") else: self.logger.error("Websocket exception: {}".format(e)) - raise e + self._handle_exception(e) + break except Exception as e: self.logger.error("Exception in read_data: {}".format(e)) - raise e + self._handle_exception(e) + break if op_code == ABNF.OPCODE_CLOSE: self.logger.warning( @@ -97,10 +99,9 @@ def read_data(self): def close(self): if not self.ws.connected: - self.logger.warn("Websocket already closed") + self.logger.warning("Websocket already closed") else: self.ws.send_close() - return def _callback(self, callback, *args): if callback: @@ -110,3 +111,9 @@ def _callback(self, callback, *args): self.logger.error("Error from callback {}: {}".format(callback, e)) if self.on_error: self.on_error(self, e) + + def _handle_exception(self, e): + if self.on_error: + self.on_error(self, e) + else: + raise e diff --git a/binance/websocket/um_futures/websocket_client.py b/binance/websocket/um_futures/websocket_client.py index c7b4fa3..d2b5070 100644 --- a/binance/websocket/um_futures/websocket_client.py +++ b/binance/websocket/um_futures/websocket_client.py @@ -62,6 +62,22 @@ def mark_price(self, symbol: str, speed: int, id=None, action=None, **kwargs): self.send_message_to_server(stream_name, action=action, id=id) + def mark_price_all_market(self, speed=1, id=None, action=None, **kwargs): + """Mark Price Stream for All market + + Stream Name: !markPrice@arr OR !markPrice@arr@1s + + https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Mark-Price-Stream-for-All-market + + Update Speed: 3000ms or 1000ms + """ + if speed == 1: + stream_name = "!markPrice@arr@{}s".format(speed) + else: + stream_name = "!markPrice@arr" + + self.send_message_to_server(stream_name, action=action, id=id) + def kline(self, symbol: str, interval: str, id=None, action=None, **kwargs): """Kline/Candlestick Streams @@ -150,7 +166,7 @@ def mini_ticker(self, symbol=None, id=None, action=None, **kwargs): Stream Name: !miniTicker@arr https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Individual-Symbol-Mini-Ticker-Stream - https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Individual-Symbol-Ticker-Streams + https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Mini-Tickers-Stream Update Speed: 500ms for individual symbol, 1000ms for all market symbols """ diff --git a/examples/cm_futures/portfolio_margin/pm_exchange_info.py b/examples/cm_futures/market/query_index_price_constituents.py similarity index 71% rename from examples/cm_futures/portfolio_margin/pm_exchange_info.py rename to examples/cm_futures/market/query_index_price_constituents.py index 49a1052..9d54476 100644 --- a/examples/cm_futures/portfolio_margin/pm_exchange_info.py +++ b/examples/cm_futures/market/query_index_price_constituents.py @@ -6,5 +6,4 @@ config_logging(logging, logging.DEBUG) cm_futures_client = CMFutures() - -logging.info(cm_futures_client.pm_exchange_info()) +logging.info(cm_futures_client.query_index_price_constituents(symbol="BTCUSD")) diff --git a/examples/cm_futures/trade/get_download_id_transaction_history.py b/examples/cm_futures/trade/get_download_id_transaction_history.py new file mode 100644 index 0000000..b5cea42 --- /dev/null +++ b/examples/cm_futures/trade/get_download_id_transaction_history.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import logging +from binance.cm_futures import CMFutures as Client +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +client = Client(key, secret, base_url="https://dapi.binance.com") + +try: + response = client.get_download_id_transaction_history( + startTime=1641102712000, endTime=1651470712000 + ) + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/convert/accept_offered_quote.py b/examples/um_futures/convert/accept_offered_quote.py new file mode 100644 index 0000000..aea5f35 --- /dev/null +++ b/examples/um_futures/convert/accept_offered_quote.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.accept_offered_quote(quoteId="1") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/convert/list_all_convert_pairs.py b/examples/um_futures/convert/list_all_convert_pairs.py new file mode 100644 index 0000000..475f04e --- /dev/null +++ b/examples/um_futures/convert/list_all_convert_pairs.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.list_all_convert_pairs(fromAsset="BNB") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/convert/order_status.py b/examples/um_futures/convert/order_status.py new file mode 100644 index 0000000..f3f35b4 --- /dev/null +++ b/examples/um_futures/convert/order_status.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.order_status(orderId="1") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/convert/send_quote_request.py b/examples/um_futures/convert/send_quote_request.py new file mode 100644 index 0000000..2d2ed8f --- /dev/null +++ b/examples/um_futures/convert/send_quote_request.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.send_quote_request( + fromAsset="BNB", toAsset="USDT", fromAmount=0.1 + ) + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/market/funding_info.py b/examples/um_futures/market/funding_info.py new file mode 100644 index 0000000..d458329 --- /dev/null +++ b/examples/um_futures/market/funding_info.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging + +config_logging(logging, logging.DEBUG) + +um_futures_client = UMFutures() +logging.info(um_futures_client.funding_info()) diff --git a/examples/um_futures/market/index_price_constituents.py b/examples/um_futures/market/index_price_constituents.py new file mode 100644 index 0000000..60c9808 --- /dev/null +++ b/examples/um_futures/market/index_price_constituents.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging + +config_logging(logging, logging.DEBUG) + +um_futures_client = UMFutures() +logging.info(um_futures_client.index_price_constituents(symbol="BTCUSDT")) diff --git a/examples/um_futures/market/quarterly_contract_settlement_price.py b/examples/um_futures/market/quarterly_contract_settlement_price.py new file mode 100644 index 0000000..cadaf57 --- /dev/null +++ b/examples/um_futures/market/quarterly_contract_settlement_price.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging + +config_logging(logging, logging.DEBUG) + +um_futures_client = UMFutures() + +logging.info(um_futures_client.quarterly_contract_settlement_price(pair="BTCUSDT")) diff --git a/examples/um_futures/trade/async_download_order_id.py b/examples/um_futures/trade/async_download_order_id.py new file mode 100644 index 0000000..32c2a8d --- /dev/null +++ b/examples/um_futures/trade/async_download_order_id.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.async_download_order_id(downloadId="1") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/async_download_trade_id.py b/examples/um_futures/trade/async_download_trade_id.py new file mode 100644 index 0000000..dd03bd6 --- /dev/null +++ b/examples/um_futures/trade/async_download_trade_id.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.async_download_trade_id(downloadId="1") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/download_order_asyn.py b/examples/um_futures/trade/download_order_asyn.py new file mode 100644 index 0000000..ed0bee1 --- /dev/null +++ b/examples/um_futures/trade/download_order_asyn.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.download_order_asyn( + startTime=1641102712000, endTime=1651470712000 + ) + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/download_trade_asyn.py b/examples/um_futures/trade/download_trade_asyn.py new file mode 100644 index 0000000..62d4336 --- /dev/null +++ b/examples/um_futures/trade/download_trade_asyn.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.download_trade_asyn( + startTime=1641102712000, endTime=1651470712000 + ) + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/futures_account_configuration.py b/examples/um_futures/trade/futures_account_configuration.py new file mode 100644 index 0000000..f29d6de --- /dev/null +++ b/examples/um_futures/trade/futures_account_configuration.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.futures_account_configuration() + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/get_bnb_burn.py b/examples/um_futures/trade/get_bnb_burn.py new file mode 100644 index 0000000..603b159 --- /dev/null +++ b/examples/um_futures/trade/get_bnb_burn.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.get_bnb_burn() + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/query_user_rate_limit.py b/examples/um_futures/trade/query_user_rate_limit.py new file mode 100644 index 0000000..1c3e79a --- /dev/null +++ b/examples/um_futures/trade/query_user_rate_limit.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.query_user_rate_limit() + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/symbol_configuration.py b/examples/um_futures/trade/symbol_configuration.py new file mode 100644 index 0000000..18a7d66 --- /dev/null +++ b/examples/um_futures/trade/symbol_configuration.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.symbol_configuration() + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/um_futures/trade/toggle_bnb_burn.py b/examples/um_futures/trade/toggle_bnb_burn.py new file mode 100644 index 0000000..d78b0a2 --- /dev/null +++ b/examples/um_futures/trade/toggle_bnb_burn.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import logging +from binance.um_futures import UMFutures +from binance.lib.utils import config_logging +from binance.error import ClientError + +config_logging(logging, logging.DEBUG) + +key = "" +secret = "" + +um_futures_client = UMFutures(key=key, secret=secret) + +try: + response = um_futures_client.toggle_bnb_burn(feeBurn="true") + logging.info(response) +except ClientError as error: + logging.error( + "Found error. status: {}, error code: {}, error message: {}".format( + error.status_code, error.error_code, error.error_message + ) + ) diff --git a/examples/websocket/um_futures/mark_price_all_market.py b/examples/websocket/um_futures/mark_price_all_market.py new file mode 100644 index 0000000..f255bf4 --- /dev/null +++ b/examples/websocket/um_futures/mark_price_all_market.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import time +import logging +from binance.lib.utils import config_logging +from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient + +config_logging(logging, logging.DEBUG) + + +def message_handler(_, message): + print(message) + + +my_client = UMFuturesWebsocketClient(on_message=message_handler) + +my_client.mark_price_all_market( + id=13, + speed=1, +) + +time.sleep(10) + +logging.debug("closing ws connection") +my_client.stop() diff --git a/setup.py b/setup.py index 84ef279..7fa65fa 100644 --- a/setup.py +++ b/setup.py @@ -41,10 +41,10 @@ "Intended Audience :: Developers", "Intended Audience :: Financial and Insurance Industry", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], python_requires=">=3.7", )