10-20-2023, 12:53 PM
In this project, I will built a Django Dashboard that is connected with MT4 and MT5. I will post signals on Django Dashboard. MT4 SignalsEA and MT5 SignalsEA will read these signals and open and closed trades on MT4 and MT5 and in return inform Django that the signals have been successfully copied or their was an error. This Django Dashboard front end will be in React. So I will be easily able to open it on my mobile phone. The idea is the use the mobile phone to open and close signals and monitor multiple MT4 and MT5 accounts that can be upto 50-100. First I created SignalDashboard project folder and then I create a backend folder in it and from this folder I launched virtual environment:
python -m venv venv
.\venv\Scripts\activate
First I install virtual environment and then I activated it. Now create a text file in SignalDashboard/bankend folder and add:
Django==4.0
Now install Django:
pip install -r requirements.txt
Now create the backend project:
django-admin startproject backend .
For now we will be using sqlite3. Run migrations:
python manage.py migrate
Install Django Rest Framework:
pip install djangorestframework
Now create the signals app:
python manage.py startapp signals
These are useful shell commands
# python manage.py dbshell
#python manage.py flush
#PRAGMA table_info(SignalEA_signalea);
#python manage.py shell
#python manage.py makemigrations
#python manage.py migrate
#python manage.py runserver
#python manage.py startapp Signal
#python manage.py validate
Create an app signals within the backend folder.
python manage.py startapp signals
Now define the model in model.py of the signals and then enter that in admin.py and make entry in the backend settings.py telling about the restframework and signals app.
admin.site.register(Signal)
You also need to tell urls.py in backend to check urls.py in signals app.
path('signals/', include('signals.urls')
Then you have to make serializers.py file in signals app and make a serializers class. After that you have views .py.
Now I made the models. One is Signal. I have generated this JSON object when running the server on localhost:
http://127.0.0.1:8000/signals/signals?format=json
{"signals":[{"id":1,"signal":"buylimit\r\nGBPUSD\r\n240\r\n1\r\n0\r\n3\r\n2\r\nLiteFinance"},{"id":2,"signal":"selllimit\r\nEURUSD\r\n240\r\n0\r\n0\r\n3\r\n1"},{"id":3,"signal":"selllimit\r\nEURNZD\r\n240\r\n2\r\n0\r\n3\r\n1"}]}
These are the request headers:
Accept
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Encoding
gzip, deflate, br
Accept-Language
en-US,en;q=0.5
Connection
keep-alive
Host
127.0.0.1:8000
Referer
http://127.0.0.1:8000/signals/signals?format=api
Sec-Fetch-Dest
document
Sec-Fetch-Mode
navigate
Sec-Fetch-Site
same-origin
Sec-Fetch-User
?1
Upgrade-Insecure-Requests
1
User-Agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
These are the response headers:
Allow
GET, HEAD, OPTIONS
Content-Length
228
Content-Type
application/json
Cross-Origin-Opener-Policy
same-origin
Date
Tue, 07 Nov 2023 13:51:57 GMT
Referrer-Policy
same-origin
Server
WSGIServer/0.2 CPython/3.8.8
Vary
Accept, Cookie
X-Content-Type-Options
nosniff
X-Frame-Options
DENY
When I try to use Webrequest on MT4. It gives an invalid array error. I need to use Wireshark to check what is happening.
Frame 196: 55 bytes on wire (440 bits), 55 bytes captured (440 bits) on interface \Device\NPF_Loopback, id 0
Null/Loopback
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 35600, Dst Port: 53338, Seq: 173, Ack: 196, Len: 11
[3 Reassembled TCP Segments (158 bytes): #192(17), #194(130), #196(11)]
Hypertext Transfer Protocol
HTTP/1.0 200 OK\r\n
Content-Type: application/json\r\n
Content-Length: 11\r\n
Server: Werkzeug/0.16.0 Python/3.11.3\r\n
Date: Wed, 08 Nov 2023 04:19:11 GMT\r\n
\r\n
[HTTP response 2/2]
[Time since request: 0.001118000 seconds]
[Prev response in frame: 188]
[Request in frame: 190]
[Request URI: http://127.0.0.1:35600/api/v2/api_lock]
File Data: 11 bytes
JavaScript Object Notation: application/json
Object
python -m venv venv
.\venv\Scripts\activate
First I install virtual environment and then I activated it. Now create a text file in SignalDashboard/bankend folder and add:
Django==4.0
Now install Django:
pip install -r requirements.txt
Now create the backend project:
django-admin startproject backend .
For now we will be using sqlite3. Run migrations:
python manage.py migrate
Install Django Rest Framework:
pip install djangorestframework
Now create the signals app:
python manage.py startapp signals
These are useful shell commands
# python manage.py dbshell
#python manage.py flush
#PRAGMA table_info(SignalEA_signalea);
#python manage.py shell
#python manage.py makemigrations
#python manage.py migrate
#python manage.py runserver
#python manage.py startapp Signal
#python manage.py validate
Create an app signals within the backend folder.
python manage.py startapp signals
Now define the model in model.py of the signals and then enter that in admin.py and make entry in the backend settings.py telling about the restframework and signals app.
admin.site.register(Signal)
You also need to tell urls.py in backend to check urls.py in signals app.
path('signals/', include('signals.urls')
Then you have to make serializers.py file in signals app and make a serializers class. After that you have views .py.
Now I made the models. One is Signal. I have generated this JSON object when running the server on localhost:
http://127.0.0.1:8000/signals/signals?format=json
{"signals":[{"id":1,"signal":"buylimit\r\nGBPUSD\r\n240\r\n1\r\n0\r\n3\r\n2\r\nLiteFinance"},{"id":2,"signal":"selllimit\r\nEURUSD\r\n240\r\n0\r\n0\r\n3\r\n1"},{"id":3,"signal":"selllimit\r\nEURNZD\r\n240\r\n2\r\n0\r\n3\r\n1"}]}
These are the request headers:
Accept
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Encoding
gzip, deflate, br
Accept-Language
en-US,en;q=0.5
Connection
keep-alive
Host
127.0.0.1:8000
Referer
http://127.0.0.1:8000/signals/signals?format=api
Sec-Fetch-Dest
document
Sec-Fetch-Mode
navigate
Sec-Fetch-Site
same-origin
Sec-Fetch-User
?1
Upgrade-Insecure-Requests
1
User-Agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
These are the response headers:
Allow
GET, HEAD, OPTIONS
Content-Length
228
Content-Type
application/json
Cross-Origin-Opener-Policy
same-origin
Date
Tue, 07 Nov 2023 13:51:57 GMT
Referrer-Policy
same-origin
Server
WSGIServer/0.2 CPython/3.8.8
Vary
Accept, Cookie
X-Content-Type-Options
nosniff
X-Frame-Options
DENY
When I try to use Webrequest on MT4. It gives an invalid array error. I need to use Wireshark to check what is happening.
Frame 196: 55 bytes on wire (440 bits), 55 bytes captured (440 bits) on interface \Device\NPF_Loopback, id 0
Null/Loopback
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 35600, Dst Port: 53338, Seq: 173, Ack: 196, Len: 11
[3 Reassembled TCP Segments (158 bytes): #192(17), #194(130), #196(11)]
Hypertext Transfer Protocol
HTTP/1.0 200 OK\r\n
Content-Type: application/json\r\n
Content-Length: 11\r\n
Server: Werkzeug/0.16.0 Python/3.11.3\r\n
Date: Wed, 08 Nov 2023 04:19:11 GMT\r\n
\r\n
[HTTP response 2/2]
[Time since request: 0.001118000 seconds]
[Prev response in frame: 188]
[Request in frame: 190]
[Request URI: http://127.0.0.1:35600/api/v2/api_lock]
File Data: 11 bytes
JavaScript Object Notation: application/json
Object
Subscribe My YouTube Channel:
https://www.youtube.com/channel/UCUE7VPo...F_BCoxFXIw
Join Our Million Dollar Trading Challenge:
https://www.doubledoji.com/million-dolla...challenge/