@mathieuc/tradingview 2.0.7 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +1,77 @@
1
- require('./envLoader');
2
- const { getSentNotifs, addSentNotifs } = require('./sentNotifs');
3
- const marketAPI = require('../../main');
4
- const discordWH = require('./discordWH')(process.env.DISCORD_TOKEN);
5
-
6
- if (!process.env.SYMBOLS) process.env.SYMBOLS = 'BTCEUR';
7
- if (!process.env.PERIOD) process.env.PERIOD = '240';
8
-
9
- const market = marketAPI(false);
10
-
11
- market.on('logged', () => {
12
- process.env.SYMBOLS.split(',').forEach((symbol) => {
13
- console.log('Listen', symbol);
14
-
15
- market.initChart({
16
- symbol,
17
- period: process.env.PERIOD,
18
- range: 30,
19
- timezone: 'Europe/Paris',
20
- indicators: [
21
- { name: 'CIPHER_A', id: 'PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT', version: '1.0' },
22
- {
23
- name: 'CIPHER_B',
24
- id: 'PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp',
25
- settings: [ // Activate Stoch divergences
26
- true, true, true, true, true, true, 9, 12,
27
- 'hlc3', 3, 53, 60, 100, -53, -60, -75, true,
28
- true, true, 45, -65, true, 15, -40, true, 60,
29
- 150, 2.5, false, 'close', 14, 30, 60, false,
30
- false, 60, 30, true, true, false, 'close', 14,
31
- 14, 3, 3, true, true, false, 'close', 10, 23,
32
- 50, 0.5, false, false, '720', 0, 0, 0, 0, 0, 0,
33
- false, '60', '240', 0, 0, false, '240', false,
34
- ],
35
- version: '15.0',
36
- },
37
- ],
38
- }, (periods) => {
39
- if (!periods[0].CIPHER_B) return;
40
-
41
- const pBefore = periods[1];
42
- const p = periods[0];
43
-
44
- const gapBefore = pBefore.CIPHER_B.VWAP;
45
- const gap = p.CIPHER_B.VWAP;
46
-
47
- const notifID = `${symbol}@${p.$time}@BULL_TRIGGER`;
48
-
49
- if (
50
- p.CIPHER_B.WTWave1 <= 0 && p.CIPHER_B.WTWave1 > -35
51
- && gapBefore < 0 && gapBefore < gap
52
- && pBefore.CIPHER_B.WTWave1 < p.CIPHER_B.WTWave1
53
- && !getSentNotifs().includes(notifID)
54
- ) {
55
- addSentNotifs(notifID);
56
- console.log(symbol, 'TRIG NOW', new Date(p.$time * 1000).toLocaleString());
57
-
58
- discordWH({
59
- content: process.env.DISCORD_MENTION,
60
- embeds: [
61
- {
62
- title: `Trigger wave on ${symbol} !`,
63
- color: 720640,
64
- description: `Cipher B trigger wave detected on ${symbol}.`,
65
- url: `https://fr.tradingview.com/chart/?symbol=${symbol}`,
66
- timestamp: new Date(p.$time * 1000),
67
- footer: {
68
- text: 'TradingView',
69
- icon_url: 'https://tradingview.com/favicon.ico',
70
- },
71
- },
72
- ],
73
- });
74
- }
75
- });
76
- });
77
- });
1
+ require('./envLoader');
2
+ const { getSentNotifs, addSentNotifs } = require('./sentNotifs');
3
+ const marketAPI = require('../../main');
4
+ const discordWH = require('./discordWH')(process.env.DISCORD_TOKEN);
5
+
6
+ if (!process.env.SYMBOLS) process.env.SYMBOLS = 'BTCEUR';
7
+ if (!process.env.PERIOD) process.env.PERIOD = '240';
8
+
9
+ const market = marketAPI(false);
10
+
11
+ market.on('logged', () => {
12
+ process.env.SYMBOLS.split(',').forEach((symbol) => {
13
+ console.log('Listen', symbol);
14
+
15
+ market.initChart({
16
+ symbol,
17
+ period: process.env.PERIOD,
18
+ range: 30,
19
+ timezone: 'Europe/Paris',
20
+ indicators: [
21
+ { name: 'CIPHER_A', id: 'PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT', version: '1.0' },
22
+ {
23
+ name: 'CIPHER_B',
24
+ id: 'PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp',
25
+ settings: [ // Activate Stoch divergences
26
+ true, true, true, true, true, true, 9, 12,
27
+ 'hlc3', 3, 53, 60, 100, -53, -60, -75, true,
28
+ true, true, 45, -65, true, 15, -40, true, 60,
29
+ 150, 2.5, false, 'close', 14, 30, 60, false,
30
+ false, 60, 30, true, true, false, 'close', 14,
31
+ 14, 3, 3, true, true, false, 'close', 10, 23,
32
+ 50, 0.5, false, false, '720', 0, 0, 0, 0, 0, 0,
33
+ false, '60', '240', 0, 0, false, '240', false,
34
+ ],
35
+ version: '15.0',
36
+ },
37
+ ],
38
+ }, (periods) => {
39
+ if (!periods[0].CIPHER_B) return;
40
+
41
+ const pBefore = periods[1];
42
+ const p = periods[0];
43
+
44
+ const gapBefore = pBefore.CIPHER_B.VWAP;
45
+ const gap = p.CIPHER_B.VWAP;
46
+
47
+ const notifID = `${symbol}@${p.$time}@BULL_TRIGGER`;
48
+
49
+ if (
50
+ p.CIPHER_B.WTWave1 <= 0 && p.CIPHER_B.WTWave1 > -35
51
+ && gapBefore < 0 && gapBefore < gap
52
+ && pBefore.CIPHER_B.WTWave1 < p.CIPHER_B.WTWave1
53
+ && !getSentNotifs().includes(notifID)
54
+ ) {
55
+ addSentNotifs(notifID);
56
+ console.log(symbol, 'TRIG NOW', new Date(p.$time * 1000).toLocaleString());
57
+
58
+ discordWH({
59
+ content: process.env.DISCORD_MENTION,
60
+ embeds: [
61
+ {
62
+ title: `Trigger wave on ${symbol} !`,
63
+ color: 720640,
64
+ description: `Cipher B trigger wave detected on ${symbol}.`,
65
+ url: `https://fr.tradingview.com/chart/?symbol=${symbol}`,
66
+ timestamp: new Date(p.$time * 1000),
67
+ footer: {
68
+ text: 'TradingView',
69
+ icon_url: 'https://tradingview.com/favicon.ico',
70
+ },
71
+ },
72
+ ],
73
+ });
74
+ }
75
+ });
76
+ });
77
+ });
@@ -1,16 +1,16 @@
1
- const fs = require('fs');
2
-
3
- const sentNotifsFile = './sentNotifs.txt';
4
-
5
- exports.getSentNotifs = () => {
6
- if (!fs.existsSync(sentNotifsFile)) fs.writeFileSync(sentNotifsFile, '');
7
- return (fs.readFileSync(sentNotifsFile, 'utf8') || '').split(';').filter((n) => n);
8
- };
9
-
10
- exports.addSentNotifs = (notif = '') => {
11
- if (!fs.existsSync(sentNotifsFile)) fs.writeFileSync(sentNotifsFile, '');
12
- fs.writeFileSync(
13
- sentNotifsFile,
14
- `${fs.readFileSync(sentNotifsFile, 'utf8') || ''}${notif};`,
15
- );
16
- };
1
+ const fs = require('fs');
2
+
3
+ const sentNotifsFile = './sentNotifs.txt';
4
+
5
+ exports.getSentNotifs = () => {
6
+ if (!fs.existsSync(sentNotifsFile)) fs.writeFileSync(sentNotifsFile, '');
7
+ return (fs.readFileSync(sentNotifsFile, 'utf8') || '').split(';').filter((n) => n);
8
+ };
9
+
10
+ exports.addSentNotifs = (notif = '') => {
11
+ if (!fs.existsSync(sentNotifsFile)) fs.writeFileSync(sentNotifsFile, '');
12
+ fs.writeFileSync(
13
+ sentNotifsFile,
14
+ `${fs.readFileSync(sentNotifsFile, 'utf8') || ''}${notif};`,
15
+ );
16
+ };
@@ -1,94 +1,94 @@
1
- require('./envLoader');
2
- const { getSentNotifs, addSentNotifs } = require('./sentNotifs');
3
- const marketAPI = require('../../main');
4
- const discordWH = require('./discordWH')(process.env.DISCORD_TOKEN);
5
-
6
- const markets = [
7
- {
8
- symbol: 'EURUSD',
9
- period: '1D',
10
- settings: {
11
- 1: 21, // HMA 1 Length
12
- 3: 89, // HMA 2 Length
13
- 5: 7, // RSI Length
14
- 8: 2, // Stop Loss (%)
15
- 9: 1, // Take Profit (%)
16
- },
17
- },
18
- {
19
- symbol: 'GBPUSD',
20
- period: '1D',
21
- settings: {
22
- 1: 220, // HMA 1 Length
23
- 3: 150, // HMA 2 Length
24
- 5: 1, // RSI Length
25
- 8: 2, // Stop Loss (%)
26
- 9: 1, // Take Profit (%)
27
- },
28
- },
29
- {
30
- symbol: 'USDCAD',
31
- period: '1D',
32
- settings: {
33
- 1: 21, // HMA 1 Length
34
- 3: 89, // HMA 2 Length
35
- 5: 10, // RSI Length
36
- 8: 3, // Stop Loss (%)
37
- 9: 2, // Take Profit (%)
38
- },
39
- },
40
- ];
41
-
42
- const market = marketAPI(false);
43
-
44
- market.on('logged', () => {
45
- markets.forEach((mrk) => {
46
- console.log('Listen', mrk.symbol);
47
-
48
- market.initChart({
49
- symbol: mrk.symbol,
50
- period: mrk.period || '1D',
51
- range: mrk.range || 30,
52
- timezone: mrk.timezone || 'Europe/Paris',
53
- indicators: [
54
- // My Magimix Indicator
55
- {
56
- name: 'MAGIMIX',
57
- id: 'USER;d90a5e852ddc439b994db6beff14d702',
58
- version: mrk.version || 'last',
59
- settings: mrk.settings || [],
60
- },
61
- ],
62
- }, ({ 0: p }) => {
63
- if (!p.MAGIMIX) return;
64
-
65
- const signalType = p.MAGIMIX.Longsignal ? 'LONG' : 'SHORT';
66
- const notifID = `${mrk.symbol}@MAGIMIX@${p.$time}@${signalType}`;
67
-
68
- if (
69
- (p.MAGIMIX.Longsignal || p.MAGIMIX.Shortsignal)
70
- && !getSentNotifs().includes(notifID)
71
- ) {
72
- addSentNotifs(notifID);
73
- console.log(mrk.symbol, 'SIGNAL', new Date(p.$time * 1000).toLocaleString());
74
-
75
- discordWH({
76
- content: process.env.DISCORD_MENTION,
77
- embeds: [
78
- {
79
- title: `Magimix ${signalType} signal for ${mrk.symbol} !`,
80
- color: p.MAGIMIX.Longsignal ? 3066993 : 15158332,
81
- description: `Magimix ${signalType} signal for ${mrk.symbol} at ${p.$prices.close} !`,
82
- url: `https://fr.tradingview.com/chart/?symbol=${mrk.symbol}`,
83
- timestamp: new Date(p.$time * 1000),
84
- footer: {
85
- text: 'TradingView',
86
- icon_url: 'https://tradingview.com/favicon.ico',
87
- },
88
- },
89
- ],
90
- });
91
- }
92
- });
93
- });
94
- });
1
+ require('./envLoader');
2
+ const { getSentNotifs, addSentNotifs } = require('./sentNotifs');
3
+ const marketAPI = require('../../main');
4
+ const discordWH = require('./discordWH')(process.env.DISCORD_TOKEN);
5
+
6
+ const markets = [
7
+ {
8
+ symbol: 'EURUSD',
9
+ period: '1D',
10
+ settings: {
11
+ 1: 21, // HMA 1 Length
12
+ 3: 89, // HMA 2 Length
13
+ 5: 7, // RSI Length
14
+ 8: 2, // Stop Loss (%)
15
+ 9: 1, // Take Profit (%)
16
+ },
17
+ },
18
+ {
19
+ symbol: 'GBPUSD',
20
+ period: '1D',
21
+ settings: {
22
+ 1: 220, // HMA 1 Length
23
+ 3: 150, // HMA 2 Length
24
+ 5: 1, // RSI Length
25
+ 8: 2, // Stop Loss (%)
26
+ 9: 1, // Take Profit (%)
27
+ },
28
+ },
29
+ {
30
+ symbol: 'USDCAD',
31
+ period: '1D',
32
+ settings: {
33
+ 1: 21, // HMA 1 Length
34
+ 3: 89, // HMA 2 Length
35
+ 5: 10, // RSI Length
36
+ 8: 3, // Stop Loss (%)
37
+ 9: 2, // Take Profit (%)
38
+ },
39
+ },
40
+ ];
41
+
42
+ const market = marketAPI(false);
43
+
44
+ market.on('logged', () => {
45
+ markets.forEach((mrk) => {
46
+ console.log('Listen', mrk.symbol);
47
+
48
+ market.initChart({
49
+ symbol: mrk.symbol,
50
+ period: mrk.period || '1D',
51
+ range: mrk.range || 30,
52
+ timezone: mrk.timezone || 'Europe/Paris',
53
+ indicators: [
54
+ // My Magimix Indicator
55
+ {
56
+ name: 'MAGIMIX',
57
+ id: 'USER;d90a5e852ddc439b994db6beff14d702',
58
+ version: mrk.version || 'last',
59
+ settings: mrk.settings || [],
60
+ },
61
+ ],
62
+ }, ({ 0: p }) => {
63
+ if (!p.MAGIMIX) return;
64
+
65
+ const signalType = p.MAGIMIX.Longsignal ? 'LONG' : 'SHORT';
66
+ const notifID = `${mrk.symbol}@MAGIMIX@${p.$time}@${signalType}`;
67
+
68
+ if (
69
+ (p.MAGIMIX.Longsignal || p.MAGIMIX.Shortsignal)
70
+ && !getSentNotifs().includes(notifID)
71
+ ) {
72
+ addSentNotifs(notifID);
73
+ console.log(mrk.symbol, 'SIGNAL', new Date(p.$time * 1000).toLocaleString());
74
+
75
+ discordWH({
76
+ content: process.env.DISCORD_MENTION,
77
+ embeds: [
78
+ {
79
+ title: `Magimix ${signalType} signal for ${mrk.symbol} !`,
80
+ color: p.MAGIMIX.Longsignal ? 3066993 : 15158332,
81
+ description: `Magimix ${signalType} signal for ${mrk.symbol} at ${p.$prices.close} !`,
82
+ url: `https://fr.tradingview.com/chart/?symbol=${mrk.symbol}`,
83
+ timestamp: new Date(p.$time * 1000),
84
+ footer: {
85
+ text: 'TradingView',
86
+ icon_url: 'https://tradingview.com/favicon.ico',
87
+ },
88
+ },
89
+ ],
90
+ });
91
+ }
92
+ });
93
+ });
94
+ });
package/tests/analysis.js CHANGED
@@ -1,13 +1,13 @@
1
- const marketAPI = require('../main');
2
-
3
- (async () => {
4
- const market = marketAPI(false);
5
-
6
- const searchBTC = (await market.search('bitcoin euro', 'crypto'))[0];
7
- console.log('Found Bitcoin / Euro:', searchBTC);
8
-
9
- const TA = await searchBTC.getTA();
10
- console.log('Full technical analysis for Bitcoin:', TA);
11
-
12
- // You can also use this way: await market.getTA('crypto', 'BINANCE:BTCEUR');
13
- })();
1
+ const marketAPI = require('../main');
2
+
3
+ (async () => {
4
+ const market = marketAPI(false);
5
+
6
+ const searchBTC = (await market.search('bitcoin euro', 'crypto'))[0];
7
+ console.log('Found Bitcoin / Euro:', searchBTC);
8
+
9
+ const TA = await searchBTC.getTA();
10
+ console.log('Full technical analysis for Bitcoin:', TA);
11
+
12
+ // You can also use this way: await market.getTA('crypto', 'BINANCE:BTCEUR');
13
+ })();
@@ -1,42 +1,42 @@
1
- const marketAPI = require('../main');
2
-
3
- const market = marketAPI(false);
4
-
5
- market.on('logged', () => {
6
- market.initChart({
7
- symbol: 'COINBASE:BTCEUR',
8
- period: '240',
9
- range: 50,
10
- indicators: [
11
- { name: 'ACCU_DISTRIB', id: 'STD;Accumulation_Distribution', version: '25' },
12
- { name: 'CIPHER_A', id: 'PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT', version: '1.0' },
13
- {
14
- name: 'CIPHER_B',
15
- id: 'PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp',
16
- settings: [ // Activate Stoch divergences
17
- true, true, true, true, true, true, 9, 12,
18
- 'hlc3', 3, 53, 60, 100, -53, -60, -75, true,
19
- true, true, 45, -65, true, 15, -40, true, 60,
20
- 150, 2.5, false, 'close', 14, 30, 60, false,
21
- false, 60, 30, true, true, false, 'close', 14,
22
- 14, 3, 3, true, true, false, 'close', 10, 23,
23
- 50, 0.5, false, false, '720', 0, 0, 0, 0, 0, 0,
24
- false, '60', '240', 0, 0, false, '240', false,
25
- ],
26
- version: '15.0',
27
- },
28
- // Color Changing Moving Average
29
- { name: 'CCMA', id: 'PUB;5nawr3gCESvSHQfOhrLPqQqT4zM23w3X', version: '6.0' },
30
- ],
31
- }, (periods) => {
32
- if (!periods[0].CIPHER_B) return;
33
- if (!periods[0].CCMA) return;
34
-
35
- console.log('Last period:', {
36
- price: periods[0].$prices.close,
37
- moneyFlow: (periods[0].CIPHER_B.RSIMFIArea >= 0) ? 'POSITIVE' : 'NEGATIVE',
38
- VWAP: periods[0].CIPHER_B.VWAP,
39
- MA: (periods[0].CCMA.Plot <= periods[0].$prices.close) ? 'ABOVE' : 'UNDER',
40
- });
41
- });
42
- });
1
+ const marketAPI = require('../main');
2
+
3
+ const market = marketAPI(false);
4
+
5
+ market.on('logged', () => {
6
+ market.initChart({
7
+ symbol: 'COINBASE:BTCEUR',
8
+ period: '240',
9
+ range: 50,
10
+ indicators: [
11
+ { name: 'ACCU_DISTRIB', id: 'STD;Accumulation_Distribution', version: '25' },
12
+ { name: 'CIPHER_A', id: 'PUB;vrOJcNRPULteowIsuP6iHn3GIxBJdXwT', version: '1.0' },
13
+ {
14
+ name: 'CIPHER_B',
15
+ id: 'PUB;uA35GeckoTA2EfgI63SD2WCSmca4njxp',
16
+ settings: [ // Activate Stoch divergences
17
+ true, true, true, true, true, true, 9, 12,
18
+ 'hlc3', 3, 53, 60, 100, -53, -60, -75, true,
19
+ true, true, 45, -65, true, 15, -40, true, 60,
20
+ 150, 2.5, false, 'close', 14, 30, 60, false,
21
+ false, 60, 30, true, true, false, 'close', 14,
22
+ 14, 3, 3, true, true, false, 'close', 10, 23,
23
+ 50, 0.5, false, false, '720', 0, 0, 0, 0, 0, 0,
24
+ false, '60', '240', 0, 0, false, '240', false,
25
+ ],
26
+ version: '15.0',
27
+ },
28
+ // Color Changing Moving Average
29
+ { name: 'CCMA', id: 'PUB;5nawr3gCESvSHQfOhrLPqQqT4zM23w3X', version: '6.0' },
30
+ ],
31
+ }, (periods) => {
32
+ if (!periods[0].CIPHER_B) return;
33
+ if (!periods[0].CCMA) return;
34
+
35
+ console.log('Last period:', {
36
+ price: periods[0].$prices.close,
37
+ moneyFlow: (periods[0].CIPHER_B.RSIMFIArea >= 0) ? 'POSITIVE' : 'NEGATIVE',
38
+ VWAP: periods[0].CIPHER_B.VWAP,
39
+ MA: (periods[0].CCMA.Plot <= periods[0].$prices.close) ? 'ABOVE' : 'UNDER',
40
+ });
41
+ });
42
+ });
@@ -0,0 +1,56 @@
1
+ const marketAPI = require('../main');
2
+
3
+ const market = marketAPI(false);
4
+
5
+ market.on('logged', async () => {
6
+ const indicators = (await market.searchIndicator('strategy'))
7
+ .filter((st) => (st.type === 'strategy' && st.access !== 'invite_only'))
8
+ .map((st) => ({
9
+ name: st.name,
10
+ id: st.id,
11
+ version: st.version,
12
+ settings: {
13
+ commission_type: 'percent',
14
+ commission_value: 0,
15
+ initial_capital: 25000,
16
+ default_qty_value: 20,
17
+ default_qty_type: 'percent_of_equity',
18
+ currency: 'EUR',
19
+ pyramiding: 10,
20
+ },
21
+ }));
22
+
23
+ let total = indicators.length;
24
+ console.log('Found', indicators.length, 'strategies');
25
+
26
+ market.initChart({
27
+ symbol: 'COINBASE:BTCEUR',
28
+ period: '1D',
29
+ range: 0,
30
+ indicators,
31
+ }, (_, strategies) => {
32
+ const loaded = Object.keys(strategies).length;
33
+ console.log(`Loading... ${loaded}/${total}`);
34
+
35
+ if (loaded < total) return;
36
+ market.end();
37
+
38
+ console.log(
39
+ 'Best strategies:',
40
+ Object.keys(strategies).map((stName) => ({
41
+ n: stName,
42
+ p: Math.round(strategies[stName].performance.all.netProfitPercent * 1000) / 1000,
43
+ })).sort((a, b) => b.p - a.p),
44
+ );
45
+ });
46
+
47
+ market.on('error', (...data) => {
48
+ if (data[1].type === 'study_error') {
49
+ console.error('Error with study:', indicators[data[1].data]);
50
+ total -= 1;
51
+ return;
52
+ }
53
+
54
+ console.error(...data);
55
+ });
56
+ });