The Charting Library supports saving/loading charts and study templates using 2 levels of API:
-
Low-Level: save/load functionality is enabled by widget's
save()
/load()
methods andcreateStudyTemplate()
/applyStudyTemplate()
methods. One should take of the storage on the server. You are able to save the JSONs where you wish. For example, you may embed them to your saved pages or user's working area etc. -
High-Level: Charting Library is able to save / load charts and study templates from the storage that you'll point it to. We created a tiny storage sample with Python and PostgreSQL that can be found in our GitHub. You can use it and run on your own server so that you'll be able to have control over all your users' saved data.
Here are a few steps for those who want to have their own chart storage:
- Clone our repository to your host
- Run the data service or use our demo service. Here is a short to-do list for anyone who is not familiar with Django.
- Install Python 3.x and Pip.
- Install PostgreSQL or some other Django-friendly database engine.
- Go to you chart storage folder and run
pip install -r requirements.txt
- Go to charting_library_charts folder and set up your database connection in settings.py (see
DATABASES
@ line #12). Please remember to create the appropriate database in your PostgreSQL. - Run
python manage.py migrate
. This will create the database schema without any data. - Run
python manage.py runserver
to run a TEST instance of your database. Don't use the command above in production environment. Use some other program (i.e., Gunicorn).
- Set up your Charting Library page: set
charts_storage_url = url-of-your-charts-storage
, also setclient_id
anduser_id
(see details below) in the widget constructor. - Enjoy!
Remark: Manual database filling/editing is not the intended usage. Please avoid doing this as you you may hurt the Django infrastructure.
- Charting Library sends HTTP/HTTPS commands to
charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id
.charts_storage_url
,charts_storage_api_version
,client_id
anduser_id
are the arguments of the widget constructor. - You should implement the processing of 4 requests: save chart / load chart / delete chart / list charts.
GET REQUEST: charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id
RESPONSE: JSON Object
status
:ok
orerror
data
: Array of Objectstimestamp
: UNIX time when the chart was saved (example,144908432
1)symbol
: base symbol of the chart (example,AA
)resolution
: resolution of the chart (example,D
)id
: unique integer identifier of the chart (example,9163
)name
: chart name (example,Test
)
POST REQUEST: charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id
name
: name of the chartcontent
: content of the chartsymbol
: chart symbol (example,AA
)resolution
: chart resolution (example,D
)
RESPONSE: JSON Object
status
:ok
orerror
id
: unique integer identifier of the chart (example,9163
)
POST REQUEST: charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id&chart=chart_id
name
: name of the chartcontent
: content of the chartsymbol
: chart symbol (example,AA
)resolution
: chart resolution (example,D
)
RESPONSE: JSON Object
status
:ok
orerror
GET REQUEST: charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id&chart=chart_id
RESPONSE: JSON Object
status
:ok
orerror
data
: Objectcontent
: saved content of the charttimestamp
: UNIX time when the chart was saved (example,1449084321
)id
: unique integer identifier of the chart (example,9163
)name
: name of the chart
DELETE REQUEST: charts_storage_url/charts_storage_api_version/charts?client=client_id&user=user_id&chart=chart_id
RESPONSE: JSON Object
status
:ok
orerror
We're running a demo chart storage service to let you save/load charts as soon as you build your Charting Library. Here is the link http://saveload.tradingview.com. Note that it's provided as-is since it's a demo.
We do not guarantee its stability. Also, note that we delete the data in the storage on a regular basis.
You are responsible for the charts that your users are able to see and load.
A user can see/load charts that have the same client_id
and user_id
that the user has.
client_id
is an identifier of user's group.
The intended use is when you have a few groups of users or when you have a few sites that use the same chart storage.
So the common practice is to set client_id = your-site's-URL
. It's up to you to decide.
user_id
is a unique identifier of a user. Users ID belongs to a particular client_id
group.
You can either set it for each user individually (private storage for each user) or set it for all users or user groups (public storage).
Here are a few examples:
client_id |
user_id |
Effect |
---|---|---|
Your site URL or other link | Unique user ID | Each user has a private chart storage that other users can't see. |
Your site URL or other link | The same value for all users | Each user can see and load any saved chart. |
Your site URL or other link | Unique user ID for registered users along with a separate setting for anonymous users | Each registered user has a private chart storage that other users can't see. All anonymous users share a single storage. |