Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
84caa21
feat: getPersonalIndicator
ThisIsRuddy Jan 27, 2025
d90503d
Merge remote-tracking branch 'upstream/main' into feat/personal-indic…
ThisIsRuddy Jan 28, 2025
8accb1f
Merge pull request #1 from danielgroen/feat/personal-indicators
danielgroen Jan 28, 2025
1899cf1
fix: re-add missing getInviteOnlyScripts function
ThisIsRuddy Jan 28, 2025
da0094d
Merge pull request #2 from danielgroen/feat/personal-indicators
ThisIsRuddy Jan 28, 2025
7b934eb
fix: reimplement deeptest since resynce with original repo
ThisIsRuddy Feb 8, 2025
5a85ece
Merge pull request #3 from danielgroen/feat/deepbacktest
ThisIsRuddy Feb 8, 2025
2aa64b9
feat: added clone function to PineIndicator & BuiltInIndicator classes
ThisIsRuddy Feb 17, 2025
3ecc9c9
Merge pull request #4 from danielgroen/feat/clone-indicator
ThisIsRuddy Feb 17, 2025
c12e4ee
dev: created initial types main.d.ts
ThisIsRuddy Feb 17, 2025
2a172f2
dev: enhanced types main.d.ts
ThisIsRuddy Feb 17, 2025
27721d9
dev: enhanced types main.d.ts
ThisIsRuddy Feb 18, 2025
b1fdb8f
feat: layouts
ThisIsRuddy Feb 23, 2025
830fff8
dev: rework + clean-up
ThisIsRuddy Feb 25, 2025
a9ec7c2
dev: deleteLayout
ThisIsRuddy Feb 25, 2025
943e58a
dev: replace env variable refs
ThisIsRuddy Feb 25, 2025
de11a83
Merge pull request #5 from danielgroen/feat/layouts
ThisIsRuddy Feb 25, 2025
3d43bac
dev: re-add console.error in try catches
ThisIsRuddy Feb 25, 2025
5875406
Merge pull request #6 from danielgroen/feat/layouts
ThisIsRuddy Feb 25, 2025
db626ec
dev: change createLayout to only return layoutShortURL
ThisIsRuddy Feb 25, 2025
0842980
Merge pull request #7 from danielgroen/feat/layouts
ThisIsRuddy Feb 25, 2025
8388613
adding 2fa login and changed return object of user
Mar 2, 2025
b643841
fixed type
Mar 2, 2025
2127b1a
adding totp for 2fa
Mar 2, 2025
c2b1835
added conditional qmark to prevent err
Mar 2, 2025
05f7347
optional chaining to prevent errors
Mar 2, 2025
ce1526a
Merge pull request #8 from danielgroen/feat/twofalogin
danielgroen Mar 2, 2025
9d9cae6
Added feature to get the first bar available for deepbacktest
Mar 2, 2025
68d8180
Added feature to get the first bar available for deepbacktest
Mar 2, 2025
2d229b9
fix: update getPersonalIndicator to use latest version
ThisIsRuddy Mar 5, 2025
b04deda
Merge pull request #11 from danielgroen/hotfix/latest-personal
ThisIsRuddy Mar 5, 2025
a008a88
Merge pull request #10 from danielgroen/feat/getFirstBarAvailable
ThisIsRuddy Mar 6, 2025
0def8b9
added more fields for getuser
Mar 6, 2025
41f0ebc
added more fields for getuser
Mar 6, 2025
47510e4
Merge pull request #12 from danielgroen/feat/get-user-expanded
danielgroen Mar 6, 2025
0384184
cleanup
Mar 6, 2025
c902fa0
Added new alert functionalities
Mar 12, 2025
28dd4fe
Merge pull request #13 from danielgroen/feat/alerts
danielgroen Mar 12, 2025
e083887
bugfix authtoken
Mar 17, 2025
93c991c
Merge pull request #14 from danielgroen/feat/fix-authToken
danielgroen Mar 17, 2025
db97878
typo
Apr 7, 2025
6863f8b
test
Apr 8, 2025
af01bc5
test
Apr 8, 2025
a814be5
test
Apr 8, 2025
93c84aa
feat: createAlertForChart
ThisIsRuddy Apr 12, 2025
9be5f4a
Merge pull request #15 from danielgroen/feat/createAlertForChart
ThisIsRuddy Apr 12, 2025
9a9af73
fix: resolves bad currency issue with some symbols
ThisIsRuddy Apr 26, 2025
0487905
Merge pull request #16 from danielgroen/fix/create-layouts
ThisIsRuddy Apr 26, 2025
33eae0c
feat: udpateLayoutStudyInputs
ThisIsRuddy Apr 26, 2025
6e0dda2
Merge pull request #17 from danielgroen/feat/updateLayoutInputs
ThisIsRuddy Apr 26, 2025
e9e0947
rebase from fork
May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: resolves bad currency issue with some symbols
  • Loading branch information
ThisIsRuddy committed Apr 26, 2025
commit 9a9af73e4ff0cf9616c3aa62b8e843b0beaba9e2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.env
.idea
4 changes: 4 additions & 0 deletions main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ declare module '@mathieuc/tradingview' {
symbol: string;
description: string;
type: string;
currency: string;
chartCurrencyId: string;
getTA: () => Promise<Periods>;
}

Expand Down Expand Up @@ -1295,6 +1297,7 @@ declare module '@mathieuc/tradingview' {

export function replaceLayout(
layout: Layout,
currencyId: string,
symbol: string,
interval: string,
studyId: string,
Expand All @@ -1306,6 +1309,7 @@ declare module '@mathieuc/tradingview' {

export function createLayout(
name: string,
currencyId: string,
symbol: string,
interval: string,
studyId: string,
Expand Down
8 changes: 4 additions & 4 deletions src/layout/contentBlob.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createEmptyLayoutContentBlob(layoutName, symbol, interval, studyId) {
function createEmptyLayoutContentBlob(layoutName, currencyId, symbol, interval, studyId) {
const shortName = symbol.split(':')[1];
return {
name: layoutName,
Expand Down Expand Up @@ -640,7 +640,7 @@ function createEmptyLayoutContentBlob(layoutName, symbol, interval, studyId) {
timeframe: '',
interval,
unitId: null,
currencyId: 'XTVCUSDT',
currencyId,
priceAxisProperties: {
autoScale: true,
autoScaleDisabled: false,
Expand Down Expand Up @@ -1033,8 +1033,8 @@ function createStudyStrategy(studyId, rawIndicator) {
}

module.exports = {
createLayoutContentBlob(layoutName, symbol, interval, studyId, rawIndicator) {
const emptyBlob = createEmptyLayoutContentBlob(layoutName, symbol, interval, studyId);
createLayoutContentBlob(layoutName, currencyId, symbol, interval, studyId, rawIndicator) {
const emptyBlob = createEmptyLayoutContentBlob(layoutName, currencyId, symbol, interval, studyId);
if (!rawIndicator) return emptyBlob;

const blob = { ...emptyBlob };
Expand Down
33 changes: 21 additions & 12 deletions src/miscRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const os = require('os');
const axios = require('axios');
const zlib = require('zlib');

const { fetchLayoutContent, createAlert } = require('@mathieuc/tradingview');
const PineIndicator = require('./classes/PineIndicator');
const { genAuthCookies, toTitleCase } = require('./utils');
const { createLayoutContentBlob } = require('./layout/contentBlob');
Expand Down Expand Up @@ -146,15 +145,19 @@ module.exports = {

const { data } = request;

return data.symbols.map((s) => {
return data.symbols
.filter((s) => Object.hasOwn(s, 'currency-logoid'))
.map((s) => {
const exchange = s.exchange.split(' ')[0];
const id = `${exchange.toUpperCase()}:${s.symbol}`;

return {
id,
exchange,
exchange: s.source_id,
fullExchange: s.exchange,
symbol: s.symbol,
currency: s.currency_code,
chartCurrencyId: s['currency-logoid'].split('/')[1],
description: s.description,
type: s.type,
getTA: () => this.getTA(id),
Expand Down Expand Up @@ -378,9 +381,11 @@ module.exports = {
},
});

if (data === 'The user requesting information on the script is not allowed to do so') throw new Error('User does not have access to this script.');
if (data === 'The user requesting information on the script is not allowed to do so')
throw new Error('User does not have access to this script.');

if (!data.success || !data.result.metaInfo || !data.result.metaInfo.inputs) throw new Error(`Non-existent or unsupported indicator: '${id}' '${data.reason}'`);
if (!data.success || !data.result.metaInfo || !data.result.metaInfo.inputs)
throw new Error(`Non-existent or unsupported indicator: '${id}' '${data.reason}'`);

const inputs = {};

Expand Down Expand Up @@ -886,7 +891,7 @@ module.exports = {
},
validateStatus,
});
return layouts || [];
return typeof layouts === 'string' || !Array.isArray(layouts) ? [] : layouts;
} catch (e) {
console.error(e);
throw new Error(`Failed to getLayouts, reason: ${e}`);
Expand All @@ -895,7 +900,7 @@ module.exports = {

/**
* Fetch layout by nameOrIdOrUrl
* @function fetchLayouts
* @function fetchLayout
* @param {string|number} nameOrIdOrUrl Layout name, id or short url
* @param {string} session User 'sessionid' cookie
* @param {string} [signature] User 'sessionid_sign' cookie
Expand Down Expand Up @@ -968,6 +973,7 @@ module.exports = {
* Replaces an existing layout
* @function replaceLayout
* @param {Layout} layout Layout
* @param {string} currencyId currencyId
* @param {string} symbol symbol
* @param {string} interval interval
* @param {string} studyId studyId
Expand All @@ -977,7 +983,7 @@ module.exports = {
* @param {string} [signature] User 'sessionid_sign' cookie
* @returns {Promise<string>} Layout URL
*/
async replaceLayout(layout, symbol, interval, studyId, indicatorId, indicatorValues, session, signature) {
async replaceLayout(layout, currencyId, symbol, interval, studyId, indicatorId, indicatorValues, session, signature) {
const formData = new FormData();
formData.append('id', layout.id);
formData.append('name', layout.name);
Expand All @@ -999,7 +1005,7 @@ module.exports = {
const rawIndicator = await module.exports.getRawIndicator(indicatorId, 'last', session, signature);
Object.entries(indicatorValues).forEach(([key, value]) => rawIndicator.setInputValue(key, value));

const contentBlob = createLayoutContentBlob(layout.name, symbol, interval, studyId, rawIndicator);
const contentBlob = createLayoutContentBlob(layout.name, currencyId, symbol, interval, studyId, rawIndicator);
const gzipData = zlib.gzipSync(JSON.stringify(contentBlob));
formData.append('content', new Blob([gzipData], { type: 'application/gzip' }), 'blob.gz');

Expand All @@ -1026,6 +1032,7 @@ module.exports = {
* Creates a new layout and populates it with the provided indicator setup
* @function createLayout
* @param {string} name name
* @param {string} currencyId currencyId
* @param {string} symbol symbol
* @param {string} interval interval
* @param {string} studyId studyId
Expand All @@ -1035,9 +1042,9 @@ module.exports = {
* @param {string} [signature] User 'sessionid_sign' cookie
* @returns {Promise<string>} Layout Short URL
*/
async createLayout(name, symbol, interval, studyId, indicatorId, indicatorValues, session, signature) {
async createLayout(name, currencyId, symbol, interval, studyId, indicatorId, indicatorValues, session, signature) {
const layout = await module.exports.createBlankLayout(name, session, signature);
const layoutShortUrl = await module.exports.replaceLayout(layout, symbol, interval, studyId, indicatorId, indicatorValues, session, signature);
const layoutShortUrl = await module.exports.replaceLayout(layout, currencyId, symbol, interval, studyId, indicatorId, indicatorValues, session, signature);
return layoutShortUrl;
},

Expand Down Expand Up @@ -1184,7 +1191,9 @@ module.exports = {
const symbol = `={"adjustment":"splits","currency-id":"${defaultCurrencyId}","session":"regular","symbol":"${defaultSymbolId}"}`;
const resolution = seriesDefaultSource.state.interval;

const seriesStrategySources = sourceId ? [chartSources.find((source) => source.id === sourceId)] : chartSources.filter((source) => (source.id !== ('_seriesId')) && source.metaInfo.includes('StrategyScript'));
const seriesStrategySources = sourceId ?
[chartSources.find((source) => source.id === sourceId)] :
chartSources.filter((source) => (source.id !== ('_seriesId')) && source.metaInfo.includes('StrategyScript'));

if (seriesStrategySources.length === 0) throw Error('No strategy found on chart. Please check the chartId & sourceId if supplied.');

Expand Down