/tradegame.org

Open-Source Trading Game Based on Real Market Data

Primary LanguagePython

Beware of vulnerability

Since my final project is now graded, the time has come to ammend issues I faced during testing stage of deployed application. The most important is the low security on the mongoDB side allowing for some form of data extraction. My mongoDB database was constatnly exploited by unknown. Beware of this before pushing things into production.

Setup Instructions

A. MongoDB Database

  1. Install MongoDB

Fedora 35 MongoDB installation instruction can be found HERE, on my GitHub Pages.

  1. Install Docker

  2. Install docker-compose

B. Python/FastAPI Backend

  1. Create virtual environment (called "trade_env" or whatever you like)
python3 -m venv trade_env

or **

virtualenv tradegame_venv
  1. Activate the virtual environemnt
trade_env\Scripts\activate.bat

or **

source tradegame_venv/bin/activate
  1. Navigate to the root directory (where the three directories backend, database and frontend are present)

  2. Install Python packages to the virtual environment

pip install -r backend/requirements.txt

If pip doesnt work, use code below and run pip install again:

python -m pip install -U --force pip

C. React Frontend

  1. Install Node Package Manager (npm)
  2. Navigate into /frontend directory (where package.json is present)
  3. Install the React dependencies with npm
npm install

Run Instructions

A. MongoDB Database

  1. Navigate to the root directory (where the three directories backend, database and frontend are present) or start your existing MongoDB server

  2. Make sure you have MongoDB installed on your machine and system variable path is set correctly.

Again: GitHub Pages regarding MongoDB installation on Fedora 35.

Remember to set up the MongoDB URL and db-name in the /TG-backend/toml.conf file

  1. Start MongoDB server with mongod
mongod --dbpath=database

OR

Run :

docker-compose up

This will spin your Docker container with the mongoDB running on it.

(if you modified the docker-compose.yml - also remember to make sure it agrees with the .toml file)

  1. The MongoDB server will be hosted at its default port

B. Python/FastAPI Backend

  1. Navigate into /backend directory (where main.py is present)

  2. Activate the virtual environemnt

trade_env\Scripts\activate.bat

or

trade_env/bin/activate
  1. Start FastAPI server
uvicorn main:app --reload

If it doesnt work, use:

python -m uvicorn main:app --reload

*** If above return an error:

ERROR:    Error loading ASGI app. Could not import module "app".

It probably means your database is not running, or you are trying to execute uvicorn server while (with cmd) beeing in the incorrect directory. Your new MongoDB installation might also require super user privelages.

Try:

sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb
sudo service mongod start

try also:

sudo service mongod restart

then:

sudo mongod --dbpath=database
  1. The FastAPI server will be hosted at its default port 3000

  2. To access SwaggerUI for API testing and documentation, goto http://localhost:3000/docs

C. React Frontend

  1. Navigate to /frontend directory (where package.json is present)
  2. Start React Web Application
npm start
  1. The React web application will be hosted at its default port 8000, goto http://localhost:8000/