Skip to content

πŸ“ˆ Get real-time stocks from TradingView

Add getDrawings function example

Mathieu Colmon945a8ca0a21f
diff --git a/examples/GetDrawings.js b/examples/GetDrawings.js
new file mode 100644
index 0000000..a3b130a
--- /dev/null
+++ b/examples/GetDrawings.js
@@ -0,0 +1,26 @@
+const TradingView = require('../main');
+
+/*
+ This example tests the
+ getDrawings function
+*/
+
+// First parameter must be the layoutID
+// (if the layout is private) Second parameter must be the sessionid cookie
+// (if the layout is private) Third parameter must be the userid (you can use getUser function)
+
+if (!process.argv[2]) throw Error('Please specify a layoutID');
+
+TradingView.getDrawings(process.argv[2], null, {
+ session: process.argv[3],
+ id: process.argv[4],
+}).then((chartToken) => {
+ console.log(`Found ${chartToken.length} drawings:`, chartToken.map((d) => ({
+ id: d.id,
+ symbol: d.symbol,
+ type: d.type,
+ text: d.state.text,
+ })));
+}).catch((err) => {
+ console.error('Error:', err.message);
+});