How to Set Up OpenAI & xAI APIs on MQL5

30 March 2025, 02:08
Thi Ngoc Tram Le
0
773

Steps to Set Up OpenAI and Grok APIs for trading bot MT5

This guide helps users set up APIs for the trading bot MT5 to enhance trading with AI

Initial step is to go into MT5, ensure
 your MT5 terminal is running, then configure the setting as follows.
Then press OK.


Steps to Set Up OpenAI API for trading bot MT5
This guide will walk you through how to obtain and set up your OpenAI API key for use with OpenAI trading bot MT5.
This is a separate service from the web version of ChatGPT (ChatGPT Plus / Pro) and does not require you to subscribe to a paid ChatGPT plan.
Instead, you can use the API features by funding your OpenAI account with a minimum of $5. The following steps are explained with reference to screenshots.

Step 1: Create an OpenAI account from the link below.
If you already have an account, you can skip this step.
 


Step 2: After logging in, you can manage your API keys from the link below: https://platform.openai.com/api-keys
You can create and delete multiple API keys here. However, note that if you close the page after creating a key once, you will not be able to view the same key again.
You can issue new keys as many times as you like for free, so if you lose your key, you can recreate it. Next, click on the "Create new secret key" button.

Step 3: Fill in a name (any name you want).
Step 4: Click "Create secret key".
Step 5: Click "Copy" (Please note that once you close it, you will not be able to view it again.). You should store it in a secret place and not let anyone else know. If you lose it, it's okay, you can just delete it and create a new one, you can do this countless times. 


Step 6: Paste the key into the input field of trading MT5 labeled "OpenAI API Key". This will allow the EA to communicate with OpenAI's API.
 
Step 7: Go to the link below to add a payment method as you need to spend a minimum of $5 to use the OpenAI API.
 



Steps to Set Up Grok API for trading bot MT5

Step 1: Visit the link below. https://x.ai/api
Step 2: Click "Start Building".
Step 3: Sign up if you don't have an account, otherwise log in.
Step 4: Click "Authorize app".
 
Step 5: Click "Continue".
Step 6: Click "Setup billing". 

Step 7: Click "Enable".
Step 8: Click "Purchase credits" (you need to spend a minimum of $5-$10 to use the Grok API key). 


Step 9: Click "Complete billing profile".
Step 10: Fill in your information and click "Save billing Address", then pay to purchase the API. 

Step 11: Click on the "API keys" tab (your API management page). 

Step 12: Click "Create API key".
Step 13: Fill in a name for the API key. 

Step 14: Click "Save".
Step 15: Copy.
Step 16: Paste the API key into the input field of trading bot MT5

Steps to Set Up Gemini API for trading bot MT5

Step 1: Go to the following link: https://ai.google.dev/gemini-api/docs/api-key
Step 2: Click on the "Get a Gemini API Key in Google AI Studio" button.



Step 3: Log in to your Google account.

Step 4: Click the "Create API Key" button.



Step 5: Click the "Copy" button.
Step 6: Paste the API key into the input field of trading bot MT5.



Setting Up Billing Gemini API for trading bot MT5
Step 1: Go to the following link: https://ai.google.dev/gemini-api/docs/api-key
Step 2: Select "Billing info".
Step 3: Click the "Upgrade to the Gemini API paid tier" button.
Step 4: Click "Set up Billing".

Step 5: Click "Manage billing accounts".
Step 6: Click "Create account".
Step 7: Fill in the information and click the "Continue" button.

Step 8: Click the "Change" button to fill in your Payments profile information. Then, enter your payment card details.


Google allows you to use the API key first without needing to deposit funds, so you can start using it immediately.
However, you need to monitor your usage at https://console.cloud.google.com/

Step-by-step guide to getting a Claude AI API Key

Step 2: Press the Start building button

Step 3: Register for an account or log in (if you already have one)

Step 4: Press Individual

Step 5: Press Buy credits



Step 6: Enter your payment method and complete payment

Step 7: Press Get API keys

Step 8: Paste the API key into EA in the corresponding Claude API Key field (same as with other AIs)

Remember to keep your API key secure and do not share it publicly.





Important Notes
  • Purchasing the Grok and OpenAI APIs is like renting a powerful service on demand. You pay to use its capabilities each time you need them, and the cost will depend on the amount of resources you consume (number of requests, number of tokens, etc.). This cost is separate from the paid plans of Grok or OpenAI. 
  • You can check the usage status of the OpenAI API here: https://platform.openai.com/settings/organization/usage
  • You can check the usage status of the Grok API here: https://console.x.ai/team/default/billing/credits

Now we are ready to use the OpenAI API, Grok API, Gemini API and Claude API in trading bot MT5.
If you have any questions, please contact the community and support.