finalni instant indikatory + save do arch

This commit is contained in:
David Brazda
2023-10-24 18:49:39 +02:00
parent 0c4fb20c66
commit de5382d04a
17 changed files with 455 additions and 234 deletions

View File

@@ -340,26 +340,45 @@ function chart_indicators(data, visible, offset) {
var cnf = null
//pokud je v nastaveni scale, pouzijeme tu
var scale = null
try {
if (addedInds[key]) {
cnf = addedInds[key]
scale = TOML.parse(cnf).scale
}
else
{
cnf = "#[stratvars.indicators."+key+"]"+TOML.stringify(stratvars_toml.stratvars.indicators[key], {newline: '\n'})
scale = stratvars_toml.stratvars.indicators[key].scale
//cnf = TOML.stringify(stratvars_toml.stratvars.indicators[key], {newline: '\n'})
//a = TOML.parse(cnf)
//console.log("PARSED again",a)
var instant = null
//console.log(key)
//zkusime zda nejde o instantni indikator z arch runneru
if ((data.ext_data !== null) && (data.ext_data.instantindicators)) {
let instantIndicator = data.ext_data.instantindicators.find(indicator => indicator.name == key);
//console.log("nalezen", key)
if (instantIndicator) {
cnf = instantIndicator.toml
scale = TOML.parse(cnf).scale
instant = 1
}
}
catch (e) {
//nic
}
//pokud nenalezeno, pak bereme standard
//pozor ted nebereme z addedInds
if (!cnf) {
if (stratvars_toml.stratvars.indicators[key]) {
cnf = "#[stratvars.indicators."+key+"]"+TOML.stringify(stratvars_toml.stratvars.indicators[key], {newline: '\n'})
scale = stratvars_toml.stratvars.indicators[key].scale
}
}
// //kontriolujeme v addedInds
// if (addedInds[key]) {
// cnf = addedInds[key]
// scale = TOML.parse(cnf).scale
// instant = 1
// }
// //a az potom bereme normos
// else
// {
// cnf = "#[stratvars.indicators."+key+"]"+TOML.stringify(stratvars_toml.stratvars.indicators[key], {newline: '\n'})
// scale = stratvars_toml.stratvars.indicators[key].scale
// //cnf = TOML.stringify(stratvars_toml.stratvars.indicators[key], {newline: '\n'})
// //a = TOML.parse(cnf)
// //console.log("PARSED again",a)
// }
// }
//initialize indicator and store reference to array
var obj = {name: key, series: null, cnf:cnf, added: ((addedInds[key])?1:null)}
var obj = {name: key, series: null, cnf:cnf, instant: instant}
//start
//console.log(key)
@@ -580,7 +599,9 @@ function remove_indicators() {
}
//switch to interval pomocna funkce
function switch_to_interval(interval, data) {
function switch_to_interval(interval, data, extra) {
store_activated_buttons_state(extra);
if (!data) {
window.alert("no data switch to interval")
}
@@ -671,7 +692,7 @@ function display_buy_markers(data) {
//xx - ted bude slLine pole
transformed_data["sl_line"].forEach((slRecord, index, array) => {
console.log("uvnitr")
//console.log("uvnitr")
slLine_temp = chart.addLineSeries({
// title: "avgpbuyline",
color: '#e4c76d',

View File

@@ -2,7 +2,6 @@
let editor_diff_arch1
let editor_diff_arch2
var archData = null
var addedInds = {}
function refresh_arch_and_callback(row, callback) {
//console.log("entering refresh")
@@ -314,129 +313,6 @@ $(document).ready(function () {
}
});
//Kod pro add indicator -dat do arch chart souboru
//modal - delete indicator button
$('#deleteIndicatorButton').click(function () {
window.$('#indicatorModal').modal('hide');
indname = $('#indicatorName').val()
//updatneme globalni promennou obsahujici vsechny arch data
//TBD nebude fungovat az budu mit vic chartů otevřených - předělat
if (archData.indicators[0][indname]) {
delete archData.indicators[0][indname]
delete addedInds[indname]
//get active resolution
const element = document.querySelector('.switcher-active-item');
resolution = element.textContent
//console.log("aktivni rozliseni", resolution)
switch_to_interval(resolution, archData)
}
});
var myModalEl = document.getElementById('indicatorModal')
myModalEl.addEventListener('hidden.bs.modal', function (event) {
close_addind_modal()
})
function close_addind_modal() {
index = $('#indicatorId').val()
const elem = document.getElementById("IND"+index);
if (elem) {
elem.classList.replace('switcher-item-highlighted', 'switcher-item');
}
//vracime pripadny schovany del button
$('#deleteIndicatorButton').show();
window.$('#indicatorModal').modal('hide');
}
//HLAVNI SAVE akce INDICATOR MODAL - ulozi nebo vytvori novy
$('#saveIndicatorButton').click(function () {
indName = $('#indicatorName').val()
if (!indName) {
alert("name musi byt vyplneno")
return
}
index = $('#indicatorId').val()
var elem = document.getElementById("IND"+index);
if (elem) {
//pokud existuje - pak jde bud o edit nebo duplicate - podle jmena
//jmeno je updatnute, jde o duplicate - vytvarime novy index
if (elem.textContent !== $('#indicatorName').val()) {
//alert("duplikujeme")
index_ind++
index = index_ind
}
}
//pokud neexistuje, pak jde o novy index - pouzijeme tento
runner_id = $("#statusArchId").text()
if (!runner_id) {
alert("no arch runner selected")
return
}
// row = archiveRecords.row('.selected').data();
// if (row == undefined) {
// }
store_activated_buttons_state()
//pridame jeste tu aktualni, aby se zobrazila jako aktivni
activatedButtons.push(indName);
//console.log(activatedButtons)
obj = new Object()
obj.runner_id = runner_id
obj.toml = ind_editor.getValue()
jsonString = JSON.stringify(obj);
//console.log("pred odeslanim",jsonString)
//cal rest api
$.ajax({
url:"/archived_runners/"+runner_id+"/previewindicator",
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key',
API_KEY); },
method:"PUT",
contentType: "application/json",
data: jsonString,
success:function(data){
//kod pro update/vytvoreni je zde stejny - updatujeme jen zdrojove dictionary
window.$('#indicatorModal').modal('hide');
//console.log(data)
//indName = $('#indicatorName').val()
//updatneme/vytvorime klic v globalni promennou obsahujici vsechny arch data
//TBD nebude fungovat az budu mit vic chartů otevřených - předělat
archData.indicators[0][indName] = data
//glob promenna obsahujici aktualne pridane indikatory a jejich konfigurace
addedInds[indName] = obj.toml
//get active resolution
const element = document.querySelector('.switcher-active-item');
resolution = element.textContent
//console.log("aktivni rozliseni", resolution)
switch_to_interval(resolution, archData)
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
window.alert(JSON.stringify(xhr));
//console.log(JSON.stringify(xhr));
//$('#button_runagain_arch').attr('disabled',false);
}
})
// #indicatorId
// #indicatorName
// #indicatorTOML
//$('#editidarchive').val(row.id);
//$('#editnote').val(row.note);
});
//show button
$('#button_show_arch').click(function () {

View File

@@ -0,0 +1,184 @@
//docasne ulozeni aktivovanych buttonu pred reloadem
var activatedButtons = []
//seznam upravenych instant indikatoru a jejich konfigurace
// var addedInds = {}
function store_activated_buttons_state(extra) {
activatedButtons = []
if (extra) {
activatedButtons.push(extra)
}
//ulozime si stav aktivovaných buttonků před změnou - mozna do sluzby
$('#indicatorsButtons .switcher-active-item').each(function() {
activatedButtons.push($(this).text());
});
}
//JQUERY SECTION
$(document).ready(function () {
//modal - delete indicator button
$('#deleteIndicatorButton').click(function () {
indname = $('#indicatorName').val()
runner_id = $("#statusArchId").text()
if (!runner_id) {
alert("no arch runner selected")
return
}
obj = new Object()
obj.runner_id = runner_id
obj.toml = TOML.parse(ind_editor.getValue())
obj.name = indname
jsonString = JSON.stringify(obj);
//console.log("pred odeslanim",jsonString)
//cal rest api
$.ajax({
url:"/archived_runners/"+runner_id+"/previewindicator",
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key',
API_KEY); },
method:"DELETE",
contentType: "application/json",
data: jsonString,
success:function(data){
window.$('#indicatorModal').modal('hide');
//updatneme globalni promennou obsahujici vsechny arch data
//TBD nebude fungovat az budu mit vic chartů otevřených - předělat
//smazeme zaznam o indiaktoru v lokalni kopii ext_data (z nich se pak prekresli indikatory)
if ((archData.ext_data !== null) && (archData.ext_data.instantindicators)) {
let index = archData.ext_data.instantindicators.findIndex(indicator => indicator.name === indname);
if (index !== -1) {
archData.ext_data.instantindicators.splice(index, 1);
}
}
if (archData.indicators[0][indname]) {
delete archData.indicators[0][indname]
//delete addedInds[indname]
//get active resolution
const element = document.querySelector('.switcher-active-item');
resolution = element.textContent
//console.log("aktivni rozliseni", resolution)
switch_to_interval(resolution, archData)
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
window.alert(JSON.stringify(xhr));
//console.log(JSON.stringify(xhr));
//$('#button_runagain_arch').attr('disabled',false);
}
})
});
var myModalEl = document.getElementById('indicatorModal')
myModalEl.addEventListener('hidden.bs.modal', function (event) {
close_indicator_modal()
})
function close_indicator_modal() {
index = $('#indicatorId').val()
const elem = document.getElementById("IND"+index);
if (elem) {
elem.classList.replace('switcher-item-highlighted', 'switcher-item');
}
//vracime pripadny schovany del button
$('#deleteIndicatorButton').show();
$('#saveIndicatorButton').show();
window.$('#indicatorModal').modal('hide');
}
//HLAVNI SAVE akce INDICATOR MODAL - ulozi nebo vytvori novy
$('#saveIndicatorButton').click(function () {
indName = $('#indicatorName').val()
if (!indName) {
alert("name musi byt vyplneno")
return
}
index = $('#indicatorId').val()
var elem = document.getElementById("IND"+index);
if (elem) {
//pokud existuje - pak jde bud o edit nebo duplicate - podle jmena
//jmeno je updatnute, jde o duplicate - vytvarime novy index
if (elem.textContent !== $('#indicatorName').val()) {
//alert("duplikujeme")
index_ind++
index = index_ind
}
}
//pokud neexistuje, pak jde o novy index - pouzijeme tento
runner_id = $("#statusArchId").text()
if (!runner_id) {
alert("no arch runner selected")
return
}
// store_activated_buttons_state()
// //pridame jeste tu aktualni, aby se zobrazila jako aktivni
// activatedButtons.push(indName);
console.log(activatedButtons)
obj = new Object()
//obj.runner_id = runner_id
obj.name = indName
obj.toml = ind_editor.getValue()
jsonString = JSON.stringify(obj);
//console.log("pred odeslanim",jsonString)
//cal rest api
$.ajax({
url:"/archived_runners/"+runner_id+"/previewindicator",
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key',
API_KEY); },
method:"PUT",
contentType: "application/json",
data: jsonString,
success:function(data){
//kod pro update/vytvoreni je zde stejny - updatujeme jen zdrojove dictionary
window.$('#indicatorModal').modal('hide');
//console.log(data)
//indName = $('#indicatorName').val()
//updatneme/vytvorime klic v globalni promennou obsahujici vsechny arch data
//TBD nebude fungovat az budu mit vic chartů otevřených - předělat
archData.indicators[0][indName] = data
//pridame pripadne upatneme v ext_data
//smazeme zaznam o indiaktoru v lokalni kopii ext_data (z nich se pak prekresli indikatory)
if ((archData.ext_data !== null) && (archData.ext_data.instantindicators)) {
let index = archData.ext_data.instantindicators.findIndex(indicator => indicator.name === indName);
if (index !== -1) {
archData.ext_data.instantindicators.splice(index, 1);
}
archData.ext_data.instantindicators.push(obj)
}
//neexistuje instantindicators - vytvorime jej a vlozime prvni objekt
else if ((archData.ext_data !== null) && (!archData.ext_data.instantindicators)) {
//a pridame tamtez novy zaznam
archData.ext_data["instantindicators"] =[obj]
}
//glob promenna obsahujici aktualne pridane indikatory a jejich konfigurace
//addedInds[indName] = obj.toml
//get active resolution
const element = document.querySelector('.switcher-active-item');
resolution = element.textContent
//console.log("aktivni rozliseni", resolution)
//vykreslime a pridavame jeste nazev indikatoru, ktery se ma vykreslit do aktivnich
switch_to_interval(resolution, archData, indName)
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
window.alert(JSON.stringify(xhr));
//console.log(JSON.stringify(xhr));
//$('#button_runagain_arch').attr('disabled',false);
}
})
});
});

View File

@@ -13,7 +13,6 @@ var candlestickSeries = null
var volumeSeries = null
var vwapSeries = null
var statusBarConfig = JSON.parse(localStorage.getItem("statusBarConfig"));
var activatedButtons = []
if (statusBarConfig == null) {
statusBarConfig = {}
}
@@ -58,14 +57,6 @@ var indConfig_default = [ {name: "ema", titlevisible: false, embed: true, displa
{name: "sec_price", titlevisible: true, embed: true, display: true, priceScaleId: "right", lastValueVisible: false},]
//console.log(JSON.stringify(indConfig_default, null,null, 2))
function store_activated_buttons_state() {
activatedButtons = []
//ulozime si stav aktivovaných buttonků před změnou - mozna do sluzby
$('#indicatorsButtons .switcher-active-item').each(function() {
activatedButtons.push($(this).text());
});
}
function initialize_statusheader() {
var rows = 2;
@@ -351,7 +342,7 @@ function create_indicator_button(item, index, def) {
itemEl.title = item.cnf
itemEl.style.color = item.series.options().color;
//pokud jde o pridanou on the fly - vybarvime jinak
if (item.added) {
if (item.instant) {
itemEl.style.outline = "solid 1px"
}
itemEl.classList.add('switcher-item');
@@ -411,11 +402,35 @@ function onResetClicked() {
visible: vis });
}
})
store_activated_buttons_state();
}
function generateIndicators(e) {
alert("stratvars generated to clipboard from selected indicators")
store_activated_buttons_state();
ind_tom = ""
indList.forEach(function (item, index) {
if (activatedButtons.includes(item.name)) {
console.log(item)
ind_tom += "\n[stratvars.indicators."+item.name+"]\n" + item.cnf
}
});
if (ind_editor) {
ind_editor.dispose()
}
require(["vs/editor/editor.main"], () => {
ind_editor = monaco.editor.create(document.getElementById('indicatorTOML_editor'), {
value: ind_tom,
language: 'toml',
theme: 'tomlTheme-dark',
automaticLayout: true
});
});
$('#deleteIndicatorButton').hide();
$('#saveIndicatorButton').hide();
window.$('#indicatorModal').modal('show');
}
//editace indikatoru, vcetne vytvoreni noveho
@@ -509,6 +524,7 @@ function populate_indicator_buttons(def) {
//console.log("activatedButtons", activatedButtons)
//console.log("obsahuje item.name", activatedButtons.includes(item.name), item.name)
//pokud existuje v aktivnich pak
//console.log("vytvarime button",item.name,activatedButtons)
if ((activatedButtons) && (activatedButtons.includes(item.name))) {
active = true
}