Expiry day Straddle Algo Trading
alembic upgrade head
Install using apt or pip3 sudo apt install gunicorn pip3 install gunicorn
gunicorn --bind 0.0.0.0:8080 wsgi:app
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04
- sudo apt install nginx
- sudo systemctl status nginx
- sudo systemctl stop nginx
- sudo systemctl start nginx
- sudo systemctl restart nginx
- sudo nginx -t
- sudo -u postgres psql
- CREATE DATABASE algotrading;
- CREATE USER algobot WITH PASSWORD 'algobot123';
- GRANT ALL PRIVILEGES ON DATABASE algotrading TO algobot;
- alembic upgrade head
- export PYTHONPATH=/home/ubuntu/ExpiryStraddleAlgoTrading
- python3 dashboard/db/db_init_table.py
- sudo nano /etc/systemd/system/gunicorn.service
- Add the following contents
[Unit] Description=Gunicorn instance to serve myproject After=network.target [Service] User=ubuntu Group=ubuntu WorkingDirectory=/home/ubuntu/ExpiryStraddleAlgoTrading #Environment="PATH=/home/sammy/myproject/myprojectenv/bin" ExecStart=/usr/bin/gunicorn --workers 2 --bind unix:gunicorn.sock -m 007 wsgi:app [Install] WantedBy=multi-user.target
- sudo systemctl start gunicorn
- sudo systemctl enable gunicorn
- sudo systemctl status gunicorn
- Test the socket activation mechanism, curl --unix-socket /home/ubuntu/ExpiryStraddleAlgoTrading/gunicorn.sock localhost
- sudo nano /etc/nginx/sites-available/algotrading-dashboard
server { listen 80; server_name your_domain www.your_domain; location / { include proxy_params; proxy_pass http://unix:/home/ubuntu/ExpiryStraddleAlgoTrading/gunicorn.sock; } }
- sudo ln -s /etc/nginx/sites-available/algotrading-dashboard /etc/nginx/sites-enabled
- sudo nginx -t
- sudo systemctl restart nginx
- Edit /etc/nginx/nginx.conf change user to ubuntu. Else you will see permission issue while connecting to the socket.
https://redis.io/docs/install/install-redis/install-redis-on-linux/
- sudo apt install lsb-release curl gpg
- curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
- echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
- sudo apt update
- sudo apt install redis
https://stackoverflow.com/questions/22256124/cannot-create-a-database-table-named-user-in-postgresql
- INSERT INTO "user" (username, password, role) VALUES ('NIHKA1018', 'password', 'Admin');
- select * from "user";
14 4 * * 1-5 cd /home/ubuntu/ExpiryStraddleAlgoTrading; python3 main.py --clean-up
15 4 * * 1-5 cd /home/ubuntu/ExpiryStraddleAlgoTrading; python3 main.py --market-feeds --option-type CE
15 4 * * 1-5 cd /home/ubuntu/ExpiryStraddleAlgoTrading; python3 main.py --market-feeds --option-type PE
18 4 * * 1-5 cd /home/ubuntu/ExpiryStraddleAlgoTrading; python3 main.py --trading
# Kill if the process is still running once the process is exited
30 10 * * * pkill -f main.py