### Start WebSocket Subscription with run() Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Example of starting the WebSocket subscription using the run() method with a specific list of symbols. The example notes that pressing Ctrl+C will interrupt the process. ```python # Start WebSocket subscription ws_api.run(_symbols=['THA.4.12', 'LVS.4.20', 'CIS.4.11']) # User presses Ctrl+C to interrupt # Logs: "[EXCEPTION] > ¡KeyboardInterrupt Exception!" # Method returns and continues program ``` -------------------------------- ### Darwinex API Client Initialization Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/configuration.md Example of initializing various Darwinex API clients with authentication credentials and version/demo settings. Includes setup for Info, Trading, Account Info, Quotes, WebSocket, and TickData APIs. ```python from darwinexapis import ( DWX_Info_API, DWX_AccInfo_API, DWX_Trading_API, DWX_Quotes_API, DWX_WebSocket_API, DWX_TickData_Downloader_API ) # Authentication auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } # Info API - Latest version info_api = DWX_Info_API(auth_creds, _version=2.0, _demo=True) # Trading API - Version 1.1 with conditional orders trading_api = DWX_Trading_API(auth_creds, _version=1.1, _demo=True) # Account Info - Always use latest acc_api = DWX_AccInfo_API(auth_creds, _demo=True) # Quotes streaming quotes_api = DWX_Quotes_API(auth_creds) # WebSocket streaming ws_api = DWX_WebSocket_API(auth_creds) # TickData downloader ftp_config = { 'dwx_ftp_user': 'your_username', 'dwx_ftp_pass': 'your_ftp_password', 'dwx_ftp_hostname': 'tickdata.darwinex.com', 'dwx_ftp_port': 21 } tickdata = DWX_TickData_Downloader_API(**ftp_config) ``` -------------------------------- ### DWX WebSocket API Lifecycle Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Demonstrates the lifecycle of the DWX WebSocket API, including initialization, starting a subscription, and notes on stopping and restarting the event loop. Ensure you have the necessary authentication credentials. ```python from darwinexapis import DWX_WebSocket_API auth_creds = { 'access_token': 'token', 'consumer_key': 'key', 'consumer_secret': 'secret', 'refresh_token': 'refresh' } ws_api = DWX_WebSocket_API(auth_creds) # Start subscription print("Starting WebSocket subscription...") ws_api.run(_symbols=['DWZ.4.7', 'DWC.4.20']) # After Ctrl+C or token refresh: # - Event loop closes # - New loop is set up # - Ready for next run() # To stop: set _active to False # ws_api._active = False ``` -------------------------------- ### Download One Hour Data Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/DOCUMENTATION_MANIFEST.txt Example of downloading one hour of ask data for a specific symbol and date. ```python data = downloader._download_one_hour_data_ask('WS30', '2023-01-01', '14') ``` -------------------------------- ### Install Darwinex APIs in Development Mode Source: https://github.com/darwinex/darwinexapis/blob/master/README.rst Install the Darwinex API package in development mode by changing the directory and using pip install -e. ```bash pip install -e . ``` -------------------------------- ### Install Darwinex APIs Source: https://github.com/darwinex/darwinexapis/blob/master/README.rst Install the Darwinex API package using pip. Upgrade to the latest version if needed. ```bash pip install darwinexapis ``` ```bash pip install -U darwinexapis ``` -------------------------------- ### Custom API URL Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/configuration.md This example demonstrates how to configure a custom base URL for an API, such as using a sandbox environment. It also shows how to set the demo mode. ```python # Use sandbox environment info_api = DWX_Info_API( auth_creds, _api_url='https://sandbox.darwinex.com', _demo=True ) ``` -------------------------------- ### Initialize Info API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/DOCUMENTATION_MANIFEST.txt Example of initializing the DWX_Info_API with authentication credentials, API version, and demo mode enabled. This is typically done before making any API calls. ```python from darwinexapis import DWX_Info_API api = DWX_Info_API(auth_creds, _version=2.0, _demo=True) ``` -------------------------------- ### Complete Example: Download Multiple Data Types Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Darwin_Data_Analytics_API.md Demonstrates initializing the API and downloading multiple types of analytics data for a specified DARWIN symbol using FTP. ```python from darwinexapis import DWX_Darwin_Data_Analytics_API # Initialize api = DWX_Darwin_Data_Analytics_API( dwx_ftp_user='your_username', dwx_ftp_pass='your_password', dwx_ftp_hostname='analytics.darwinex.com', dwx_ftp_port=21 ) # Download multiple data types for a DARWIN darwin_symbol = 'PLF' # Get leverage data leverage = api.get_data_from_ftp(darwin_symbol, 'AVG_LEVERAGE') print(f"Leverage data shape: {leverage.shape}") ``` -------------------------------- ### Analytics FTP File Path Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md This example demonstrates the path format for accessing analytics data files via FTP. Files are CSVs with one record per line. ```bash PLF/AVG_LEVERAGE PLF/RETURN_DIVERGENCE ``` -------------------------------- ### Initialize Trading API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/DOCUMENTATION_MANIFEST.txt Example of initializing the DWX_Trading_API with authentication credentials, API version, and demo mode enabled. This is used for executing trades. ```python trading = DWX_Trading_API(auth_creds, _version=1.1, _demo=True) ``` -------------------------------- ### Instantiate DWX_WebSocket_API with Authentication Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Example of how to instantiate the DWX_WebSocket_API class with necessary authentication credentials. Ensure 'your_token', 'your_key', 'your_secret', and 'your_refresh' are replaced with actual values. ```python from darwinexapis import DWX_WebSocket_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } ws_api = DWX_WebSocket_API(auth_creds) ``` -------------------------------- ### Complete DWX TickData Downloader API Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Downloader_API.md Demonstrates initializing the downloader, downloading hourly and daily data, and saving it in multiple formats. Also shows downloading data for a date range. ```python from darwinexapis import DWX_TickData_Downloader_API # Initialize downloader = DWX_TickData_Downloader_API( dwx_ftp_user='your_username', dwx_ftp_pass='your_password', dwx_ftp_hostname='tickdata.darwinex.com', dwx_ftp_port=21 ) # Download hourly ask data bid_hour = downloader._download_one_hour_data_ask( _asset='WS30', _date='2018-10-01', _hour='22', _verbose=True ) # Save in multiple formats downloader._save_df_to_csv(bid_hour, '/data/') downloader._save_df_to_pickle(bid_hour, '/data/') # Download daily data daily_bid = downloader._download_one_day_data_bid( _asset='WS30', _date='2018-10-01', _verbose=True ) downloader._save_df_to_csv(daily_bid, '/data/') # Download date range month_ask = downloader._download_month_data_ask( _asset='WS30', _start_date='2018-10-01', _end_date='2018-10-04', _verbose=True ) downloader._save_df_to_csv(month_ask, '/data/') ``` -------------------------------- ### TickData FTP File Path Example Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md This example shows the expected path format for accessing tick data files via FTP. Files are gzip-compressed CSVs with millisecond-precision data. ```bash WS30/WS30_ASK_2018-10-01_22.log.gz WS30/WS30_BID_2018-10-01_22.log.gz ``` -------------------------------- ### run() Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Starts the WebSocket subscription in a synchronous event loop. This method is the primary way to initiate and manage the WebSocket connection for real-time data. ```APIDOC ## run() ### Description Synchronously starts the WebSocket subscription by creating and running an asyncio event loop. It manages the lifecycle of the `subscribe()` coroutine, including error handling and cleanup. ### Method run(_symbols=['DWZ.4.7', 'DWC.4.20', 'LVS.4.20', 'SYO.4.24', 'YZZ.4.20']) ### Parameters #### Path Parameters - **_symbols** (list[str]) - Optional - DARWIN symbols to subscribe to. Defaults to a predefined list. ### Behavior 1. Stores the provided symbols. 2. Creates or retrieves an asyncio event loop. 3. Runs the `subscribe()` coroutine until completion. 4. Handles `RuntimeError` and `KeyboardInterrupt` exceptions. 5. Cleans up by cancelling tasks and closing the event loop upon completion or interruption. 6. Prepares for subsequent calls by setting up a new event loop. ### Raises - RuntimeError: Caught and logged; execution continues. - KeyboardInterrupt: Caught and logged; execution continues. ### Example ```python # Start WebSocket subscription ws_api.run(_symbols=['THA.4.12', 'LVS.4.20', 'CIS.4.11']) # User presses Ctrl+C to interrupt # Logs: "[EXCEPTION] > ¡KeyboardInterrupt Exception!" # Method returns and continues program ``` ``` -------------------------------- ### Initialize TickData Downloader API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/DOCUMENTATION_MANIFEST.txt Example of initializing the DWX_TickData_Downloader_API with user credentials and host information. This API is used for downloading tick data. ```python downloader = DWX_TickData_Downloader_API(user, pass, host, port) ``` -------------------------------- ### Authentication Credentials Dictionary Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/README.md Example structure for the authentication credentials dictionary required for API access. ```APIDOC ## Credentials Dictionary ### Description This dictionary contains the necessary credentials for authenticating with the Darwinex APIs. ### Fields - **access_token** (string) - Required - OAuth2 access token. - **consumer_key** (string) - Required - OAuth consumer key (username). - **consumer_secret** (string) - Required - OAuth consumer secret. - **refresh_token** (string) - Required - OAuth refresh token. ``` -------------------------------- ### Complete DARWIN API Suite Example Source: https://github.com/darwinex/darwinexapis/blob/master/README.rst A comprehensive Python script to demonstrate the usage of various DARWIN API classes. Ensure you have generated an Access Token from the Darwinex Platform. ```python # Let's import the different classes: from darwinexapis.API.InfoAPI.DWX_Info_API import DWX_Info_API from darwinexapis.API.InvestorAccountInfoAPI.DWX_AccInfo_API import DWX_AccInfo_API from darwinexapis.API.QuotesAPI.DWX_Quotes_API import DWX_Quotes_API from darwinexapis.API.TradingAPI.DWX_Trading_API import DWX_Trading_API from darwinexapis.API.WebSocketAPI.DWX_WebSocket_API import DWX_WebSocket_API ### Let's create the authentication dictionary: AUTH_CREDS = {'access_token': 'YOUR_ALPHA_TOKEN', 'consumer_key': 'YOUR_ALPHA_TOKEN', 'consumer_secret': 'YOUR_ALPHA_TOKEN', 'refresh_token': 'YOUR_ALPHA_TOKEN'} # Let's instantiate some API objects: darwinexInfo = DWX_Info_API(AUTH_CREDS, _version=2.0, _demo=True) darwinexInvestorAcc = DWX_AccInfo_API(AUTH_CREDS, _version=2.0, _demo=True) darwinexQuotes = DWX_Quotes_API(AUTH_CREDS, _version=1.0) darwinexTrading = DWX_Trading_API(AUTH_CREDS, _version=1.1, _demo=True) darwinexWebSocket = DWX_WebSocket_API(AUTH_CREDS, _version=0.0) # DWX_Info_API: darwinUniverse = darwinexInfo._Get_DARWIN_Universe_(_status='ACTIVE', _iterate=True, _perPage=100) print(darwinUniverse) # DWX_AccInfo_API: print(darwinexInvestorAcc._Get_Accounts_()) # DWX_Quotes_API: darwinexQuotes._stream_quotes_() darwinexQuotes._process_stream_(_symbols=["ENH.4.16"], _plot=False) # DWX_Trading_API: print(darwinexTrading._Get_Permitted_Operations_()) print(darwinexTrading._Get_Account_Leverage_(_id=0)) # DWX_WebSocket_API: darwinexWebSocket.run(_symbols=["ENH.4.16", "CIS.4.11", "CGT.4.5", "CDG.4.14", "ABH.4.21", "ENO.4.13"]) ``` -------------------------------- ### GET /products (DARWIN Universe) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve a paginated list of all available DARWIN products. Supports filtering by status and pagination. ```APIDOC ## GET /products ### Description Retrieve paginated list of all available DARWIN products. ### Method GET ### Endpoint https://api.darwinex.com/darwininfo/2.0/products?status={status}&page={page}&per_page={per_page} ### Parameters #### Query Parameters - **status** (string) - Optional - Filter by product status: 'ACTIVE', 'INACTIVE', 'ALL'. - **page** (integer) - Optional - Page number (0-indexed). - **per_page** (integer) - Optional - Results per page (1-100). ### Response #### Success Response (200) - **Response**: JSON object ```json { "content": [ { "name": "THA.4.12", "quote": 150.25, "status": "ACTIVE", ... } ], "totalPages": 5, "currentPage": 0 } ``` ``` -------------------------------- ### DWX_WebSocket_API run() Method Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Synchronous method to start the WebSocket subscription within an event loop. It runs the subscribe coroutine and handles exceptions. ```python run(_symbols=['DWZ.4.7', 'DWC.4.20', 'LVS.4.20', 'SYO.4.24', 'YZZ.4.20']) ``` -------------------------------- ### Manual Token Refresh Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/errors.md This example shows how to manually trigger a token refresh using the `_get_access_refresh_tokens_wrapper` method. It includes a try-except block to catch potential exceptions during the refresh process. ```python from darwinexapis import DWX_Info_API api = DWX_Info_API(auth_creds) # Manual token refresh try: api.AUTHENTICATION._get_access_refresh_tokens_wrapper() except Exception as e: print(f"Token refresh failed: {e}") # Handle accordingly ``` -------------------------------- ### Load DataFrame and Save to CSV Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Reader_API.md Loads symbol data into a DataFrame and then saves it to a specified CSV path. The example demonstrates saving to an '/output/' directory. ```python df = reader._get_symbol_as_dataframe_() reader._save_df_to_csv(df, which_path='/output/') # Saves to: /output/WS30_BID_ASK.csv ``` -------------------------------- ### Download One Hour Ask Tick Data Source: https://github.com/darwinex/darwinexapis/blob/master/README.rst Downloads one hour of ask tick data for a specified asset and date. This is a continuation of the tick data download example. ```python ask_hour_data = DOWNLOADER._download_one_hour_data_ask(_asset='WS30', ``` -------------------------------- ### Initialize API and Get Analytics Data Source: https://github.com/darwinex/darwinexapis/blob/master/darwinexapis/API/DarwinDataAnalyticsAPI/README.rst Initializes the DWX_Darwin_Data_Analytics_API and retrieves specific analytics data for a given Darwin. The data can then be saved to a CSV file. Ensure the CONFIG_PATH points to your credentials file. ```python # Do some imports: import os, pandas as pd # Import the class: from darwinexapis.API.DarwinDataAnalyticsAPI.DWX_Data_Analytics_API import DWX_Darwin_Data_Analytics_API # Create the object: CONFIG_PATH = os.path.expandvars('${HOME}/FTP_DARWIN_Access_Credentials.cfg') ANALYZER = DWX_DARWIN_DATA_ANALYTICS_API(config=CONFIG_PATH) # Download data of certain analytics variable: dataFrameReturned = ANALYZER.get_analytics(darwin='LVS', data_type='RETURN_DIVERGENCE') ANALYZER.save_data_to_csv(dataFrameReturned, which_path=os.path.expandvars('${HOME}/darwinexapis/EXAMPLE_DATA/'), filename='LVS_AVG_LEVERAGE') print(dataFrameReturned) ``` -------------------------------- ### Initialize DWX_Info_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Info_API.md Instantiate the DWX_Info_API class with authentication credentials and optional parameters for API URL, name, version, and demo mode. ```python from darwinexapis import DWX_Info_API auth_creds = { 'access_token': 'your_access_token', 'consumer_key': 'your_consumer_key', 'consumer_secret': 'your_consumer_secret', 'refresh_token': 'your_refresh_token' } info_api = DWX_Info_API(auth_creds, _version=2.0, _demo=True) ``` -------------------------------- ### GET /products (Historical Quotes) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve historical end-of-day quotes for a DARWIN product. Supports filtering by start and end timestamps. ```APIDOC ## GET /products/{symbol}/history/quotes ### Description Retrieve historical end-of-day quotes for a DARWIN product. ### Method GET ### Endpoint https://api.darwinex.com/darwininfo/2.0/products/{symbol}/history/quotes ### Parameters #### Query Parameters - **start** (Millisecond UNIX timestamp) - Optional - Start timestamp for historical data. - **end** (Millisecond UNIX timestamp) - Optional - End timestamp for historical data. ### Request Headers ``` Authorization: Bearer {access_token} ``` ### Response #### Success Response (200) - **Response**: JSON array ```json [ [1234567890000, 150.25], [1234567891000, 150.30] ] ``` #### Error Responses - **401**: Unauthorized - **404**: Symbol not found ``` -------------------------------- ### GET /products/{symbol}/history/ohlc (OHLC Candles) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve OHLC candle data for a DARWIN. Requires specifying resolution, start, and end timestamps. ```http GET https://api.darwinex.com/darwininfo/2.0/products/{symbol}/history/ohlc?resolution={resolution}&from={start}&to={end} ``` ```json [ [1234567890000, 150.00, 151.50, 149.75, 150.25, 1000], ... ] ``` -------------------------------- ### Initialize DWX_AccInfo_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_AccInfo_API.md Instantiate the DWX_AccInfo_API class with authentication credentials and optional parameters for API URL, name, version, and demo mode. ```python from darwinexapis import DWX_AccInfo_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } acc_api = DWX_AccInfo_API(auth_creds, _demo=True) ``` -------------------------------- ### Get Symbol Dataframe with Daily Resampling Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Reader_API.md Load daily OHLC data by specifying the precision as 'D' and setting a daily start hour. Returns a DataFrame with OHLC columns for mid-price. ```python # Load daily OHLC df_daily = reader._get_symbol_as_dataframe_( _convert_epochs=True, _precision='D', _daily_start=22 ) print(df_daily.head()) ``` -------------------------------- ### Initialize DWX_TickData_Downloader_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Downloader_API.md Instantiate the downloader with FTP credentials. Ensure you use your Darwinex FTP username and password, not your login credentials. ```python from darwinexapis import DWX_TickData_Downloader_API ftp_creds = { 'username': 'your_username', 'password': 'your_ftp_password', 'ftpServer': 'tickdata.darwinex.com', 'port': 21 } downloader = DWX_TickData_Downloader_API( dwx_ftp_user=ftp_creds['username'], dwx_ftp_pass=ftp_creds['password'], dwx_ftp_hostname=ftp_creds['ftpServer'], dwx_ftp_port=ftp_creds['port'] ) ``` -------------------------------- ### DWX_Info_API Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Info_API.md Initializes the DWX_Info_API client with authentication credentials and API configuration. Supports demo/sandbox mode. ```APIDOC ## DWX_Info_API Constructor ### Description Initializes the DWX_Info_API client with authentication credentials and API configuration. Supports demo/sandbox mode. ### Parameters #### Path Parameters - **_auth_creds** (dict) - Required - Authentication credentials dictionary with keys: access_token, consumer_key, consumer_secret, refresh_token - **_api_url** (str) - Optional - Base URL for the API endpoint. Default: 'https://api.darwinex.com' - **_api_name** (str) - Optional - API name component for URL construction. Default: 'darwininfo' - **_version** (float) - Optional - API version. Default: 1.5 - **_demo** (bool) - Optional - Flag to initialize in demo/sandbox mode. Default: False ### Example ```python from darwinexapis import DWX_Info_API auth_creds = { 'access_token': 'your_access_token', 'consumer_key': 'your_consumer_key', 'consumer_secret': 'your_consumer_secret', 'refresh_token': 'your_refresh_token' } info_api = DWX_Info_API(auth_creds, _version=2.0, _demo=True) ``` ``` -------------------------------- ### GET /investoraccounts/{id} (Account Details) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get detailed information for a specific investor account using its ID. ```APIDOC ## GET /investoraccounts/{id} ### Description Get detailed information for a specific account. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id} ``` -------------------------------- ### GET Trades by Status Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get trades for an investor account, filtered by their open or closed status. Supports pagination and product filtering. ```http GET https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/trades/{status}?productName={symbol}&page={page}&per_page={per_page} ``` -------------------------------- ### GET /investoraccounts/{id}/currentpositions (Open Positions) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get all open positions in an investor account. Supports filtering by DARWIN symbol. ```APIDOC ## GET /investoraccounts/{id}/currentpositions ### Description Get all open positions in account. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/currentpositions?productName={symbol} ### Parameters #### Query Parameters - **productName** (string) - Optional - DARWIN symbol to filter positions by. ``` -------------------------------- ### Initialize DWX_Graphics_Helpers Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Graphics_Helpers.md Instantiate the DWX_Graphics_Helpers class. No parameters are required for initialization. ```python from darwinexapis.MINIONS.dwx_graphics_helpers import DWX_Graphics_Helpers graphics = DWX_Graphics_Helpers() ``` -------------------------------- ### GET /investoraccounts/{id}/currentpositions (Open Positions) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get all open positions in an account. Supports optional filtering by product name. ```http GET https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/currentpositions?productName={symbol} ``` -------------------------------- ### GET /investoraccounts/{id}/trades/{status} Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get trades for a specific investor account, filtered by their open or closed status, with optional product and pagination filters. ```APIDOC ## GET /investoraccounts/{id}/trades/{status} (Trades by Status) ### Description Get trades filtered by open/closed status. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/trades/{status}?productName={symbol}&page={page}&per_page={per_page} ### Parameters #### Path Parameters - **status** (string) - Required - 'open' or 'closed' ``` -------------------------------- ### Initialize Darwinex API Client Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/README.md Instantiate the API client for production or sandbox environments. Ensure your authentication credentials are correct. ```python from darwinexapis import DWX_Info_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } # Production api = DWX_Info_API(auth_creds, _version=2.0, _demo=False) # Sandbox (recommended for testing) api = DWX_Info_API(auth_creds, _version=2.0, _demo=True) ``` -------------------------------- ### GET /investoraccounts/{id}/orders/{order_id} (Order Details) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get details for a specific order within an investor account using account and order IDs. ```APIDOC ## GET /investoraccounts/{id}/orders/{order_id} ### Description Get details for a specific order. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/orders/{order_id} ``` -------------------------------- ### Initialize DWX_Darwin_Data_Analytics_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Darwin_Data_Analytics_API.md Instantiate the API client with your Darwinex FTP credentials. Ensure you have the correct username, password, hostname, and port. ```python from darwinexapis import DWX_Darwin_Data_Analytics_API api = DWX_Darwin_Data_Analytics_API( dwx_ftp_user='your_username', dwx_ftp_pass='your_password', dwx_ftp_hostname='analytics.darwinex.com', dwx_ftp_port=21 ) ``` -------------------------------- ### GET /investoraccounts/{id}/conditionalorders/{status} (Conditional Orders List) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get conditional orders filtered by status. Supports optional filtering by product name and pagination. ```http GET https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/conditionalorders/{status}?productName={symbol}&page={page}&per_page={per_page} ``` -------------------------------- ### Initialize DWX_TickData_Reader_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Reader_API.md Instantiate the DWX_TickData_Reader_API class by providing paths to the bid and ask pickle files. ```python from darwinexapis import DWX_TickData_Reader_API reader = DWX_TickData_Reader_API( _bids_file='WS30_BID_2018-10-01_23.pkl', _asks_file='WS30_ASK_2018-10-01_23.pkl' ) ``` -------------------------------- ### GET /investoraccounts/{id}/conditionalorders/{status} (Conditional Orders List) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Get conditional orders filtered by status for a specific investor account. Supports filtering by product name and pagination. ```APIDOC ## GET /investoraccounts/{id}/conditionalorders/{status} ### Description Get conditional orders filtered by status. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/conditionalorders/{status}?productName={symbol}&page={page}&per_page={per_page} ### Parameters #### Path Parameters - **status** (string) - Required - Filter by order status: 'pending', 'executed', 'rejected', 'cancelled', 'deleted'. #### Query Parameters - **productName** (string) - Optional - DARWIN symbol to filter by. - **page** (integer) - Optional - Page number. - **per_page** (integer) - Optional - Results per page. ``` -------------------------------- ### Initialize DWX Trading API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Trading_API.md Instantiate the DWX Trading API client. Provide authentication credentials and optionally specify the API URL, name, version, and demo mode. The demo parameter defaults to True for sandbox environment usage. ```python from darwinexapis import DWX_Trading_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } trading_api = DWX_Trading_API(auth_creds, _version=1.1, _demo=True) ``` -------------------------------- ### GET /productmarket/status Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Check which trading operations are currently permitted for the authenticated user. ```APIDOC ## GET /productmarket/status (Permitted Operations) ### Description Check which trading operations are allowed. ### Method GET ### Endpoint https://api.darwinex.com/trading/1.1/productmarket/status ### Request Headers - Authorization: Bearer {access_token} ### Response #### Success Response - **trading_allowed** (boolean) - Indicates if trading is allowed. - **buy_allowed** (boolean) - Indicates if buying is allowed. - **sell_allowed** (boolean) - Indicates if selling is allowed. ### Response Example ```json { "trading_allowed": true, "buy_allowed": true, "sell_allowed": true, ... } ``` ``` -------------------------------- ### GET Permitted Trading Operations Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Check which trading operations are currently allowed for your account. Requires an authorization token. ```http GET https://api.darwinex.com/trading/1.1/productmarket/status Authorization: Bearer {access_token} ``` -------------------------------- ### GET /investoraccounts (Account List) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve all investor accounts for the authenticated user. Returns a list of account summaries. ```APIDOC ## GET /investoraccounts ### Description Retrieve all investor accounts for authenticated user. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts ### Request Headers ``` Authorization: Bearer {access_token} ``` ### Response #### Success Response (200) - **Response**: JSON array ```json [ { "id": 12345, "balance": 10000.00, "equity": 10500.00, ... } ] ``` ``` -------------------------------- ### GET /investoraccounts (Account List) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve all investor accounts for the authenticated user. Requires an access token for authorization. ```http GET https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts Authorization: Bearer {access_token} ``` ```json [ { "id": 12345, "balance": 10000.00, "equity": 10500.00, ... } ] ``` -------------------------------- ### DWX_Graphics_Helpers Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Graphics_Helpers.md Initializes the DWX_Graphics_Helpers class. No parameters are required. ```APIDOC ## DWX_Graphics_Helpers() ### Description Initializes the DWX_Graphics_Helpers class for creating visualizations. ### Parameters None ### Example ```python from darwinexapis.MINIONS.dwx_graphics_helpers import DWX_Graphics_Helpers graphics = DWX_Graphics_Helpers() ``` ``` -------------------------------- ### Initialize DWX_Quotes_API Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Quotes_API.md Instantiate the DWX_Quotes_API class with authentication credentials. Ensure you have your access token, consumer key, consumer secret, and refresh token. ```python from darwinexapis import DWX_Quotes_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } quotes_api = DWX_Quotes_API(auth_creds) ``` -------------------------------- ### Retrieve Last Downloaded DataFrame Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Downloader_API.md Use this method to get the most recently downloaded DataFrame from the internal asset database. ```python _return_pandas_dataframe_() ``` -------------------------------- ### DWX_API_AUTHENTICATION Class Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_API_Auth.md Initializes the DWX_API_AUTHENTICATION class with provided credentials. The _auth_creds dictionary must contain access_token, consumer_key, consumer_secret, and refresh_token. ```python from darwinexapis.API.DWX_API_Auth import DWX_API_AUTHENTICATION auth_creds = { 'access_token': '63ca7671-cf30-3e4d-a13e-0ae789183d73', 'consumer_key': '827c785e-f5ed-33bc-87e5-fb9854', 'consumer_secret': '827c785e-f5ed-33bc-87e5-fb9854', 'refresh_token': '827c785e-f5ed-33bc-87e5-fb9854fe1f80' } auth = DWX_API_AUTHENTICATION(auth_creds) ``` -------------------------------- ### DWX_TickData_Downloader_API Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Downloader_API.md Initializes the DWX_TickData_Downloader_API with FTP credentials to connect to the Darwinex FTP server. ```APIDOC ## DWX_TickData_Downloader_API(dwx_ftp_user, dwx_ftp_pass, dwx_ftp_hostname, dwx_ftp_port) ### Description Initializes the DWX_TickData_Downloader_API with FTP credentials to connect to the Darwinex FTP server. ### Parameters #### Path Parameters - **dwx_ftp_user** (str) - Required - Darwinex FTP username - **dwx_ftp_pass** (str) - Required - FTP password (NOT your Darwinex login password) - **dwx_ftp_hostname** (str) - Required - FTP server hostname (e.g., 'tickdata.darwinex.com') - **dwx_ftp_port** (int) - Required - FTP port number (typically 21) ### Example ```python from darwinexapis import DWX_TickData_Downloader_API ftp_creds = { 'username': 'your_username', 'password': 'your_ftp_password', 'ftpServer': 'tickdata.darwinex.com', 'port': 21 } downloader = DWX_TickData_Downloader_API( dwx_ftp_user=ftp_creds['username'], dwx_ftp_pass=ftp_creds['password'], dwx_ftp_hostname=ftp_creds['ftpServer'], dwx_ftp_port=ftp_creds['port'] ) ``` ``` -------------------------------- ### GET /products (DARWIN Universe) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve a paginated list of all available DARWIN products. Supports filtering by status and pagination. ```http GET https://api.darwinex.com/darwininfo/2.0/products?status={status}&page={page}&per_page={per_page} ``` ```json { "content": [ { "name": "THA.4.12", "quote": 150.25, "status": "ACTIVE", ... } ], "totalPages": 5, "currentPage": 0 } ``` -------------------------------- ### Initialize DWX_TickData_Reader_API and Load Data Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Reader_API.md Initializes the DWX_TickData_Reader_API with bid and ask files. Demonstrates loading raw tick data with spread calculation and integrity checks. ```python from darwinexapis import DWX_TickData_Reader_API # Initialize reader reader = DWX_TickData_Reader_API( _bids_file='WS30_BID_2018-10-01_23.pkl', _asks_file='WS30_ASK_2018-10-01_23.pkl' ) # Option 1: Load raw tick data with spread df_ticks = reader._get_symbol_as_dataframe_( _convert_epochs=True, _check_integrity=True, _calc_spread=True, _precision='tick' ) reader._save_df_to_csv(df_ticks, which_path='/data/') # Option 2: Load hourly OHLC df_hourly = reader._get_symbol_as_dataframe_( _convert_epochs=True, _precision='H' ) print(f"Hourly data shape: {df_hourly.shape}") print(df_hourly.head(10)) # Option 3: Load daily OHLC with specific columns df_daily = reader._get_symbol_as_dataframe_( _convert_epochs=True, _precision='D', _daily_start=22, _reindex=['WS30_mid_price'], _symbol_digits=5 ) # Option 4: Load with integrity checks df_validated = reader._get_symbol_as_dataframe_( _convert_epochs=True, _check_integrity=True, _calc_spread=True ) # Displays frequency statistics and hourly spread chart ``` -------------------------------- ### GET /products (Historical Quotes) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve historical end-of-day quotes for a DARWIN product. Requires an access token for authorization. ```http GET https://api.darwinex.com/darwininfo/2.0/products/{symbol}/history/quotes Authorization: Bearer {access_token} ``` ```json [ [1234567890000, 150.25], [1234567891000, 150.30] ] ``` -------------------------------- ### DWX_Trading_API Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_Trading_API.md Initializes the DWX Trading API client. Allows configuration of authentication, API endpoint, and environment (demo/live). ```APIDOC ## DWX_Trading_API Constructor ### Description Initializes the DWX Trading API client with specified authentication credentials, API URL, and environment settings. ### Parameters #### Path Parameters * **_auth_creds** (dict) - Required - Authentication credentials dictionary. * **_api_url** (str) - Optional - Base API URL. Defaults to 'https://api.darwinex.com'. * **_api_name** (str) - Optional - API name component. Defaults to 'trading'. * **_version** (float) - Optional - API version. Defaults to 1.0. * **_demo** (bool) - Optional - Initialize in demo/sandbox environment. Defaults to True. ### Request Example ```python from darwinexapis import DWX_Trading_API auth_creds = { 'access_token': 'your_token', 'consumer_key': 'your_key', 'consumer_secret': 'your_secret', 'refresh_token': 'your_refresh' } trading_api = DWX_Trading_API(auth_creds, _version=1.1, _demo=True) ``` ``` -------------------------------- ### Heartbeat Message Format Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Example of a heartbeat message received from the WebSocket API. These messages are used to keep the connection alive. ```json {"op":"hb","timestamp":1587838905842} ``` -------------------------------- ### DWX_API_AUTHENTICATION Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_API_Auth.md Initializes the authentication handler with provided credentials. The credentials dictionary must contain access_token, consumer_key, consumer_secret, and refresh_token. ```APIDOC ## DWX_API_AUTHENTICATION(_auth_creds) ### Description Initializes the authentication handler with provided credentials. The credentials dictionary must contain access_token, consumer_key, consumer_secret, and refresh_token. ### Parameters #### Path Parameters - **_auth_creds** (dict) - Required - Credentials dictionary with keys: access_token, consumer_key, consumer_secret, refresh_token ### Instance Attributes - **_auth_creds** (dict) - Stored credentials (updated when tokens refresh) - **expires_in** (float) - UNIX timestamp when current access token expires ### Credentials Dictionary Format ```json { "access_token": "string-token", "consumer_key": "oauth-consumer-key", "consumer_secret": "oauth-consumer-secret", "refresh_token": "refresh-token-string" } ``` ### Example ```python from darwinexapis.API.DWX_API_Auth import DWX_API_AUTHENTICATION auth_creds = { 'access_token': '63ca7671-cf30-3e4d-a13e-0ae789183d73', 'consumer_key': '827c785e-f5ed-33bc-87e5-fb9854', 'consumer_secret': '827c785e-f5ed-33bc-87e5-fb9854', 'refresh_token': '827c785e-f5ed-33bc-87e5-fb9854fe1f80' } auth = DWX_API_AUTHENTICATION(auth_creds) ``` ``` -------------------------------- ### GET /investoraccounts/{id}/orders/executed Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve executed orders for a specific investor account, with optional filtering by product name and pagination. ```APIDOC ## GET /investoraccounts/{id}/orders/executed (Executed Orders) ### Description Retrieve executed orders for a product. ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/orders/executed?productName={symbol}&page={page}&per_page={per_page} ``` -------------------------------- ### GET Account Leverage Information Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve the current leverage settings, maximum leverage, and margin required for a specific investor account. ```http GET https://api.darwinex.com/trading/1.1/investoraccounts/{account_id}/leverage ``` -------------------------------- ### launch_loop_again() Method Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Creates and sets up a new event loop, preparing the API for subsequent calls to the run() method. ```python launch_loop_again() ``` -------------------------------- ### Get Trades by Status Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_AccInfo_API.md Retrieves trades filtered by their open or closed status for a given account and DARWIN product. Supports pagination. ```python _Get_Trades_by_Status_(_id=0, _darwin='PLF.4.1', _status='open', _page=0, _perpage=1) ``` ```python open_trades = acc_api._Get_Trades_by_Status_( _id=12345, _darwin='THA.4.12', _status='open' ) closed_trades = acc_api._Get_Trades_by_Status_( _id=12345, _darwin='THA.4.12', _status='closed', _page=0, _perpage=10 ) ``` -------------------------------- ### Buy at Market Order Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/DOCUMENTATION_MANIFEST.txt Shows how to place a market order using the DWX_Trading_API. The order details are provided in a JSON format. Ensure the trading API object is initialized. ```python trading._Buy_At_Market_(_id=12345, _order=order_json) ``` -------------------------------- ### Quote Message Format Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Example of a quote message received from the WebSocket API. Contains the product name, quote price, and timestamp. ```json { "productName": "DWZ.4.7", "quote": 150.25, "timestamp": 1687876543210 } ``` -------------------------------- ### Manual Async Usage of subscribe() Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Demonstrates how to manually run the asynchronous subscribe coroutine using asyncio's event loop. Includes handling for KeyboardInterrupt to stop the process. ```python import asyncio # Manually run the coroutine ws_api._active = True loop = asyncio.get_event_loop() try: loop.run_until_complete(ws_api.subscribe(['THA.4.12'])) except KeyboardInterrupt: ws_api._active = False loop.close() ``` -------------------------------- ### GET /investoraccounts/{id}/leverage Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve the current leverage settings, including current, maximum, and required margin for a specific investor account. ```APIDOC ## GET /investoraccounts/{id}/leverage (Account Leverage) ### Description Get current leverage setting for account. ### Method GET ### Endpoint https://api.darwinex.com/trading/1.1/investoraccounts/{account_id}/leverage ### Response #### Success Response - **current_leverage** (float) - The current leverage ratio. - **max_leverage** (float) - The maximum available leverage ratio. - **margin_required** (float) - The amount of margin required for the current positions. ### Response Example ```json { "current_leverage": 2.0, "max_leverage": 10.0, "margin_required": 500.00 } ``` ``` -------------------------------- ### GET /investoraccounts/{id}/conditionalorders/{order_id} (Conditional Order) Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/endpoints.md Retrieve details for a conditional order (stop-loss/take-profit) using account and order IDs. ```APIDOC ## GET /investoraccounts/{id}/conditionalorders/{order_id} ### Description Retrieve details for a conditional order (stop-loss/take-profit). ### Method GET ### Endpoint https://api.darwinex.com/investoraccountinfo/2.0/investoraccounts/{account_id}/conditionalorders/{order_id} ``` -------------------------------- ### DWX_TickData_Reader_API Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_TickData_Reader_API.md Initializes the DWX_TickData_Reader_API with paths to bid and ask tick data pickle files. ```APIDOC ## DWX_TickData_Reader_API Constructor ### Description Initializes the DWX_TickData_Reader_API with paths to bid and ask tick data pickle files. ### Parameters #### Path Parameters - **_bids_file** (str) - Required - Path to pickle file containing bid tick data - **_asks_file** (str) - Required - Path to pickle file containing ask tick data ### Example ```python from darwinexapis import DWX_TickData_Reader_API reader = DWX_TickData_Reader_API( _bids_file='WS30_BID_2018-10-01_23.pkl', _asks_file='WS30_ASK_2018-10-01_23.pkl' ) ``` ``` -------------------------------- ### DWX_WebSocket_API Class Constructor Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_WebSocket_API.md Initializes the DWX_WebSocket_API with authentication credentials and API endpoint. Authentication credentials are required. ```python DWX_WebSocket_API(_auth_creds='', _api_url='ws://api.darwinex.com/quotewebsocket/1.0.0', _api_name='', _version=0.0) ``` -------------------------------- ### Get Executed Orders Source: https://github.com/darwinex/darwinexapis/blob/master/_autodocs/api-reference/DWX_AccInfo_API.md Retrieves executed orders for a specified account and DARWIN product, with support for pagination. Useful for auditing trade history. ```python _Get_Executed_Orders_(_id=0, _darwin='PLF.4.1', _page=0, _perpage=1) ``` ```python executed = acc_api._Get_Executed_Orders_( _id=12345, _darwin='THA.4.12', _page=0, _perpage=50 ) print(f"Total executed: {len(executed)}") ```