This is a backend implementing a chart storage with Python and PostgreSQL. You can run this storage on your server to process users' saved data such as chart layouts, drawing templates, and indicator templates. For more information, refer to the Saving and loading charts section of the Advanced Charts documentation.
This backend is a reference implementation and has no authentication or authorization.
Data is scoped only by the client and user query parameters, which are supplied by the caller.
Anyone who knows or guesses a client/user pair can read, overwrite, or delete that data.
Before using it in production, you must:
- Put it behind your own authentication (for example, a reverse proxy that validates a session or token) and derive or verify
userserver-side instead of trusting the query parameter. - Restrict
Access-Control-Allow-Originto your own domains (it is*by default, seeapi/v11/common.py). - Set
SECRET_KEYandALLOWED_HOSTS, and serve the storage over HTTPS with a production WSGI server. - Avoid exposing the Prometheus
/metricsendpoint publicly.
Demo server: https://saveload.tradingview.com, used in our examples, is a public demo for testing only.
Anything saved there can be read, modified, or deleted by anyone, and may be wiped at any time.
Do not use it in production.
Python 3.10 or later, pip, Django, PostgreSQL
- Clone the repository to your host machine.
- Install Python 3.10 or later and pip. Use a virtual environment if your host has an older Python version that cannot be upgraded.
- Install PostgreSQL or any other Django-friendly database engine. You can also install pgAdmin or any other administrative tool for your database.
- Go to your chart storage folder and install the required dependencies:
pip install -r requirements.txt. Thepsycopg[binary]PostgreSQL driver ships prebuilt, so no compiler is needed. For production, considerpsycopg[c]instead, which uses your system'slibpqand its security updates (see the psycopg installation guide). - Create an empty database in PostgreSQL using either the command line or pgAdmin.
- Configure your database connection in
charting_library_charts/settings.py(seeDATABASESat line 16). - Generate a secret key by running
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'. - Set your secret key to your environment variables
export SECRET_KEY='...'. This is required: the storage does not start without it. - Run
python manage.py migrateto create the database schema without any data. - Start a test instance of your database by running
python manage.py runserver. Note that for production environments, you should avoid usingrunserverand instead use a suitable WSGI (Web Server Gateway Interface) server like Gunicorn. - Set
charts_storage_urlin the Widget Constructor to the URL of your chart storage. Additionally, ensure to setclient_idanduser_id. Note that these values only partition data; they do not secure it (see Security notice).