### Install py3cw Package Source: https://github.com/bogdanteodoru/py3cw/blob/master/README.md Install the py3cw library using pip. ```bash pip install py3cw ``` -------------------------------- ### GET /marketplace/items Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Browses available signal providers and bot presets in the 3Commas marketplace. ```APIDOC ## GET /marketplace/items ### Description Browse available signal providers and bot presets in the 3Commas marketplace. ### Method GET ### Endpoint /marketplace/items ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of items to return (default: 20). - **offset** (integer) - Optional - The number of items to skip (default: 0). ### Response #### Success Response (200) - **name** (string) - The name of the marketplace item. - **item_type** (string) - The type of the item (e.g., 'signal_provider', 'bot_preset'). - ... (other item details) #### Response Example ```json [ { "name": "TradingView Signals", "item_type": "signal_provider" } ] ``` ``` -------------------------------- ### GET /deals Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of deals filtered by scope and account. ```APIDOC ## GET /deals ### Description Retrieve all active or historical deals. ### Method GET ### Endpoint deals ### Parameters #### Request Body - **limit** (integer) - Optional - Number of records to return - **offset** (integer) - Optional - Pagination offset - **scope** (string) - Required - Filter by status: 'active', 'finished', 'completed', 'cancelled', 'failed' - **account_id** (integer) - Required - The account ID to filter by ``` -------------------------------- ### Get Deal Details Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve detailed information for a specific deal by its ID. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get deal details error, data = p3cw.request( entity='deals', action='show', action_id='456789' ) if error: print(f"Error: {error}") else: print(f"Deal: {data['pair']}") print(f"Status: {data['status']}") print(f"Current profit: {data['actual_profit_percentage']}%") print(f"Safety orders filled: {data['completed_safety_orders_count']}/{data['max_safety_orders']}") ``` -------------------------------- ### GET /deals/{action_id} Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve detailed information about a specific deal. ```APIDOC ## GET /deals/{action_id} ### Description Retrieve detailed information about a specific deal including all orders and current status. ### Method GET ### Endpoint deals/show ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the deal ``` -------------------------------- ### Bots API - Start New Deal Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Manually triggers a new deal for a specific bot, bypassing the configured start conditions. ```APIDOC ## POST /bots/{action_id}/start_new_deal ### Description Manually triggers a new deal for a specific bot, bypassing the configured start conditions. ### Method POST ### Endpoint /bots/{action_id}/start_new_deal ### Path Parameters - **action_id** (string) - Required - The ID of the bot to start a new deal for. ### Request Body - **pair** (string) - Required - The trading pair for the new deal (e.g., 'USDT_BTC'). - **skip_signal_checks** (boolean) - Optional - Whether to skip signal checks. - **skip_open_deals_checks** (boolean) - Optional - Whether to skip open deals checks. ### Request Example ```json { "pair": "USDT_BTC", "skip_signal_checks": true, "skip_open_deals_checks": false } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly started deal. ### Response Example ```json { "id": 456789 } ``` ``` -------------------------------- ### Get All Bots with Filters Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of bots with optional filters for scope. Requires Py3CW initialization. ```python error, data = p3cw.request( entity='bots', action='', payload={ 'limit': 50, 'offset': 0, 'scope': 'enabled' # 'enabled', 'disabled', or omit for all } ) if error: print(f"Error: {error}") else: for bot in data: print(f"Bot: {bot['name']}, Pair: {bot['pairs']}, Active deals: {bot['active_deals_count']}") ``` -------------------------------- ### GET /smart_trades_v2 Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve all smart trades with filtering options. ```APIDOC ## GET /smart_trades_v2 ### Description Retrieve all smart trades with filtering options. ### Method GET ### Endpoint smart_trades_v2 ### Parameters #### Request Body - **limit** (integer) - Optional - Number of records - **offset** (integer) - Optional - Pagination offset - **account_id** (integer) - Required - Account ID - **scope** (string) - Required - 'active', 'finished', 'cancelled', 'failed' - **type** (string) - Required - 'simple_buy', 'simple_sell', 'smart_sell', 'smart_trade', 'smart_cover' ``` -------------------------------- ### Get Account Info Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Fetch detailed information for a specific account using its ID. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get specific account info error, data = p3cw.request( entity='accounts', action='account_info', action_id='12345' ) if error: print(f"Error: {error}") else: print(f"Account: {data['name']}, Balance: {data.get('usd_amount', 'N/A')} USD") # Output: Account: My Binance, Balance: 5000.00 USD ``` -------------------------------- ### GET /accounts Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve all connected exchange accounts from your 3Commas profile. ```APIDOC ## GET /accounts ### Description Retrieve all connected exchange accounts from your 3Commas profile. Returns account details including exchange type, balance information, and connection status. ### Method GET ### Endpoint accounts ### Response #### Success Response (200) - **data** (array) - List of account objects containing id, exchange_name, and balance details. ``` -------------------------------- ### Get Bot Statistics Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve overall bot statistics for an account, including profit and completed deals. Requires Py3CW initialization. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get overall bot statistics error, data = p3cw.request( entity='bots', action='stats', payload={ 'account_id': 12345 } ) if error: print(f"Error: {error}") else: print(f"Total profit: {data.get('overall_usd_profit', 0)} USD") print(f"Total deals: {data.get('completed_deals_count', 0)}") ``` -------------------------------- ### Start New Deal for Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Manually trigger a new deal for a specific bot and pair, with options to skip signal checks or open deal checks. Requires bot ID and Py3CW initialization. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Start a new deal for a specific pair error, data = p3cw.request( entity='bots', action='start_new_deal', action_id='98765', payload={ 'pair': 'USDT_BTC', 'skip_signal_checks': True, 'skip_open_deals_checks': False } ) if error: print(f"Error: {error}") else: print(f"Deal started with ID: {data['id']}") ``` -------------------------------- ### Get Market Pairs Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve valid trading pairs for a specified exchange market. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get market pairs for Binance error, data = p3cw.request( entity='accounts', action='market_pairs', payload={ 'market_code': 'binance' } ) if error: print(f"Error: {error}") else: print(f"Available pairs: {data[:5]}") # First 5 pairs # Output: Available pairs: ['USDT_BTC', 'USDT_ETH', 'USDT_BNB', 'USDT_ADA', 'USDT_XRP'] ``` -------------------------------- ### GET /users/current_mode Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Checks whether the account is in real or paper trading mode. ```APIDOC ## GET /users/current_mode ### Description Check whether the account is in real or paper trading mode. ### Method GET ### Endpoint /users/current_mode ### Response #### Success Response (200) - **mode** (string) - The current trading mode ('real' or 'paper'). #### Response Example ```json { "mode": "real" } ``` ``` -------------------------------- ### GET /accounts/market_pairs Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve available trading pairs for a specific market or exchange. ```APIDOC ## GET /accounts/market_pairs ### Description Retrieve available trading pairs for a specific market/exchange. Useful for validating pair names before creating bots or trades. ### Method GET ### Endpoint accounts/market_pairs ### Parameters #### Request Body - **market_code** (string) - Required - The code of the market/exchange (e.g., 'binance'). ### Response #### Success Response (200) - **data** (array) - List of available trading pairs. ``` -------------------------------- ### Enable/Disable Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Toggle a bot's active status to start or stop it from opening new deals. Requires the bot's ID and Py3CW initialization. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Enable a bot error, data = p3cw.request( entity='bots', action='enable', action_id='98765' ) if not error: print(f"Bot enabled: {data['is_enabled']}") # Disable a bot error, data = p3cw.request( entity='bots', action='disable', action_id='98765' ) if not error: print(f"Bot disabled: {not data['is_enabled']}") ``` -------------------------------- ### Get Grid Bot Profits Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve profit history and performance metrics for a specific grid bot using its ID. This is useful for performance tracking. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get grid bot profits error, data = p3cw.request( entity='grid_bots', action='profits', action_id='321654' ) if error: print(f"Error: {error}") else: print(f"Grid profit data: {data}") # Output: Grid profit data: {'grid_profit': '150.25', 'grid_profit_percentage': '2.5', ...} ``` -------------------------------- ### GET /grid_bots/{action_id}/profits Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieves profit history and performance metrics for a specific grid bot. ```APIDOC ## GET /grid_bots/{action_id}/profits ### Description Retrieve profit history and performance metrics for a grid bot. ### Method GET ### Endpoint /grid_bots/{action_id}/profits ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the grid bot to retrieve profits for. ### Response #### Success Response (200) - **grid_profit** (string) - The total profit generated by the grid bot. - **grid_profit_percentage** (string) - The percentage of profit relative to the investment. - ... (other performance metrics) #### Response Example ```json { "grid_profit": "150.25", "grid_profit_percentage": "2.5" } ``` ``` -------------------------------- ### Bots API - Get Bot Statistics Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieves performance statistics for all bots or overall account trading statistics. ```APIDOC ## GET /bots/stats ### Description Retrieves performance statistics for all bots or overall account trading statistics. ### Method GET ### Endpoint /bots/stats ### Query Parameters - **account_id** (integer) - Optional - The ID of the account to retrieve statistics for. If omitted, returns overall statistics. ### Response #### Success Response (200) - **overall_usd_profit** (number) - The overall profit in USD. - **completed_deals_count** (integer) - The total number of completed deals. ### Response Example ```json { "overall_usd_profit": 1250.50, "completed_deals_count": 145 } ``` ``` -------------------------------- ### GET /accounts/{account_id}/account_info Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve detailed information about a specific exchange account by its ID. ```APIDOC ## GET /accounts/{account_id}/account_info ### Description Retrieve detailed information about a specific exchange account by its ID, including balance data and trading pairs. ### Method GET ### Endpoint accounts/account_info ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the account to retrieve info for. ### Response #### Success Response (200) - **data** (object) - Detailed account information including name and usd_amount. ``` -------------------------------- ### Bots API - Enable/Disable Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Toggles a bot's active status to start or stop it from opening new deals. ```APIDOC ## POST /bots/{action_id}/{action} ### Description Toggles a bot's active status to start or stop it from opening new deals. ### Method POST ### Endpoint /bots/{action_id}/{action} ### Path Parameters - **action_id** (string) - Required - The ID of the bot to enable or disable. - **action** (string) - Required - The action to perform ('enable' or 'disable'). ### Response #### Success Response (200) - **is_enabled** (boolean) - The new enabled status of the bot. ### Response Example ```json { "is_enabled": true } ``` ``` -------------------------------- ### Get Current Trading Mode Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Check if the account is currently in real or paper trading mode. This is useful for verifying trading environment settings. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get current trading mode error, data = p3cw.request( entity='users', action='current_mode' ) if error: print(f"Error: {error}") else: print(f"Current mode: {data['mode']}") # Output: Current mode: real ``` -------------------------------- ### Get Smart Trade by ID Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve detailed information about a specific smart trade using its ID. This is useful for monitoring trade status and performance. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get smart trade details error, data = p3cw.request( entity='smart_trades_v2', action='get_by_id', action_id='789012' ) if error: print(f"Error: {error}") else: print(f"Pair: {data['pair']}") print(f"Status: {data['status']['type']}") print(f"Profit: {data.get('profit', {}).get('percent', 'N/A')}%') ``` -------------------------------- ### Smart Trades V2 API - Get Smart Trade by ID Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve detailed information about a specific smart trade using its ID. ```APIDOC ## GET /api/v2/smart_trades/{id} ### Description Retrieves detailed information about a specific smart trade. ### Method GET ### Endpoint /api/v2/smart_trades/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the smart trade to retrieve. ### Response #### Success Response (200) - **pair** (string) - The trading pair. - **status** (object) - The current status of the smart trade. - **type** (string) - The type of status (e.g., 'waiting_position', 'active'). - **profit** (object) - Profit information. - **percent** (string) - The profit percentage. #### Response Example ```json { "pair": "USDT_ETH", "status": { "type": "waiting_position" }, "profit": { "percent": "0.5" } } ``` ``` -------------------------------- ### Bots API - Get All Bots Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieves a list of all trading bots with optional filters for limiting results, setting offsets, and filtering by scope (enabled, disabled, or all). ```APIDOC ## GET /bots ### Description Retrieves a list of all trading bots with optional filters. ### Method GET ### Endpoint /bots ### Query Parameters - **limit** (integer) - Optional - Maximum number of bots to return. - **offset** (integer) - Optional - Number of bots to skip before returning results. - **scope** (string) - Optional - Filter bots by status ('enabled', 'disabled', or omit for all). ### Response #### Success Response (200) - **data** (array) - A list of bot objects. - **name** (string) - The name of the bot. - **pairs** (array) - The trading pairs configured for the bot. - **active_deals_count** (integer) - The number of active deals for the bot. ### Response Example ```json { "data": [ { "name": "BTC DCA Bot", "pairs": ["USDT_BTC"], "active_deals_count": 2 } ] } ``` ``` -------------------------------- ### Initialize Py3CW Client Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Configure the client using either HMAC credentials or an RSA private key with custom request options. ```python from py3cw.request import Py3CW # Basic initialization with HMAC secret p3cw = Py3CW( key='your_api_key', secret='your_api_secret' ) # Advanced initialization with RSA private key and custom request options p3cw = Py3CW( key='your_api_key', selfsigned='''-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEA... -----END RSA PRIVATE KEY-----''', request_options={ 'request_timeout': 10, # Timeout in seconds (connect and read) 'nr_of_retries': 3, # Number of retry attempts 'retry_status_codes': [500, 502, 503, 504], # Status codes to retry 'retry_backoff_factor': 0.5 # Exponential backoff multiplier } ) ``` -------------------------------- ### POST /grid_bots/manual Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Creates a grid bot with manually specified price range and grid parameters. ```APIDOC ## POST /grid_bots/manual ### Description Create a grid bot with manually specified price range and grid parameters. ### Method POST ### Endpoint /grid_bots/manual ### Parameters #### Request Body - **account_id** (integer) - Required - The ID of the account to create the bot on. - **pair** (string) - Required - The trading pair for the bot (e.g., 'USDT_BTC'). - **upper_price** (string) - Required - The upper price limit for the grid. - **lower_price** (string) - Required - The lower price limit for the grid. - **grids_quantity** (string) - Required - The total number of grids. - **quantity_per_grid** (string) - Required - The quantity of base currency to allocate per grid. - **leverage_type** (string) - Optional - The leverage type to use (e.g., 'not_specified', 'cross', 'isolated'). ### Request Example ```json { "account_id": 12345, "pair": "USDT_BTC", "upper_price": "50000", "lower_price": "40000", "grids_quantity": "20", "quantity_per_grid": "50", "leverage_type": "not_specified" } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly created manual grid bot. #### Response Example ```json { "id": 321655 } ``` ``` -------------------------------- ### Initialize Py3CW Client Source: https://github.com/bogdanteodoru/py3cw/blob/master/README.md Initialize the Py3CW client with API keys and optional request options. Customize timeout, retries, and backoff factor. ```python from py3cw.request import Py3CW # request_options is optional, as all the keys from the dict # so you can only change what you want. # # default options for request_options are: # request_timeout: 30s (30 for connect, 30 for read) # nr_of_retries: 5 # retry_status_codes: [500, 502, 503, 504] # retry_backoff_factor (optional): It allows you to change how long the processes will sleep between failed requests. # For example, if the backoff factor is set to: # 1 second the successive sleeps will be 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256. # 2 seconds - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 # 10 seconds - 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560 # # NOTE: Nr of retries and retry_status_codes will also be used if we get # an falsy success from 3 commas (eg: { "error": { "status_code": 502 }}) p3cw = Py3CW( key='', secret='', #System generated secret key selfsigned='', #RSA generated private key request_options={ 'request_timeout': 10, 'nr_of_retries': 1, 'retry_status_codes': [502], 'retry_backoff_factor': 0.1 } ) ``` -------------------------------- ### Create Manual Grid Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Use this to create a grid bot with manually defined price range and grid parameters. Ensure you have valid API keys and account ID. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Create manual grid bot error, data = p3cw.request( entity='grid_bots', action='manual', payload={ 'account_id': 12345, 'pair': 'USDT_BTC', 'upper_price': '50000', 'lower_price': '40000', 'grids_quantity': '20', 'quantity_per_grid': '50', 'leverage_type': 'not_specified' } ) if error: print(f"Error: {error}") else: print(f"Manual Grid bot created: {data['id']}") # Output: Manual Grid bot created: 321655 ``` -------------------------------- ### Smart Trades V2 API - Create Smart Trade Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Create a new smart trade with trailing take profit, stop loss, and other configurations. ```APIDOC ## POST /api/v2/smart_trades ### Description Creates a new smart trade with specified parameters, including leverage, position details, take profit, and stop loss. ### Method POST ### Endpoint /api/v2/smart_trades ### Parameters #### Request Body - **account_id** (integer) - Required - The ID of the account to create the smart trade in. - **pair** (string) - Required - The trading pair (e.g., 'USDT_ETH'). - **instant** (boolean) - Optional - If true, the trade is executed immediately. - **skip_enter_step** (boolean) - Optional - If true, skips the initial entry step. - **leverage** (object) - Optional - Leverage settings. - **enabled** (boolean) - Required - Whether leverage is enabled. - **position** (object) - Required - Details of the trade position. - **type** (string) - Required - Type of position ('buy' or 'sell'). - **units** (object) - Required - The quantity of the asset to trade. - **value** (string) - Required - The numerical value of the units. - **order_type** (string) - Required - The type of order ('limit' or 'market'). - **price** (object) - Required if order_type is 'limit' - The price for the limit order. - **value** (string) - Required - The numerical value of the price. - **take_profit** (object) - Optional - Take profit configuration. - **enabled** (boolean) - Required - Whether take profit is enabled. - **steps** (array) - Required if enabled is true - A list of take profit steps. - **order_type** (string) - Required - The order type for the take profit step. - **price** (object) - Required - The price condition for the take profit step. - **type** (string) - Required - The type of price ('bid', 'ask', 'last'). - **percent** (string) - Required - The percentage of the price change. - **volume** (string) - Required - The volume to which this take profit applies. - **stop_loss** (object) - Optional - Stop loss configuration. - **enabled** (boolean) - Required - Whether stop loss is enabled. - **order_type** (string) - Required - The order type for the stop loss ('limit' or 'market'). - **price** (object) - Required - The price condition for the stop loss. - **value** (string) - Required - The numerical value of the stop loss price. ### Request Example ```json { "account_id": 12345, "pair": "USDT_ETH", "instant": false, "skip_enter_step": false, "leverage": { "enabled": false }, "position": { "type": "buy", "units": { "value": "0.1" }, "order_type": "limit", "price": { "value": "3000" } }, "take_profit": { "enabled": true, "steps": [ { "order_type": "limit", "price": { "type": "bid", "percent": "5" }, "volume": "100" } ] }, "stop_loss": { "enabled": true, "order_type": "market", "price": { "value": "2800" } } } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly created smart trade. #### Response Example ```json { "id": 789012 } ``` ``` -------------------------------- ### Create Smart Trade with Trailing Take Profit Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Use this to create a new smart trade with trailing take profit enabled. Ensure your API key and secret are correctly configured. ```python error, data = p3cw.request( entity='smart_trades_v2', action='new', payload={ 'account_id': 12345, 'pair': 'USDT_ETH', 'instant': False, 'skip_enter_step': False, 'leverage': { 'enabled': False }, 'position': { 'type': 'buy', 'units': { 'value': '0.1' }, 'order_type': 'limit', 'price': { 'value': '3000' } }, 'take_profit': { 'enabled': True, 'steps': [ { 'order_type': 'limit', 'price': { 'type': 'bid', 'percent': '5' }, 'volume': '100' } ] }, 'stop_loss': { 'enabled': True, 'order_type': 'market', 'price': { 'value': '2800' } } } ) if error: print(f"Error: {error}") else: print(f"Smart trade created with ID: {data['id']}") ``` -------------------------------- ### List Marketplace Items Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Browse available signal providers and bot presets in the 3Commas marketplace. You can filter results using limit and offset parameters. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get marketplace items error, data = p3cw.request( entity='marketplace', action='items', payload={ 'limit': 20, 'offset': 0 } ) if error: print(f"Error: {error}") else: for item in data: print(f"Item: {item['name']}, Type: {item['item_type']}") # Output: Item: TradingView Signals, Type: signal_provider ``` -------------------------------- ### Create AI Grid Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Create an AI-powered grid bot. This bot automatically determines optimal grid parameters based on historical data. Requires account ID, trading pair, and quantity. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Create AI grid bot error, data = p3cw.request( entity='grid_bots', action='ai', payload={ 'account_id': 12345, 'pair': 'USDT_ETH', 'total_quantity': '1000', 'leverage_type': 'not_specified', 'leverage_custom_value': None } ) if error: print(f"Error: {error}") else: print(f"AI Grid bot created: {data['id']}") print(f"Lower price: {data['lower_price']}, Upper price: {data['upper_price']}") print(f"Grid lines: {data['grids_quantity']}") ``` -------------------------------- ### Load Balances Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Trigger a manual refresh of account balances from the exchange. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Refresh balances for account error, data = p3cw.request( entity='accounts', action='load_balances', action_id='12345' ) if error: print(f"Error: {error}") else: print(f"Balances refreshed: {data}") ``` -------------------------------- ### List All Bots Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of all configured trading bots. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') ``` -------------------------------- ### Grid Bots API - Create AI Grid Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Create an AI-powered grid bot that automatically optimizes trading parameters. ```APIDOC ## POST /api/v2/grid_bots/ai ### Description Creates an AI-powered grid bot. The system automatically determines optimal grid parameters based on historical data. ### Method POST ### Endpoint /api/v2/grid_bots/ai ### Parameters #### Request Body - **account_id** (integer) - Required - The ID of the account for the grid bot. - **pair** (string) - Required - The trading pair (e.g., 'USDT_ETH'). - **total_quantity** (string) - Required - The total quantity of the base asset to be traded. - **leverage_type** (string) - Optional - The type of leverage ('not_specified', 'cross', 'isolated'). - **leverage_custom_value** (string or null) - Optional - The custom leverage value if leverage_type is 'isolated'. ### Request Example ```json { "account_id": 12345, "pair": "USDT_ETH", "total_quantity": "1000", "leverage_type": "not_specified", "leverage_custom_value": null } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the created AI grid bot. - **lower_price** (string) - The lower bound of the price range for the grid. - **upper_price** (string) - The upper bound of the price range for the grid. - **grids_quantity** (integer) - The number of grid lines. #### Response Example ```json { "id": 321654, "lower_price": "2800", "upper_price": "3500", "grids_quantity": 50 } ``` ``` -------------------------------- ### List Active Deals Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of active deals with pagination and filtering options. ```python error, data = p3cw.request( entity='deals', action='', payload={ 'limit': 100, 'offset': 0, 'scope': 'active', # 'active', 'finished', 'completed', 'cancelled', 'failed' 'account_id': 12345 } ) if error: print(f"Error: {error}") else: for deal in data: print(f"Deal ID: {deal['id']}, Pair: {deal['pair']}, Profit: {deal.get('actual_profit', 'N/A')}") ``` -------------------------------- ### List All Accounts Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of all connected exchange accounts and their basic details. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get all accounts error, data = p3cw.request( entity='accounts', action='' ) if error: print(f"Error: {error}") else: for account in data: print(f"Account ID: {account['id']}, Exchange: {account['exchange_name']}") # Output: Account ID: 12345, Exchange: Binance ``` -------------------------------- ### POST /bots/start_new_deal with Forced-Mode Header Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Overrides the account trading mode for a specific request using the additional_headers parameter. ```APIDOC ## POST /bots/start_new_deal with Forced-Mode Header ### Description Override the account trading mode for a specific request using the additional_headers parameter. This allows testing in paper mode without switching the entire account. ### Method POST ### Endpoint /bots/start_new_deal ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the bot to start a new deal with. #### Request Body - **pair** (string) - Required - The trading pair for the new deal. #### Headers - **Forced-Mode** (string) - Optional - Overrides the account trading mode ('real' or 'paper'). ### Request Example ```json { "pair": "USDT_BTC" } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly started deal. #### Response Example ```json { "id": 456790 } ``` ``` -------------------------------- ### Add Funds to Deal Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Add additional funds to an existing deal to adjust the average entry price. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Add funds to a deal error, data = p3cw.request( entity='deals', action='add_funds', action_id='456789', payload={ 'quantity': '0.001', 'is_market': True, 'response_type': 'deal' } ) if error: print(f"Error: {error}") else: print(f"Funds added, new average price: {data.get('bought_average_price')}") ``` -------------------------------- ### POST /accounts/{account_id}/load_balances Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Force refresh account balances from the exchange. ```APIDOC ## POST /accounts/{account_id}/load_balances ### Description Force refresh account balances from the exchange. This triggers an immediate sync with the exchange API. ### Method POST ### Endpoint accounts/load_balances ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the account to refresh. ``` -------------------------------- ### Deals API - List All Deals Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieves all deals (active, completed, or all) with optional filtering by bot, account, or status. ```APIDOC ## GET /deals ### Description Retrieves all deals (active, completed, or all) with optional filtering by bot, account, or status. ### Method GET ### Endpoint /deals ### Query Parameters - **bot_id** (integer) - Optional - Filter deals by bot ID. - **account_id** (integer) - Optional - Filter deals by account ID. - **status** (string) - Optional - Filter deals by status ('active', 'completed', 'stopped', 'error', 'all'). - **limit** (integer) - Optional - Maximum number of deals to return. - **offset** (integer) - Optional - Number of deals to skip before returning results. ### Response #### Success Response (200) - **data** (array) - A list of deal objects. - **id** (integer) - The ID of the deal. - **bot_id** (integer) - The ID of the bot associated with the deal. - **pair** (string) - The trading pair for the deal. - **status** (string) - The current status of the deal. ### Response Example ```json { "data": [ { "id": 123456, "bot_id": 98765, "pair": "USDT_BTC", "status": "active" } ] } ``` ``` -------------------------------- ### POST /deals/{action_id}/add_funds Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Add additional funds to an existing deal. ```APIDOC ## POST /deals/{action_id}/add_funds ### Description Add additional funds to an existing deal to lower the average entry price. ### Method POST ### Endpoint deals/add_funds ### Parameters #### Path Parameters - **action_id** (string) - Required - The ID of the deal #### Request Body - **quantity** (string) - Required - Amount to add - **is_market** (boolean) - Required - Whether to use market order - **response_type** (string) - Required - Response format type ``` -------------------------------- ### List Grid Bots Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of all configured grid bots. This endpoint allows filtering by account, state, and pagination. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get all grid bots error, data = p3cw.request( entity='grid_bots', action='', payload={ 'limit': 50, 'offset': 0, 'account_ids': [12345], 'state': 'enabled' # 'enabled', 'disabled' } ) if error: print(f"Error: {error}") else: for bot in data: print(f"Grid Bot: {bot['name']}, Pair: {bot['pair']}, Profit: {bot.get('current_profit', 'N/A')}") ``` -------------------------------- ### Make a Basic API Request Source: https://github.com/bogdanteodoru/py3cw/blob/master/README.md Perform a request to the 3Commas API without any payload data. The response is destructured into error and data. ```python # With no action # Destruct response to error and data # and check first if we have an error, otherwise check the data error, data = p3cw.request( entity='smart_trades_v2', action='' ) ``` -------------------------------- ### POST /users/change_mode Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Switches between real and paper trading modes for testing strategies. ```APIDOC ## POST /users/change_mode ### Description Switch between real and paper trading modes for testing strategies. ### Method POST ### Endpoint /users/change_mode ### Parameters #### Request Body - **mode** (string) - Required - The desired trading mode ('real' or 'paper'). ### Request Example ```json { "mode": "paper" } ``` ### Response #### Success Response (200) - **mode** (string) - The newly set trading mode ('real' or 'paper'). #### Response Example ```json { "mode": "paper" } ``` ``` -------------------------------- ### Panic Sell Deal Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Immediately close a deal by selling all positions at market price. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Panic sell a deal error, data = p3cw.request( entity='deals', action='panic_sell', action_id='456789' ) if error: print(f"Error: {error}") else: print(f"Deal closed: {data['status']}") ``` -------------------------------- ### Bots API - Create Bot Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Creates a new DCA (Dollar Cost Averaging) trading bot with specified parameters including pairs, safety orders, and take profit settings. ```APIDOC ## POST /bots/create_bot ### Description Creates a new DCA (Dollar Cost Averaging) trading bot with specified parameters. ### Method POST ### Endpoint /bots/create_bot ### Request Body - **name** (string) - Required - The name of the bot. - **account_id** (integer) - Required - The ID of the account to create the bot in. - **pairs** (array of strings) - Required - The trading pairs for the bot (e.g., ['USDT_BTC']). - **base_order_volume** (string) - Required - The volume of the base order. - **take_profit** (string) - Required - The take profit percentage. - **safety_order_volume** (string) - Required - The volume of safety orders. - **martingale_volume_coefficient** (string) - Optional - Martingale volume coefficient. - **martingale_step_coefficient** (string) - Optional - Martingale step coefficient. - **max_safety_orders** (integer) - Optional - Maximum number of safety orders. - **active_safety_orders_count** (integer) - Optional - Number of active safety orders. - **safety_order_step_percentage** (string) - Optional - Percentage step for safety orders. - **take_profit_type** (string) - Optional - Type of take profit ('total' or 'percentage'). - **strategy_list** (array of objects) - Optional - List of strategies to apply. - **bot_type** (string) - Optional - The type of bot (e.g., 'Bot::SingleBot'). ### Request Example ```json { "name": "My BTC DCA Bot", "account_id": 12345, "pairs": ["USDT_BTC"], "base_order_volume": "10", "take_profit": "1.5", "safety_order_volume": "20", "martingale_volume_coefficient": "1.05", "martingale_step_coefficient": "1", "max_safety_orders": 5, "active_safety_orders_count": 3, "safety_order_step_percentage": "2.5", "take_profit_type": "total", "strategy_list": [{"strategy": "nonstop"}], "bot_type": "Bot::SingleBot" } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the newly created bot. ### Response Example ```json { "id": 98765 } ``` ``` -------------------------------- ### List Smart Trades Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Retrieve a list of smart trades with filtering options. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Get all smart trades error, data = p3cw.request( entity='smart_trades_v2', action='', payload={ 'limit': 50, 'offset': 0, 'account_id': 12345, 'scope': 'active', # 'active', 'finished', 'cancelled', 'failed' 'type': 'simple_buy' # 'simple_buy', 'simple_sell', 'smart_sell', 'smart_trade', 'smart_cover' } ) if error: print(f"Error: {error}") else: for trade in data: print(f"Smart Trade ID: {trade['id']}, Pair: {trade['pair']}, Status: {trade['status']['type']}") ``` -------------------------------- ### Update Smart Trade Take Profit Source: https://context7.com/bogdanteodoru/py3cw/llms.txt Modify the take profit settings for an existing smart trade. This allows dynamic adjustment of profit targets. ```python from py3cw.request import Py3CW p3cw = Py3CW(key='your_api_key', secret='your_api_secret') # Update smart trade take profit error, data = p3cw.request( entity='smart_trades_v2', action='update', action_id='789012', payload={ 'take_profit': { 'enabled': True, 'steps': [ { 'order_type': 'limit', 'price': { 'type': 'bid', 'percent': '7' }, 'volume': '100' } ] } } ) if error: print(f"Error: {error}") else: print(f"Smart trade updated: {data['id']}") ```