diff --git a/DBManagement/DataManagement.py b/DBManagement/DataManagement.py index 3d7b17637fd525846e5fbce532c622a137f6136f..2291d0276aed5358c21d1a139ddcb89bde7505db 100644 --- a/DBManagement/DataManagement.py +++ b/DBManagement/DataManagement.py @@ -9,6 +9,7 @@ from bson.objectid import ObjectId import sqlite3 +import os from sqlite3 import Error pathToDb = "../DBManagement/tradeDB.sqlite" @@ -55,11 +56,15 @@ def export_Simulation_All(data): #create mongo conenction to db def create_connection_DB(db_file): conn = None - try: - conn = sqlite3.connect(db_file) - except Error as e: - print(e) - return conn + if not os.path.isfile(db_file): + print("\nPlease download the database here: https://eswys.ch/tmp/tradeDB.sqlite.zip\nAnd put it in the directory DBManagement/ with the name 'tradeDB.sqlite' \n") + os._exit(0) + else: + try: + conn = sqlite3.connect(db_file) + except Error as e: + print(e) + return conn #Get all simulation results for a given strategy def getSimulationResults(strat): trades_db = get_database() @@ -85,11 +90,15 @@ def getHistoCandles(symbol,dateStart,dateEnd): conn = create_connection_DB(pathToDb) print(type(conn)) print(conn) - with conn: - cur = conn.cursor() - cur.execute("SELECT CANDLEDATA, LOGTIME_UTC FROM SYMBOLDATA WHERE MARKETSYMBOL=? AND LOGTIME_UTC BETWEEN ? AND ? ORDER BY LOGTIME_UTC",(symbol,dateStart,dateEnd)) - rows = cur.fetchall() - return rows + try: + with conn: + cur = conn.cursor() + cur.execute("SELECT CANDLEDATA, LOGTIME_UTC FROM SYMBOLDATA WHERE MARKETSYMBOL=? AND LOGTIME_UTC BETWEEN ? AND ? ORDER BY LOGTIME_UTC",(symbol,dateStart,dateEnd)) + rows = cur.fetchall() + return rows + except: + print("\nDatabase is invalid, please download the database here: https://eswys.ch/tmp/tradeDB.sqlite.zip\nAnd put it in the directory DBManagement/ with the name 'tradeDB.sqlite' \n") + os._exit(0) #Get multilevel LOB def getHistoLimitOrderBook(symbol): conn = create_connection_DB(pathToDb) diff --git a/main/backend.py b/main/backend.py index 6680d4295c6d5f0b2dd7ef0e6e4212f3bcc3b25c..5c7a6321c4888e6a4f04044321a1b5518e52d525 100644 --- a/main/backend.py +++ b/main/backend.py @@ -93,7 +93,7 @@ def index(): figJson = createFigPyplot(market,tmpOrder) results = getResults() reponse = make_response(render_template('index.html', inProgress=simulationInProgress, fig=figJson, res=results, err=dictError, stickyForm=stickyForm)) - reponse.headers['Content-Security-Policy'] = "style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.5.1/plotly.min.js https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js https://fonts.googleapis.com/ https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" + # reponse.headers['Content-Security-Policy'] = "style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.5.1/plotly.min.js https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js https://fonts.googleapis.com/ https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" if resetParams == 2: resetParams = 1 dictError = {} @@ -257,6 +257,10 @@ def uploadFile(): try: fileData = file.read() z = zipfile.ZipFile(io.BytesIO(fileData)) + try: z.testzip() + except RuntimeError: + lstErrorSimulations.append("Le fichier ZIP ("+nameZIP+") est corrompu ou protégé par un mot de passe.") + continue for filename in z.namelist(): if filename.startswith('__MACOSX/'): continue @@ -298,7 +302,7 @@ def uploadFile(): except json.JSONDecodeError: lstErrorSimulations.append("Le contenu du fichier JSON ("+ filename +") dans le ZIP ("+nameZIP+") n'est pas valide.") continue - except zipfile.BadZipFile: + except zipfile.BadZipFile or zipfile.LargeZipFile: lstErrorSimulations.append("Le fichier ZIP ("+ filename +") est invalide ou corrompu.") continue else: @@ -333,9 +337,12 @@ def addSimulation(): @app.route("/progress") def progress(): - if dec.sim.progressBar < 60: - dec.sim.progressBar += 4 - return jsonify({'progress': dec.sim.progressBar}) + if dec.sim != None: + if dec.sim.progressBar < 60: + dec.sim.progressBar += 4 + return jsonify({'progress': dec.sim.progressBar}) + else: + return redirect('/') @app.route("/deleteSimulation", methods=["GET"]) def deleteSimulation(): @@ -704,6 +711,7 @@ def getResults(): dict['moneyLosses'][i] = dict['startBalance'][i] * (round(dict['losses'][j],2) * 0.01) return dict + def getKeys(): privateKeyPath = "privateKey.pem" publicKeyPath = "publicKey.pem" diff --git a/main/simulation.py b/main/simulation.py index 4efadca07a6674255dc13aac4f01ed259d3c4f73..d6c11bc369f98881fbeb818933c3762b55ae24a4 100644 --- a/main/simulation.py +++ b/main/simulation.py @@ -277,7 +277,6 @@ class Simulation: #Check is order placed is winning or not def checkStatusOrder(self, order): - print(order) #order = ast.literal_eval(order) if order["type"] =="AV": end= self.isWinningAV(order) @@ -287,6 +286,7 @@ class Simulation: def calculateUpRatedPrice(self,price,rate): + # print(price+price*rate) return price+price*rate def calculateDownRatedPrice(self,price,rate): diff --git a/main/templates/index.html b/main/templates/index.html index d3617c01894af2717fc161de0cb700524f57c241..e6a4506986d2a7ef37859e8cbc0b6478d9f11ef3 100644 --- a/main/templates/index.html +++ b/main/templates/index.html @@ -96,7 +96,6 @@ </div> --> <div class="mb-4 pb-2"> - <div class="form-inline"> <label class="form-label my-1 mr-2" for="indicator">Indicateur technique</label> diff --git a/main/templates/mySimulation.html b/main/templates/mySimulation.html index aab7f56b31ecfdc03e65051e1de7c47485392fde..9b119ed6a8eae93040dfbd4c0e8035a00883e6e8 100644 --- a/main/templates/mySimulation.html +++ b/main/templates/mySimulation.html @@ -91,8 +91,12 @@ </div> <div class="row"> <div class="col-md-6 mb-2"> - <span class="badge badge-pill bg-warning">Stratégie</span><span> {{ - simulation['params']['indicatorSelect'] }}</span> + <span class="badge badge-pill bg-warning">Indicateur</span><span> + {% if simulation['params']['indicatorSelect'] == "random"%} + Aléatoire + {% else %} + {{ simulation['params']['indicatorSelect'] }} + {% endif %}</span> </div> <div class="col-md-6 mb-2"> <span class="badge badge-pill bg-warning">Winrate</span><span> {{ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..c7ecc1540f17df53b241a61961ab3dbe3ecf6714 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,40 @@ +blinker==1.6.2 +bson==0.5.10 +certifi==2023.5.7 +cffi==1.15.1 +charset-normalizer==3.2.0 +click==8.1.4 +contourpy==1.1.0 +cryptography==41.0.1 +cycler==0.11.0 +Flask==2.3.2 +fonttools==4.40.0 +gevent==22.10.2 +greenlet==2.0.2 +idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.1.2 +kiwisolver==1.4.4 +MarkupSafe==2.1.3 +matplotlib==3.7.2 +numpy==1.25.0 +packaging==23.1 +pandas==2.0.3 +pandas-ta==0.3.14b0 +Pillow==10.0.0 +plotly==5.15.0 +pycparser==2.21 +pyparsing==3.0.9 +python-dateutil==2.8.2 +pytz==2023.3 +requests==2.31.0 +scipy==1.11.1 +six==1.16.0 +tenacity==8.2.2 +tzdata==2023.3 +urllib3==2.0.3 +websocket-client==1.6.1 +websockets==11.0.3 +Werkzeug==2.3.6 +zope.event==5.0 +zope.interface==6.0