Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Django Signals Dashboard
#1

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

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/
Reply
#2

Frontend is in React. Run this command in SignalDashboard directory:

npm install -g create-react-app

Now create the frontend app:

create-react-app frontend

Now cd frontend and npm start.Create npm add react-router-dom@6 . In Index.js add import { BrowserRouter } from "react-router-dom"; and
<BrowserRouter>
<App />
</BrowserRouter>

Now add react bootstrap npm add react-bootstrap bootstrap . Import react bootstrap in Index.js import 'bootstrap/dist/css/bootstrap.min.css'; In src directory create pages and in that Home.jsx. Now go to backoffice and install pip install django-cors-headers . Add 'corsheaders', to settings.py.

I have simply dropped the idea of using React on the frontend. Instead I will use Django admin panel and customize it to fit my needs. I will use Django admin panel on mobile to send signals to MT4 and MT5 platforms and receive messages from them. I have shifted the whole project to pythonanywhere.com. They give a free account upto 512 MB. I have setup all the files like I did on my laptop but I am getting this error that I need to resolve:

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This is a path problem that arises when deploying Django app on a production site. The following link solved the problem:

https://help.pythonanywhere.com/pages/De...goProject/

I had to provide the path so that Django app is discovered. I have done that and I have successfully tested GET request on MT4 and MT5. POST request is giving Bad Request Error. I am working on it. I don't have to work on the frontend as Django Admin panel is responsive by default and is serving my purpose very well. I want to change the home page. For that I made a pages app with python manage.py startapp pages. I also created a templates folder in the project:
── django_project
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
| └── pages
| ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── templates
├── home.html
└── manage.py

In this templates folder I have created home.html.
# django_project/settings.py
TEMPLATES = [
{
...
"DIRS": [BASE_DIR / "templates"], # new
...
},
]

Then in views I made this change:
# pages/views.py
from django.views.generic import TemplateView

class HomePageView(TemplateView):
template_name = "home.html"

Then mentioned the path in project urls.py and pages urls.py. Now if you are using disk space and want to clear the cache, you should use the following bash command:

rm -rf ~/.cache/*

I am trying to figure out how to schedule a post that will be created a few hours and a day later.

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/
Reply
#3

I solved a major problem in the Django app that involved scheduling the signals. I made another model manager and named it PublishedManager. In that I over rode the queryset and solved the problem. Now I am trying to commit the code files to github repository:

Code:
git init
git config --global push.default simple
git add *
git add .gitignore
git status
git config --global user.email "youremail@umich.edu"
git config --global user.name "Your X. Name"
git config --global credential.helper cache   # Optional but convienent
git config --global credential.helper 'cache --timeout=604800'  # Optional but convienent
git commit -m "first commit"
git remote add origin https://github.com/--your-github-acct--/django_projects.git
git push -u origin main
(enter id and password for git)

I made changes to .gitignore but it is not being reflected when I check with git status.

Make changes in .gitignore file.
Run git rm -r --cached . command.
Run git add . command
git commit -m "Commit message" or just git commit or continue working.

Now again check with git status.

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/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)