### Install Gate.io API Python Client via Setuptools Source: https://github.com/gateio/gateapi-python/blob/master/README.md Install the package using Setuptools. This can be done for the current user or system-wide. ```sh python setup.py install --user ``` ```sh sudo python setup.py install ``` -------------------------------- ### Install Gate.io API Python Client via Pip Source: https://github.com/gateio/gateapi-python/blob/master/README.md Install the package directly using pip. Ensure you have Python 2.7 or 3.4+ installed. ```sh pip install --user gate-api ``` -------------------------------- ### Query Current Market Leverage Lending Tiers (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/MarginApi.md Fetch the current market leverage lending tiers for a given currency pair. This example demonstrates basic API client setup. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) ``` -------------------------------- ### UnifiedApi: get_user_leverage_currency_setting Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get user currency leverage. ```APIDOC ## GET /unified/leverage/user_currency_setting ### Description Get user currency leverage. ### Method GET ### Endpoint /unified/leverage/user_currency_setting ``` -------------------------------- ### Import Gate.io API Python Client Source: https://github.com/gateio/gateapi-python/blob/master/README.md Import the necessary gate_api package after installation. ```python import gate_api ``` -------------------------------- ### Get Single Currency Information - Python Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Retrieves detailed information for a specific currency using its name. This example demonstrates how to call the API and handle potential GateApiException or general ApiException. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.SpotApi(api_client) currency = 'GT' # str | Currency name try: # Query single currency information api_response = api_instance.get_currency(currency) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SpotApi->get_currency: %s\n" % e) ``` -------------------------------- ### Run Spot Demo Source: https://github.com/gateio/gateapi-python/blob/master/example/README.md Execute the spot trading demo against the live Gate.io environment. Requires your actual API key and secret. ```bash python app.py spot -k -s ``` -------------------------------- ### Basic Gate.io API Usage Example Source: https://github.com/gateio/gateapi-python/blob/master/README.md Demonstrates how to initialize the API client, create an instance of a specific API class (EarnUniApi), and make a call to query lending currency list. Includes basic exception handling for API-specific errors and general API exceptions. The host defaults to https://api.gateio.ws/api/v4 if not specified. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnUniApi(api_client) try: # Query lending currency list api_response = api_instance.list_uni_currencies() print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnUniApi->list_uni_currencies: %s\n" % e) ``` -------------------------------- ### Get UniLoan Annualized Trend Chart (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/EarnUniApi.md Retrieve the annualized trend chart for a UniLoan currency. Requires start and end timestamps and the currency asset. Ensure API keys are correctly configured. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnUniApi(api_client) _from = 1719763200 # int | Start timestamp in seconds, maximum span 30 days to = 1722441600 # int | End timestamp in seconds, maximum span 30 days asset = 'BTC' # str | Currency name try: # UniLoan currency annualized trend chart api_response = api_instance.list_uni_chart(_from, to, asset) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnUniApi->list_uni_chart: %s\n" % e) ``` -------------------------------- ### Run Margin Demo Source: https://github.com/gateio/gateapi-python/blob/master/example/README.md Execute the margin trading demo against the live Gate.io environment. Requires your actual API key and secret. ```bash python app.py margin -k -s ``` -------------------------------- ### List Supported Collateral Currencies (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/CollateralLoanApi.md Provides an example of how to query the supported borrowing and collateral currencies. This snippet initializes the API client with a host configuration. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) ``` -------------------------------- ### Get Margin Transferable Source: https://github.com/gateio/gateapi-python/blob/master/docs/MarginApi.md Gets the maximum transferable amount for isolated margin. ```APIDOC ## GET /margin/transferable ### Description Gets the maximum transferable amount for isolated margin. ### Method GET ### Endpoint /margin/transferable ### Parameters #### Query Parameters - **currency_pair** (str) - Required - Currency pair ### Response #### Success Response (200) - **MarginTransferable** - Maximum transferable amount ``` -------------------------------- ### Batch Place Orders with API Key Authentication Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Demonstrates how to place multiple orders simultaneously using API key authentication. Ensure your API key and secret are correctly configured. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.SpotApi(api_client) order = [gate_api.Order()] # Specify the expiration time (milliseconds); if the GATE receives the request time greater than the expiration time, the request will be rejected (optional) x_gate_exptime = '1689560679123' # str | try: # Batch place orders api_response = api_instance.create_batch_orders(order, x_gate_exptime=x_gate_exptime) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SpotApi->create_batch_orders: %s\n" % e) ``` -------------------------------- ### MarginApi - Get Maximum Transferable Amount for Isolated Margin Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get the maximum transferable amount for isolated margin. ```APIDOC ## GET /margin/transferable ### Description Get maximum transferable amount for isolated margin ### Method GET ### Endpoint /margin/transferable ``` -------------------------------- ### Authenticate and Query User LTV Info (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/CollateralLoanApi.md Shows how to set up APIv4 key authentication and retrieve the user's collateralization ratio and remaining borrowable currencies for specified collateral and borrow currencies. Remember to replace placeholder API keys. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.CollateralLoanApi(api_client) collateral_currency = 'BTC' # str | Collateral currency borrow_currency = 'USDT' # str | Borrowed currency try: # Query user's collateralization ratio and remaining borrowable currencies api_response = api_instance.get_user_ltv_info(collateral_currency, borrow_currency) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling CollateralLoanApi->get_user_ltv_info: %s\n" % e) ``` -------------------------------- ### MarginUniApi - Get Uni Currency Pair Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get detailed information about a specific UniFi margin lending market. ```APIDOC ## GET /margin/uni/currency_pairs/{currency_pair} ### Description Get lending market details ### Method GET ### Endpoint /margin/uni/currency_pairs/{currency_pair} #### Path Parameters - **currency_pair** (string) - Required - The currency pair to get details for. ``` -------------------------------- ### Configure and Place Dual Investment Order Source: https://github.com/gateio/gateapi-python/blob/master/docs/EarnApi.md Demonstrates how to configure API credentials, instantiate the Earn API client, and place a dual investment order. Ensure you replace 'YOU_API_KEY' and 'YOUR_API_SECRET' with your actual credentials. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnApi(api_client) place_dual_investment_order = gate_api.PlaceDualInvestmentOrder() # PlaceDualInvestmentOrder | try: # Place Dual Investment order api_instance.place_dual_order(place_dual_investment_order) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnApi->place_dual_order: %s\n" % e) ``` -------------------------------- ### Get Lending Market Details - Python Source: https://github.com/gateio/gateapi-python/blob/master/docs/MarginUniApi.md Retrieves detailed information for a specific unified lending market currency pair. Use this to get specific data about a trading pair. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.MarginUniApi(api_client) currency_pair = 'AE_USDT' # str | Currency pair try: # Get lending market details api_response = api_instance.get_uni_currency_pair(currency_pair) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling MarginUniApi->get_uni_currency_pair: %s\n" % e) ``` -------------------------------- ### List Orders using Spot API Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Demonstrates how to list orders using the Spot API. It includes parameters for currency pair, status, pagination, and time range. Error handling for API exceptions is also shown. ```python from gate_api.exceptions import ApiException, GateApiException # Create an instance of the API class api_instance = gate_api.SpotApi(api_client) currency_pair = 'BTC_USDT' # str | Query by specified currency pair. Required for open orders, optional for filled orders status = 'open' # str | List orders based on status `open` - order is waiting to be filled `finished` - order has been filled or cancelled page = 1 # int | Page number (optional) (default to 1) limit = 100 # int | Maximum number of records to be returned. If `status` is `open`, maximum of `limit` is 100 (optional) (default to 100) account = 'spot' # str | Specify query account (optional) _from = 1627706330 # int | Start timestamp for the query (optional) to = 1635329650 # int | End timestamp for the query, defaults to current time if not specified (optional) side = 'sell' # str | Specify all bids or all asks, both included if not specified (optional) try: # List orders api_response = api_instance.list_orders(currency_pair, status, page=page, limit=limit, account=account, _from=_from, to=to, side=side) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SpotApi->list_orders: %s\n" % e) ``` -------------------------------- ### Set User Market Leverage - Python Source: https://github.com/gateio/gateapi-python/blob/master/docs/MarginApi.md This example demonstrates how to set the user's market leverage multiplier. It requires API key authentication and the creation of a MarginMarketLeverage object. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.MarginApi(api_client) margin_market_leverage = gate_api.MarginMarketLeverage() # MarginMarketLeverage | try: # Set user market leverage multiplier api_instance.set_user_market_leverage(margin_market_leverage) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling MarginApi->set_user_market_leverage: %s\n" % e) ``` -------------------------------- ### Get My Trades Source: https://github.com/gateio/gateapi-python/blob/master/docs/FuturesApi.md Query your personal futures trading records. By default, this endpoint retrieves data from the past 6 months. For longer historical data, use the `GET /futures/{settle}/my_trades_timerange` endpoint. ```APIDOC ## get_my_trades ### Description Query personal trading records ### Method GET ### Endpoint /futures/{settle}/my_trades ### Parameters #### Path Parameters - **settle** (str) - Required - Settle currency #### Query Parameters - **contract** (str) - Optional - Query orders by contract - **order** (str) - Optional - Query orders by order ID - **limit** (int) - Optional - Maximum number of records to return (default: 100) - **offset** (int) - Optional - Offset record number (default: 0) - **last_id** (str) - Optional - Retrieve records after the specified ID ### Response #### Success Response (200) - **list[MyFuturesTrade]** - A list of personal futures trade records. #### Response Example (Response structure depends on the MyFuturesTrade model definition, not provided in source) ``` -------------------------------- ### get_system_time Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Get server current time. ```APIDOC ## get_system_time ### Description Get server current time. ### Method GET ### Endpoint /system/time ### Response #### Success Response (200) - **SystemTime** - Server current time ### Request Example ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # The following lines are commented out because they are not part of the example's core functionality # api_instance = gate_api.SpotApi(api_client) # try: # api_response = api_instance.get_system_time() # print(api_response) # except GateApiException as ex: # print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) # except ApiException as e: # print("Exception when calling SpotApi->get_system_time: %s\n" % e) ``` ``` -------------------------------- ### Create Uni Loan (Borrow or Repay) Source: https://github.com/gateio/gateapi-python/blob/master/docs/MarginUniApi.md This snippet demonstrates how to initiate a borrow or repay operation using the `create_uni_loan` method. Proper API key authentication is required. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. ``` -------------------------------- ### list_order_book Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Get market depth information. ```APIDOC ## GET /spot/order_book ### Description Get market depth information. ### Method GET ### Endpoint /spot/order_book ### Parameters #### Query Parameters - **currency_pair** (string) - Required - Query currency pair - **limit** (int) - Optional - Maximum number of records to return - **with_id** (bool) - Optional - Return order book with sequence ID, default is false ``` -------------------------------- ### list_tickers Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Get currency pair ticker information. ```APIDOC ## GET /spot/tickers ### Description Get currency pair ticker information. ### Method GET ### Endpoint /spot/tickers ### Parameters #### Query Parameters - **currency_pair** (string) - Optional - Filter by currency pair ``` -------------------------------- ### Authenticate and Query User Total Borrowing and Collateral Amount (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/CollateralLoanApi.md Demonstrates how to configure APIv4 key authorization and query the user's total borrowing and collateral amount. Ensure you replace 'YOU_API_KEY' and 'YOUR_API_SECRET' with your actual credentials. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.CollateralLoanApi(api_client) try: # Query user's total borrowing and collateral amount api_response = api_instance.get_user_total_amount() print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling CollateralLoanApi->get_user_total_amount: %s\n" % e) ``` -------------------------------- ### Get Position Source: https://github.com/gateio/gateapi-python/blob/master/README.md Retrieves information for a single position. ```APIDOC ## GET /futures/{settle}/positions/{contract} ### Description Retrieves information for a single position. ### Method GET ### Endpoint /futures/{settle}/positions/{contract} ``` -------------------------------- ### Query Lending Currency List Source: https://github.com/gateio/gateapi-python/blob/master/README.md This example demonstrates how to query the list of lending currencies supported by Gate.io using the EarnUniApi. ```APIDOC ## Query lending currency list ### Description Queries the list of lending currencies supported by Gate.io. ### Method `list_uni_currencies()` ### Parameters None ### Request Example ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) api_instance = gate_api.EarnUniApi(api_client) try: api_response = api_instance.list_uni_currencies() print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnUniApi->list_uni_currencies: %s\n" % e) ``` ### Response #### Success Response (200) - **response** (list) - A list of lending currency objects. #### Response Example ```json [ { "currency": "USDT", "lending_enabled": true, "min_lending_amount": "10", "max_lending_amount": "1000000", "interest_rate": "0.05", "daily_borrow": "0.0001", "borrow_rate": "0.0003" } ] ``` ``` -------------------------------- ### Calculate Portfolio Margin Source: https://github.com/gateio/gateapi-python/blob/master/docs/UnifiedApi.md This example shows how to use the portfolio margin calculator. It requires a UnifiedPortfolioInput object and handles potential API exceptions. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.UnifiedApi(api_client) unified_portfolio_input = gate_api.UnifiedPortfolioInput() # UnifiedPortfolioInput | try: # Portfolio margin calculator api_response = api_instance.calculate_portfolio_margin(unified_portfolio_input) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling UnifiedApi->calculate_portfolio_margin: %s\n" % e) ``` -------------------------------- ### UnifiedApi: get_history_loan_rate Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get historical lending rates. ```APIDOC ## GET /unified/history_loan_rate ### Description Get historical lending rates. ### Method GET ### Endpoint /unified/history_loan_rate ``` -------------------------------- ### Run Futures Demo on Real Trading Source: https://github.com/gateio/gateapi-python/blob/master/example/README.md Execute the futures demo against the live Gate.io trading environment. Requires your actual API key and secret. ```bash python app.py futures -k -s ``` -------------------------------- ### Query Loan Records with Unified API Source: https://github.com/gateio/gateapi-python/blob/master/docs/UnifiedApi.md This example demonstrates how to query loan records using the Unified API. You can filter by type, currency, and pagination parameters. APIv4 key authentication is used. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.UnifiedApi(api_client) type = 'type_example' # str | Loan record type: borrow - borrowing, repay - repayment (optional) currency = 'BTC' # str | Query by specified currency name (optional) page = 1 # int | Page number (optional) (default to 1) limit = 100 # int | Maximum number of items returned. Default: 100, minimum: 1, maximum: 100 (optional) (default to 100) try: # Query loan records api_response = api_instance.list_unified_loan_records(type=type, currency=currency, page=page, limit=limit) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling UnifiedApi->list_unified_loan_records: %s\n" % e) ``` -------------------------------- ### Get position Source: https://github.com/gateio/gateapi-python/blob/master/docs/FuturesApi.md Retrieves information for a single futures position. ```APIDOC ## GET /futures/{settle}/positions/{contract} ### Description Get single position information ### Method GET ### Endpoint /futures/{settle}/positions/{contract} ``` -------------------------------- ### Get Currency Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Retrieves detailed information for a specific currency. ```APIDOC ## get_currency ### Description Query single currency information. ### Method GET ### Endpoint /spot/currency ### Parameters #### Query Parameters - **currency** (str) - Required - Currency name ### Return type [**Currency**](Currency.md) ### Authorization No authorization required ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ### HTTP response details | Status code | Description | |-------------|-------------| **200** | Query successful | ``` -------------------------------- ### Place Collateral Loan Order with APIv4 Authentication Source: https://github.com/gateio/gateapi-python/blob/master/docs/CollateralLoanApi.md Demonstrates how to place a collateral loan order using APIv4 key authentication. Ensure your API key and secret are correctly configured. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.CollateralLoanApi(api_client) create_collateral_order = gate_api.CreateCollateralOrder() # CreateCollateralOrder | try: # Place collateral loan order api_response = api_instance.create_collateral_loan(create_collateral_order) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling CollateralLoanApi->create_collateral_loan: %s\n" % e) ``` -------------------------------- ### Create Sub-Account with APIv4 Key Authorization Source: https://github.com/gateio/gateapi-python/blob/master/docs/SubAccountApi.md Demonstrates how to create a new sub-account using APIv4 key authorization. Ensure your API key and secret are correctly configured. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.SubAccountApi(api_client) sub_account = gate_api.SubAccount() # SubAccount | try: # Create a new sub-account api_response = api_instance.create_sub_accounts(sub_account) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SubAccountApi->create_sub_accounts: %s\n" % e) ``` -------------------------------- ### List Push Orders Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get UID transfer history. ```APIDOC ## GET /wallet/push ### Description Get UID transfer history. ### Method GET ### Endpoint /wallet/push ``` -------------------------------- ### Initialize Gate.io API Client Source: https://github.com/gateio/gateapi-python/blob/master/docs/UnifiedApi.md Configure and initialize the Gate.io API client using your API key and secret for authentication. This setup is required before making any API calls. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) ``` -------------------------------- ### Get Total Balance Source: https://github.com/gateio/gateapi-python/blob/master/README.md Query personal account totals. ```APIDOC ## GET /wallet/total_balance ### Description Query personal account totals. ### Method GET ### Endpoint /wallet/total_balance ``` -------------------------------- ### Get Trade Fee Source: https://github.com/gateio/gateapi-python/blob/master/README.md Query personal trading fees. ```APIDOC ## GET /wallet/fee ### Description Query personal trading fees. ### Method GET ### Endpoint /wallet/fee ``` -------------------------------- ### Set Unified Collateral with Python Source: https://github.com/gateio/gateapi-python/blob/master/docs/UnifiedApi.md Configure collateral currency for the unified account. Requires API Key authentication. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters ``` -------------------------------- ### Get Index Constituents Source: https://github.com/gateio/gateapi-python/blob/master/README.md Queries the constituents of a specific index. ```APIDOC ## GET /futures/{settle}/index_constituents/{index} ### Description Queries the constituents of a specific index. ### Method GET ### Endpoint /futures/{settle}/index_constituents/{index} ``` -------------------------------- ### Create Spot Order with API Key Authentication Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Use this snippet to create a spot order using API key authentication. Ensure your API key and secret are configured correctly. The `x_gate_exptime` parameter is optional and specifies the request expiration time in milliseconds. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.SpotApi(api_client) order = gate_api.Order() # Order | x_gate_exptime = '1689560679123' # str | Specify the expiration time (milliseconds); if the GATE receives the request time greater than the expiration time, the request will be rejected (optional) try: # Create an order api_response = api_instance.create_order(order, x_gate_exptime=x_gate_exptime) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SpotApi->create_order: %s\n" % e) ``` -------------------------------- ### Create Uni Lend or Redemption (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/EarnUniApi.md This snippet demonstrates how to create a unified lending or redemption request. Note the specific conditions for lending and redemption, including settlement periods. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnUniApi(api_client) create_uni_lend = gate_api.CreateUniLend() # CreateUniLend | try: # Create lending or redemption api_instance.create_uni_lend(create_uni_lend) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnUniApi->create_uni_lend: %s\n" % e) ``` -------------------------------- ### UnifiedApi: get_unified_risk_units Source: https://github.com/gateio/gateapi-python/blob/master/README.md Get user risk unit details. ```APIDOC ## GET /unified/risk_units ### Description Get user risk unit details. ### Method GET ### Endpoint /unified/risk_units ``` -------------------------------- ### Place Structured Order (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/EarnApi.md Places a structured product order. Requires API key authentication and a StructuredBuy object. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure APIv4 key authorization configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnApi(api_client) structured_buy = gate_api.StructuredBuy() # StructuredBuy | try: # Place Structured Product Order api_instance.place_structured_order(structured_buy) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnApi->place_structured_order: %s\n" % e) ``` -------------------------------- ### Get index constituents Source: https://github.com/gateio/gateapi-python/blob/master/docs/FuturesApi.md Retrieves the constituents of a specified futures index. ```APIDOC ## GET /futures/{settle}/index_constituents/{index} ### Description Query index constituents ### Method GET ### Endpoint /futures/{settle}/index_constituents/{index} ``` -------------------------------- ### list_delivery_positions Source: https://github.com/gateio/gateapi-python/blob/master/docs/DeliveryApi.md Get user position list for a given settle currency. ```APIDOC ## list_delivery_positions ### Description Get user position list. ### Method GET ### Endpoint /delivery/positions ### Parameters #### Query Parameters - **settle** (str) - Required - Settle currency ### Return type [list[Position]](Position.md) ### Request Example ```python api_instance.list_delivery_positions(settle) ``` ### Response #### Success Response (200) - **list[Position]** - User position list retrieved successfully ``` -------------------------------- ### List All Currencies - Python Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Fetches a list of all supported currencies from the Gate.io Spot API. Includes error handling for API-specific and general exceptions. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.SpotApi(api_client) try: # Query all currency information api_response = api_instance.list_currencies() print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling SpotApi->list_currencies: %s\n" % e) ``` -------------------------------- ### Get Delivery Contract Source: https://github.com/gateio/gateapi-python/blob/master/docs/DeliveryApi.md Queries information for a single delivery contract. ```APIDOC ## get_delivery_contract ### Description Query single contract information ### Method GET ### Endpoint /delivery/{settle}/contracts/{contract} ### Parameters #### Path Parameters - **settle** (str) - Required - Settle currency - **contract** (str) - Required - Futures contract ### Request Example ```python api_instance.get_delivery_contract(settle='usdt', contract='BTC_USDT_20200814') ``` ### Response #### Success Response (200) - **DeliveryContract** - Contract information ``` -------------------------------- ### List Dual Investment Plans (Python) Source: https://github.com/gateio/gateapi-python/blob/master/docs/EarnApi.md Retrieves a list of Dual Investment products. Requires an API client instance. Handles potential API exceptions. ```python from __future__ import print_function import gate_api from gate_api.exceptions import ApiException, GateApiException # Defining the host is optional and defaults to https://api.gateio.ws/api/v4 # See configuration.py for a list of all supported configuration parameters. configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.EarnApi(api_client) plan_id = 1 # int | Financial project ID (optional) try: # Dual Investment product list api_response = api_instance.list_dual_investment_plans(plan_id=plan_id) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling EarnApi->list_dual_investment_plans: %s\n" % e) ``` -------------------------------- ### Get futures account Source: https://github.com/gateio/gateapi-python/blob/master/docs/DeliveryApi.md Retrieve the futures account balance and details. ```APIDOC ## GET /delivery/{settle}/accounts ### Description Get futures account. ### Method GET ### Endpoint /delivery/{settle}/accounts ### Parameters #### Path Parameters - **settle** (string) - Required - The settlement currency of the contracts. ``` -------------------------------- ### Batch Place Orders Source: https://github.com/gateio/gateapi-python/blob/master/docs/SpotApi.md Allows for the placement of multiple orders in a single request. It's crucial to ensure the `x_gate_exptime` is set correctly to avoid request rejection. ```APIDOC ## POST /spot/orders ### Description Batch place orders. Supports placing multiple orders at the same time. ### Method POST ### Endpoint /spot/orders ### Parameters #### Query Parameters - **x_gate_exptime** (str) - Optional - Specify the expiration time (milliseconds); if the GATE receives the request time greater than the expiration time, the request will be rejected #### Request Body - **order** (list[Order]) - Required - List of orders to be placed. ### Request Example ```python [ { "text": "buy 10 BTC 1000 USDT", "param": { "symbol": "BTC_USDT", "side": "buy", "type": "limit", "price": "1000", "amount": "10", "account": "spot" } } ] ``` ### Response #### Success Response (200) - **list[BatchOrder]** - Details of the placed orders. #### Response Example ```json [ { "id": "12345", "create_time": "1678886400", "update_time": "1678886400", "amount": "10", "left": "10", "price": "1000", "average_price": "0", "market": "BTC_USDT", "status": "open", "type": "limit", "account": "spot" } ] ``` ``` -------------------------------- ### Get Options Order Source: https://github.com/gateio/gateapi-python/blob/master/docs/OptionsApi.md Queries details for a single options order. ```APIDOC ## GET /options/orders/{order_id} ### Description Query single order details. ### Method GET ### Endpoint /options/orders/{order_id} ### Parameters #### Path Parameters - **order_id** (integer) - Required - Order ID ``` -------------------------------- ### Get Options Contract Source: https://github.com/gateio/gateapi-python/blob/master/docs/OptionsApi.md Queries details for a specified options contract. ```APIDOC ## GET /options/contracts/{contract} ### Description Query specified contract details. ### Method GET ### Endpoint /options/contracts/{contract} ### Parameters #### Path Parameters - **contract** (string) - Required - Options contract name ``` -------------------------------- ### Configure APIv4 Key Authorization and Query Auto-Deleverages Source: https://github.com/gateio/gateapi-python/blob/master/docs/FuturesApi.md Demonstrates how to configure APIv4 key authorization and then query auto-deleveraging order information using the Futures API. Ensure you replace 'YOU_API_KEY' and 'YOUR_API_SECRET' with your actual credentials. ```python configuration = gate_api.Configuration( host = "https://api.gateio.ws/api/v4", key = "YOU_API_KEY", secret = "YOUR_API_SECRET" ) api_client = gate_api.ApiClient(configuration) # Create an instance of the API class api_instance = gate_api.FuturesApi(api_client) settle = 'usdt' # str | Settle currency contract = 'BTC_USDT' # str | Futures contract, return related data only if specified (optional) limit = 100 # int | Maximum number of records returned in a single list (optional) (default to 100) offset = 0 # int | List offset, starting from 0 (optional) (default to 0) _from = 1547706332 # int | Start timestamp Specify start time, time format is Unix timestamp. If not specified, it defaults to (the data start time of the time range actually returned by to and limit) (optional) to = 1547706332 # int | Termination Timestamp Specify the end time. If not specified, it defaults to the current time, and the time format is a Unix timestamp (optional) at = 0 # int | Specify auto-deleveraging timestamp (optional) (default to 0) try: # Query ADL auto-deleveraging order information api_response = api_instance.list_auto_deleverages(settle, contract=contract, limit=limit, offset=offset, _from=_from, to=to, at=at) print(api_response) except GateApiException as ex: print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message)) except ApiException as e: print("Exception when calling FuturesApi->list_auto_deleverages: %s\n" % e) ``` -------------------------------- ### SpotApi - Get System Time Source: https://github.com/gateio/gateapi-python/blob/master/README.md Fetches the current server time. ```APIDOC ## GET /spot/time ### Description Get server current time. ### Method GET ### Endpoint /spot/time ```