from flask import Flask, render_template, redirect, url_for, request, session
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
import ccxt
import pandas as pd
import numpy as np
import json
from datetime import datetime
import matplotlib.pyplot as plt

# Flask App Setup
app = Flask(__name__)
app.secret_key = 'your_secret_key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///trading_bot.db'
db = SQLAlchemy(app)

# User Model
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)
    demo_account = db.Column(db.Boolean, default=True)
    autotrader_enabled = db.Column(db.Boolean, default=False)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

# Trading Bot Initialization
with open('config.json') as f:
    config = json.load(f)

class CryptoTradingBot:
    def init(self, api_key, api_secret):
        self.exchange = ccxt.binance({
            'apiKey': api_key,
            'secret': api_secret,
        })

    # Other methods from the previous code …

    def fetch_data(self, symbol, limit=500):
        bars = self.exchange.fetch_ohlcv(symbol, timeframe='1h', limit=limit)
        df = pd.DataFrame(bars, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
        df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
        return df

@app.route('/')
def index():
    if 'user_id' not in session:
        return redirect(url_for('login'))
    user = User.query.get(session['user_id'])
    return render_template('index.html', username=user.username, demo_account=user.demo_account, autotrader_enabled=user.autotrader_enabled)

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        user = User.query.filter_by(email=email).first()
        if user and user.check_password(password):
            session['user_id'] = user.id
            return redirect(url_for('index'))
    return render_template('login.html')

@app.route('/signup', methods=['GET', 'POST'])
def signup():
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']
        user = User(username=username, email=email)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        session['user_id'] = user.id
        return redirect(url_for('index'))
    return render_template('signup.html')

@app.route('/manage_apis', methods=['GET', 'POST'])
def manage_apis():
    if 'user_id' not in session:
        return redirect(url_for('login'))
    if request.method == 'POST':
        # Handle API key and secret updates
        pass
    return render_template('manage_apis.html')

@app.route('/signals')
def signals():
    if 'user_id' not in session:
        return redirect(url_for('login'))
    return render_template('signals.html')

@app.route('/trades')
def trades():
    if 'user_id' not in session:
        return redirect(url_for('login'))
    return render_template('trades.html')

@app.route('/api/toggle_demo_account', methods=['POST'])
def toggle_demo_account():
    if 'user_id' not in session:
        return 'Unauthorized', 401
    user = User.query.get(session['user_id'])
    user.demo_account = not user.demo_account
    db.session.commit()
    return 'OK', 200

@app.route('/api/toggle_autotrader', methods=['POST'])
def toggle_autotrader():
    if 'user_id' not in session:
        return 'Unauthorized', 401
    user = User.query.get(session['user_id'])
    user.autotrader_enabled = not user.autotrader_enabled
    db.session.commit()
    return 'OK', 200

if __name__ == '__main__':
    db.create_all()
    app.run(debug=True)
When I run the above code it says   File "D:\Tradin\NewBot\app.py", line 123, in <module>
    db.create_all()
  File "D:\Tradin\NewBot\venv\Lib\site-packages\flask_sqlalchemy\extension.py", line 900, in create_all     
    self._call_for_binds(bind_key, "create_all")
  File "D:\Tradin\NewBot\venv\Lib\site-packages\flask_sqlalchemy\extension.py", line 871, in _call_for_binds
    engine = self.engines[key]
             ^^^^^^^^^^^^
  File "D:\Tradin\NewBot\venv\Lib\site-packages\flask_sqlalchemy\extension.py", line 687, in engines
    app = current_app._get_current_object()  # type: ignore[attr-defined]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Tradin\NewBot\venv\Lib\site-packages\werkzeug\local.py", line 519, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.

What is the problem and assist me in resolving it