From fb254010de4464937084a155d84f32630448c6b0 Mon Sep 17 00:00:00 2001 From: nicelgueta Date: Tue, 1 Nov 2022 00:36:31 +0000 Subject: [PATCH] 0.4.0: updated to conform to latest OKX changes --- pyokx/Account.py | 7 +++- pyokx/Blocktrading.py | 14 ++++++- pyokx/Convert.py | 4 +- pyokx/Funding.py | 4 +- pyokx/Gridtrading.py | 10 ++--- pyokx/Marketdata.py | 88 ++++++++++++++++++++++++++++++++++++++++++- pyokx/Publicdata.py | 27 +++++++++---- pyokx/Trade.py | 55 ++++++++++++++++----------- pyokx/__init__.py | 2 +- 9 files changed, 166 insertions(+), 45 deletions(-) diff --git a/pyokx/Account.py b/pyokx/Account.py index 9100c24..56d700f 100644 --- a/pyokx/Account.py +++ b/pyokx/Account.py @@ -384,6 +384,7 @@ def get_fee_rates( instType: str, instId: str = None, uly: str = None, + instFamily: str = None, use_proxy: bool = False, ) -> APIReturn: """ @@ -655,7 +656,11 @@ def get_greeks(self, ccy: str = None, use_proxy: bool = False) -> APIReturn: return self.request(details) def get_pm_limitation( - self, instType: str, uly: str, use_proxy: bool = False + self, + instType: str, + uly: str = None, + instFamily: str = None, + use_proxy: bool = False, ) -> APIReturn: """ Get PM limitation diff --git a/pyokx/Blocktrading.py b/pyokx/Blocktrading.py index 8bf5d9b..29deabc 100644 --- a/pyokx/Blocktrading.py +++ b/pyokx/Blocktrading.py @@ -33,6 +33,7 @@ def create_rfq( side: str, anonymous: bool = None, clRfqId: str = None, + allowPartialExecution: bool = None, tgtCcy: str = None, use_proxy: bool = False, ) -> APIReturn: @@ -129,7 +130,13 @@ def cancel_all_rfqs(self, use_proxy: bool = False) -> APIReturn: return self.request(details) def execute_quote( - self, rfqId: str, quoteId: str, use_proxy: bool = False + self, + rfqId: str, + quoteId: str, + instId: str, + sz: str, + legs: List[dict] = None, + use_proxy: bool = False, ) -> APIReturn: """ Execute Quote @@ -154,8 +161,9 @@ def set_quote_products( self, instType: str, data: List[dict], - uly: str = None, + instFamily: str = None, instId: str = None, + includeAll: bool = None, maxBlockSz: str = None, makerPxBand: str = None, use_proxy: bool = False, @@ -370,6 +378,8 @@ def get_trades( state: str = None, beginId: str = None, endId: str = None, + beginTs: str = None, + endTs: str = None, limit: str = None, use_proxy: bool = False, ) -> APIReturn: diff --git a/pyokx/Convert.py b/pyokx/Convert.py index 6c409d6..fc06653 100644 --- a/pyokx/Convert.py +++ b/pyokx/Convert.py @@ -56,7 +56,7 @@ def estimate_quote( ) -> APIReturn: """ Estimate quote - Rate Limit: 2 requests per second + Rate Limit: 10 requests per second Rate limit rule: UserID """ kwargs = { @@ -86,7 +86,7 @@ def convert_trade( ) -> APIReturn: """ Convert trade - Rate Limit: 2 requests per second + Rate Limit: 10 requests per second Rate limit rule: UserID """ kwargs = { diff --git a/pyokx/Funding.py b/pyokx/Funding.py index 30c4294..f2e3493 100644 --- a/pyokx/Funding.py +++ b/pyokx/Funding.py @@ -90,7 +90,7 @@ def funds_transfer( Failure of the request does not mean the transfer has failed. Recommend to call "Get funds transfer state" to confirm the status. Rate Limit: 1 request per second - Rate limit rule: UserID + Currency + Rate limit rule: UserID + Currency """ kwargs = { k: v @@ -207,6 +207,7 @@ def get_deposit_history( ccy: str = None, depId: str = None, txId: str = None, + type: str = None, state: str = None, after: str = None, before: str = None, @@ -310,6 +311,7 @@ def get_withdrawal_history( wdId: str = None, clientId: str = None, txId: str = None, + type: str = None, state: str = None, after: str = None, before: str = None, diff --git a/pyokx/Gridtrading.py b/pyokx/Gridtrading.py index 07ab9a6..e624e46 100644 --- a/pyokx/Gridtrading.py +++ b/pyokx/Gridtrading.py @@ -19,8 +19,8 @@ def place_grid_algo_order( """ Place grid algo order Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -47,7 +47,7 @@ def amend_grid_algo_order( Amend grid algo order Supported contract grid algo order amendment. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) + Derivatives rate limit rule: UserID + (instrumentType + underlying) """ kwargs = { k: v @@ -74,8 +74,8 @@ def stop_grid_algo_order( Stop grid algo order A maximum of 10 orders can be canceled per request. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v diff --git a/pyokx/Marketdata.py b/pyokx/Marketdata.py index 6288848..22c7691 100644 --- a/pyokx/Marketdata.py +++ b/pyokx/Marketdata.py @@ -4,7 +4,11 @@ class Marketdata(APIComponent): def get_tickers( - self, instType: str, uly: str = None, use_proxy: bool = False + self, + instType: str, + uly: str = None, + instFamily: str = None, + use_proxy: bool = False, ) -> APIReturn: """ Get tickers @@ -89,6 +93,26 @@ def get_order_book( ) return self.request(details) + def get_order_lite_book(self, instId: str, use_proxy: bool = False) -> APIReturn: + """ + Get order lite book + Retrieve order top 25 book of the instrument more quickly + Rate Limit: 6 requests per 1 seconds + Rate limit rule: IP + """ + kwargs = { + k: v + for k, v in locals().items() + if k not in ["use_proxy", "self"] and v is not None + } + details = EndpointDetails( + request_path="/api/v5/market/books-lite", + method="GET", + params=kwargs, + use_proxy=use_proxy, + ) + return self.request(details) + def get_candlesticks( self, instId: str, @@ -173,6 +197,34 @@ def get_index_candlesticks( ) return self.request(details) + def get_index_candlesticks_history( + self, + instId: str, + after: str = None, + before: str = None, + bar: str = None, + limit: str = None, + use_proxy: bool = False, + ) -> APIReturn: + """ + Get index candlesticks history + Retrieve the candlestick charts of the index from recent years. + Rate Limit: 10 requests per 2 seconds + Rate limit rule: IP + """ + kwargs = { + k: v + for k, v in locals().items() + if k not in ["use_proxy", "self"] and v is not None + } + details = EndpointDetails( + request_path="/api/v5/market/history-index-candles", + method="GET", + params=kwargs, + use_proxy=use_proxy, + ) + return self.request(details) + def get_mark_price_candlesticks( self, instId: str, @@ -201,6 +253,34 @@ def get_mark_price_candlesticks( ) return self.request(details) + def get_mark_price_candlesticks_history( + self, + instId: str, + after: str = None, + before: str = None, + bar: str = None, + limit: str = None, + use_proxy: bool = False, + ) -> APIReturn: + """ + Get mark price candlesticks history + Retrieve the candlestick charts of mark price from recent years. + Rate Limit: 10 requests per 2 seconds + Rate limit rule: IP + """ + kwargs = { + k: v + for k, v in locals().items() + if k not in ["use_proxy", "self"] and v is not None + } + details = EndpointDetails( + request_path="/api/v5/market/history-mark-price-candles", + method="GET", + params=kwargs, + use_proxy=use_proxy, + ) + return self.request(details) + def get_trades( self, instId: str, limit: str = None, use_proxy: bool = False ) -> APIReturn: @@ -332,7 +412,11 @@ def get_index_components(self, index: str, use_proxy: bool = False) -> APIReturn return self.request(details) def get_block_tickers( - self, instType: str, uly: str = None, use_proxy: bool = False + self, + instType: str, + uly: str = None, + instFamily: str = None, + use_proxy: bool = False, ) -> APIReturn: """ Get block tickers diff --git a/pyokx/Publicdata.py b/pyokx/Publicdata.py index cdba53f..3292149 100644 --- a/pyokx/Publicdata.py +++ b/pyokx/Publicdata.py @@ -7,6 +7,7 @@ def get_instruments( self, instType: str, uly: str = None, + instFamily: str = None, instId: str = None, use_proxy: bool = False, ) -> APIReturn: @@ -14,7 +15,7 @@ def get_instruments( Get instruments Retrieve a list of instruments with open contracts. Rate Limit: 20 requests per 2 seconds - Rate limit rule: IP +instrumentType + Rate limit rule: IP + instrumentType """ kwargs = { k: v @@ -32,7 +33,8 @@ def get_instruments( def get_delivery_exercise_history( self, instType: str, - uly: str, + uly: str = None, + instFamily: str = None, after: str = None, before: str = None, limit: str = None, @@ -40,9 +42,9 @@ def get_delivery_exercise_history( ) -> APIReturn: """ Get delivery/exercise history - Retrieve the estimated delivery price of the last 3 months, which will only have a return value one hour before the delivery/exercise. + Retrieve delivery records of Futures and exercise records of Options in the last 3 months. Rate Limit: 40 requests per 2 seconds - Rate limit rule: IP +(instrumentType、uly) + Rate limit rule: IP + (instrumentType + uly) """ kwargs = { k: v @@ -61,6 +63,7 @@ def get_open_interest( self, instType: str, uly: str = None, + instFamily: str = None, instId: str = None, use_proxy: bool = False, ) -> APIReturn: @@ -151,7 +154,11 @@ def get_limit_price(self, instId: str, use_proxy: bool = False) -> APIReturn: return self.request(details) def get_option_market_data( - self, uly: str, expTime: str = None, use_proxy: bool = False + self, + uly: str = None, + instFamily: str = None, + expTime: str = None, + use_proxy: bool = False, ) -> APIReturn: """ Get option market data @@ -240,6 +247,7 @@ def get_liquidation_orders( self, instType: str, uly: str = None, + instFamily: str = None, alias: str = None, mgnMode: str = None, instId: str = None, @@ -273,6 +281,7 @@ def get_mark_price( self, instType: str, uly: str = None, + instFamily: str = None, instId: str = None, use_proxy: bool = False, ) -> APIReturn: @@ -301,6 +310,7 @@ def get_position_tiers( instType: str, tdMode: str, uly: str = None, + instFamily: str = None, instId: str = None, ccy: str = None, tier: str = None, @@ -308,7 +318,7 @@ def get_position_tiers( ) -> APIReturn: """ Get position tiers - Retrieve position tiers information, maximum leverage depends on your borrowings and margin ratio. + Retrieve position tiers information, maximum leverage depends on your borrowings and margin ratio. Rate Limit: 10 requests per 2 seconds Rate limit rule: IP """ @@ -388,9 +398,10 @@ def get_underlying(self, instType: str, use_proxy: bool = False) -> APIReturn: def get_insurance_fund( self, instType: str, - type: str = None, uly: str = None, + instFamily: str = None, ccy: str = None, + type: str = None, before: str = None, after: str = None, limit: str = None, @@ -426,7 +437,7 @@ def unit_convert( ) -> APIReturn: """ Unit convert - Convert currency to contract, or contract to currency. + Convert the crypto value to the number of contracts, or vice versa Rate Limit: 10 requests per 2 seconds Rate limit rule: IP """ diff --git a/pyokx/Trade.py b/pyokx/Trade.py index 46016fa..fe436bf 100644 --- a/pyokx/Trade.py +++ b/pyokx/Trade.py @@ -24,8 +24,8 @@ def place_order( Place order You can place an order only if you have sufficient funds. Rate Limit: 60 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -61,8 +61,8 @@ def place_multiple_orders( Place multiple orders Place orders in batches. Maximum 20 orders can be placed per request. Request parameters should be passed in the form of an array. Rate Limit: 300 orders per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) Unlike other endpoints, the rate limit of this endpoint is determined by the number of orders. If there is only one order in the request, it will consume the rate limit of `Place order`. @@ -91,8 +91,8 @@ def cancel_order( Cancel order Cancel an incomplete order. Rate Limit: 60 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -118,8 +118,8 @@ def cancel_multiple_orders( Cancel multiple orders Cancel incomplete orders in batches. Maximum 20 orders can be canceled per request. Request parameters should be passed in the form of an array. Rate Limit: 300 orders per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) Unlike other endpoints, the rate limit of this endpoint is determined by the number of orders. If there is only one order in the request, it will consume the rate limit of `Cancel order`. @@ -152,8 +152,8 @@ def amend_order( Amend order Amend an incomplete order. Rate Limit: 60 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -183,8 +183,8 @@ def amend_multiple_orders( Amend multiple orders Amend incomplete orders in batches. Maximum 20 orders can be amended per request. Request parameters should be passed in the form of an array. Rate Limit: 300 orders per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) Unlike other endpoints, the rate limit of this endpoint is determined by the number of orders. If there is only one order in the request, it will consume the rate limit of `Amend order`. @@ -217,8 +217,8 @@ def close_positions( Close positions Close all positions of an instrument via a market order. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -244,8 +244,8 @@ def get_order_details( Get order details Retrieve order details. Rate Limit: 60 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -264,6 +264,7 @@ def get_order_list( self, instType: str = None, uly: str = None, + instFamily: str = None, instId: str = None, ordType: str = None, state: str = None, @@ -295,18 +296,21 @@ def get_order_history_last_7_days( self, instType: str = None, uly: str = None, + instFamily: str = None, instId: str = None, ordType: str = None, state: str = None, category: str = None, after: str = None, before: str = None, + begin: str = None, + end: str = None, limit: str = None, use_proxy: bool = False, ) -> APIReturn: """ Get order history (last 7 days) - Retrieve the completed order data for the last 7 days, and the incomplete orders that have been cancelled are only reserved for 2 hours. + Retrieve the completed order data for the last 7 days, and the incomplete orders that have been canceled are only reserved for 2 hours. Rate Limit: 40 requests per 2 seconds Rate limit rule: UserID """ @@ -327,12 +331,15 @@ def get_order_history_last_3_months( self, instType: str = None, uly: str = None, + instFamily: str = None, instId: str = None, ordType: str = None, state: str = None, category: str = None, after: str = None, before: str = None, + begin: str = None, + end: str = None, limit: str = None, use_proxy: bool = False, ) -> APIReturn: @@ -359,6 +366,7 @@ def get_transaction_details_last_3_days( self, instType: str = None, uly: str = None, + instFamily: str = None, instId: str = None, ordId: str = None, after: str = None, @@ -391,6 +399,7 @@ def get_transaction_details_last_3_months( self, instType: str = None, uly: str = None, + instFamily: str = None, instId: str = None, ordId: str = None, after: str = None, @@ -438,8 +447,8 @@ def place_algo_order( Place algo order The algo order includes trigger order, oco order, conditional order,iceberg order, twap order and trailing order. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -461,8 +470,8 @@ def cancel_algo_order( Cancel algo order Cancel unfilled algo orders (not including Iceberg order, TWAP order, Trailing Stop order). A maximum of 10 orders can be canceled per request. Request parameters should be passed in the form of an array. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v @@ -484,8 +493,8 @@ def cancel_advance_algo_order( Cancel advance algo order Cancel unfilled algo orders (including Iceberg order, TWAP order, Trailing Stop order). A maximum of 10 orders can be canceled per request. Request parameters should be passed in the form of an array. Rate Limit: 20 requests per 2 seconds - Derivatives rate limit rule: UserID +(instrumentType、underlying) - Spot & Margin rate limit rule: UserID +(instrumentType、instrumentID) + Derivatives rate limit rule: UserID + (instrumentType + underlying) + Spot & Margin rate limit rule: UserID + (instrumentType + instrumentID) """ kwargs = { k: v diff --git a/pyokx/__init__.py b/pyokx/__init__.py index 04369a6..3a70a65 100644 --- a/pyokx/__init__.py +++ b/pyokx/__init__.py @@ -15,7 +15,7 @@ from .base import OKXClient -__version__ = "0.3.1" +__version__ = "0.4.0" def change_log_level(level: str = "INFO"):