FE:shortcuts,monacoeditor for stratvars
This commit is contained in:
@ -1244,7 +1244,11 @@ def next(data, state: StrategyState):
|
||||
|
||||
#POKUD je nastaven MIN PROFIT, zkontrolujeme ho a az pripadne pustime CONDITIONY
|
||||
directive_name = "exit_cond_min_profit"
|
||||
exit_cond_min_profit = get_override_for_active_trade(directive_name=directive_name, default_value=safe_get(state.vars, directive_name, None))
|
||||
exit_cond_min_profit_nodir = get_override_for_active_trade(directive_name=directive_name, default_value=safe_get(state.vars, directive_name, None))
|
||||
|
||||
directive_name = "exit_cond_min_profit_" + str(smer)
|
||||
exit_cond_min_profit = get_override_for_active_trade(directive_name=directive_name, default_value=exit_cond_min_profit_nodir)
|
||||
|
||||
|
||||
#máme nastavený exit_cond_min_profit
|
||||
# zjistíme, zda jsme v daném profit a případně nepustíme dál
|
||||
|
||||
@ -823,8 +823,8 @@ def delete_archived_runners_byID(id: UUID):
|
||||
print("log deleted",resl.rowcount)
|
||||
conn.commit()
|
||||
print("commit")
|
||||
if resh.rowcount == 0 or resd.rowcount == 0:
|
||||
return -1, "not found "+str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount)
|
||||
# if resh.rowcount == 0 or resd.rowcount == 0:
|
||||
# return -1, "not found "+str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount)
|
||||
return 0, str(resh.rowcount) + " " + str(resd.rowcount) + " " + str(resl.rowcount)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@ -17,12 +17,12 @@
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css">
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.js" integrity="sha256-a9jBBRygX1Bh5lt8GZjXDzyOB+bWve9EiO7tROUtj/E=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||
<script src="/static/js/jquery.serializejson.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
|
||||
|
||||
|
||||
|
||||
<script src="https://cdn.datatables.net/select/1.6.2/js/dataTables.select.min.js"></script>
|
||||
|
||||
|
||||
@ -45,7 +45,25 @@
|
||||
<!-- <script src="https://cdn.datatables.net/select/1.6.2/js/dataTables.select.min.js"></script> -->
|
||||
<script src="/static/js/fast-toml.js" type="text/javascript"></script>
|
||||
|
||||
|
||||
<!-- <script>
|
||||
// require is provided by loader.min.js.
|
||||
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs' }});
|
||||
require(["vs/editor/editor.main"], () => {
|
||||
monaco.editor.create(document.getElementById('stratvars_editor'), {
|
||||
value: `function x() {
|
||||
console.log("Hello world!");
|
||||
}`,
|
||||
language: 'javascript',
|
||||
theme: 'vs-dark',
|
||||
automaticLayout: true
|
||||
});
|
||||
});
|
||||
</script> -->
|
||||
<!-- predelat na local z cdn -->
|
||||
<link rel="stylesheet" data-name="vs/editor/editor.main" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs/editor/editor.main.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs/loader.min.js"></script>
|
||||
|
||||
|
||||
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/editor/editor.main.js"></script> -->
|
||||
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/loader.min.js"></script> -->
|
||||
</head>
|
||||
@ -176,12 +194,12 @@
|
||||
<div class="legend" id="legendArchive"></div>
|
||||
</div> -->
|
||||
<div id="controls">
|
||||
<button id="button_edit_arch" class="btn btn-outline-success btn-sm">Edit</button>
|
||||
<button id="button_delete_arch" class="btn btn-outline-success btn-sm">Delete</button>
|
||||
<button id="button_edit_arch" class="btn btn-outline-success btn-sm">Edit(a)</button>
|
||||
<button id="button_delete_arch" class="btn btn-outline-success btn-sm">Delete(d)</button>
|
||||
<button id="button_show_arch" class="btn btn-outline-success btn-sm">Show</button>
|
||||
<button id="button_refresh" class="refresh btn btn-outline-success btn-sm">Refresh</button>
|
||||
<button id="button_compare_arch" class="refresh btn btn-outline-success btn-sm">Compare</button>
|
||||
<button id="button_runagain_arch" class="refresh btn btn-outline-success btn-sm">Run Again</button>
|
||||
<button id="button_runagain_arch" class="refresh btn btn-outline-success btn-sm">Run Again(r)</button>
|
||||
<!-- <button id="button_stopall" class="btn btn-outline-success btn-sm">Stop All</button>
|
||||
<button id="button_refresh" class="btn btn-outline-success btn-sm">Refresh</button> -->
|
||||
</div>
|
||||
@ -282,7 +300,8 @@
|
||||
<div id="controlsStratin">
|
||||
<button id="button_add" class="btn btn-outline-success btn-sm">Add</button>
|
||||
<button id="button_add_json" class="btn btn-outline-success btn-sm">Add JSON</button>
|
||||
<button id="button_edit" class="btn btn-outline-success btn-sm">Edit</button>
|
||||
<button id="button_edit" class="btn btn-outline-success btn-sm">Edit(e)</button>
|
||||
<button id="button_edit_stratvars" class="btn btn-outline-success btn-sm">Stratvars(s)</button>
|
||||
<button id="button_dup" class="btn btn-outline-success btn-sm">Duplicate</button>
|
||||
<button id="button_copy" class="btn btn-outline-success btn-sm">Copy JSON</button>
|
||||
<button id="button_delete" class="btn btn-outline-success btn-sm">Delete</button>
|
||||
@ -355,9 +374,9 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<!-- <div class="form-group">
|
||||
<div id="editor"></div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
|
||||
<!-- Create a textarea for saving content -->
|
||||
@ -411,6 +430,33 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="stratvarsModal" class="modal fade" style="--bs-modal-width: 900px;">
|
||||
<div class="modal-dialog">
|
||||
<form method="post" id="stratvarsForm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title_json"><i class="fa fa-plus"></i>Edit Stratvars</h4>
|
||||
<button type="button" name="stratvars_close_x" id="stratvars_close_x" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body" style="display: block;">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" id="stratvar_id" name="stratvar_id" placeholder="id" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<div id="stratvars_editor" style="height:700px;border:1px solid black;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="button" name="stratvars_save" id="stratvars_save" class="btn btn-primary" value="Save" />
|
||||
<input type="button" name="stratvars_save_exit" id="stratvars_save_exit" class="btn btn-primary" value="Save&Exit" />
|
||||
<button type="button" name="stratvars_close" id="stratvars_close" class="btn btn-secondary">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="jsonModal" class="modal fade">
|
||||
<div class="modal-dialog">
|
||||
<form method="post" id="jsonForm">
|
||||
@ -592,7 +638,6 @@
|
||||
</div>
|
||||
<script src="/static/js/config.js"></script>
|
||||
<script type="text/javascript" src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
|
||||
<script src="/static/js/jquery.serializejson.js"></script>
|
||||
<script src="/static/js/utils.js"></script>
|
||||
<script src="/static/js/archivechart.js"></script>
|
||||
<script src="/static/js/archivetables.js"></script>
|
||||
|
||||
@ -119,6 +119,9 @@ $(document).ready(function () {
|
||||
//delete button
|
||||
$('#button_delete_arch').click(function () {
|
||||
rows = archiveRecords.rows('.selected');
|
||||
if (rows == undefined) {
|
||||
return
|
||||
}
|
||||
$('#listofids').html("");
|
||||
|
||||
if(rows.data().length > 0 ) {
|
||||
@ -138,6 +141,9 @@ $(document).ready(function () {
|
||||
//edit button
|
||||
$('#button_edit_arch').click(function () {
|
||||
row = archiveRecords.row('.selected').data();
|
||||
if (rows == undefined) {
|
||||
return
|
||||
}
|
||||
window.$('#editModalArchive').modal('show');
|
||||
$('#editidarchive').val(row.id);
|
||||
$('#editnote').val(row.note);
|
||||
|
||||
@ -7,18 +7,7 @@
|
||||
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
||||
*/
|
||||
(function (factory) {
|
||||
/* global define, require, module */
|
||||
if (typeof define === "function" && define.amd) { // AMD. Register as an anonymous module.
|
||||
define(["jquery"], factory);
|
||||
} else if (typeof exports === "object") { // Node/CommonJS
|
||||
var jQuery = require("jquery");
|
||||
module.exports = factory(jQuery);
|
||||
} else { // Browser globals (zepto supported)
|
||||
factory(window.jQuery || window.Zepto || window.$); // Zepto supported on browsers as well
|
||||
}
|
||||
|
||||
}(function ($) {
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
var rCRLF = /\r?\n/g;
|
||||
@ -335,4 +324,4 @@
|
||||
var isUndefined = function(obj) { return obj === void 0; }; // safe check for undefined values
|
||||
var isValidArrayIndex = function(val) { return /^[0-9]+$/.test(String(val)); }; // 1,2,3,4 ... are valid array indexes
|
||||
var isArray = Array.isArray || function(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; };
|
||||
}));
|
||||
})(jQuery);
|
||||
@ -38,9 +38,65 @@ function is_stratin_running(id) {
|
||||
return running
|
||||
}
|
||||
|
||||
let editor;
|
||||
|
||||
//STRATIN and RUNNERS TABELS
|
||||
$(document).ready(function () {
|
||||
|
||||
//incialize TOML LANGUAGE IN MONACO
|
||||
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs' }});
|
||||
|
||||
require(["vs/editor/editor.main"], () => {
|
||||
|
||||
// Register the TOML language
|
||||
monaco.languages.register({ id: 'toml' });
|
||||
|
||||
// Define the TOML language configuration
|
||||
monaco.languages.setLanguageConfiguration('toml', {
|
||||
comments: {
|
||||
lineComment: '#',
|
||||
},
|
||||
brackets: [['[', ']']], // Define brackets used in TOML arrays
|
||||
autoClosingPairs: [
|
||||
// Define auto-closing pairs for quotes
|
||||
{ open: '"', close: '"', notIn: ['string', 'comment'] },
|
||||
{ open: "'", close: "'", notIn: ['string', 'comment'] },
|
||||
],
|
||||
});
|
||||
|
||||
// Define the TOML tokenizer
|
||||
monaco.languages.setMonarchTokensProvider('toml', {
|
||||
tokenizer: {
|
||||
root: [
|
||||
[/#.*/, 'comment'], // Comments
|
||||
[/".*"/, 'string'], // Double-quoted strings
|
||||
[/'[^']*'/, 'string'], // Single-quoted strings
|
||||
[/-?\d+\.\d+/, 'number'], // Floating-point numbers (including negative)
|
||||
[/-?\d+/, 'number'], // Integer numbers (including negative)
|
||||
[/\btrue\b/, 'boolean-true'], // True values
|
||||
[/\bfalse\b/, 'boolean-false'], // False values
|
||||
[/=\s*/, 'delimiter'], // Key-Value separator
|
||||
[/\[.*\]/, 'array'], // Array brackets
|
||||
[/\.\s*(and|or)\s*\./, 'logical-operator'],
|
||||
[/[^#=\[\]]+/, 'keyword'], // Keywords (anything not covered above)
|
||||
[/[ \t\r\n]+/, 'white'], // Whitespace
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
// Define the theme for highlighting true and false values
|
||||
monaco.editor.defineTheme('tomlTheme-dark', {
|
||||
colors: {},
|
||||
base: 'vs-dark', // Use the VS Code Dark Theme as a base
|
||||
inherit: true,
|
||||
rules: [
|
||||
{ token: 'boolean-true', foreground: '009485', fontStyle:"" }, // Use the same color as VS Code for true
|
||||
{ token: 'boolean-false', foreground: 'e45649', fontStyle:"" }, // Use the same color as VS Code for false
|
||||
],
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
stratinRecords.ajax.reload();
|
||||
runnerRecords.ajax.reload();
|
||||
|
||||
@ -56,6 +112,7 @@ $(document).ready(function () {
|
||||
$('#button_stop').attr('disabled','disabled');
|
||||
$('#button_connect').attr('disabled','disabled');
|
||||
$('#button_edit').attr('disabled','disabled');
|
||||
$('#button_edit_stratvars').attr('disabled','disabled');
|
||||
$('#button_dup').attr('disabled','disabled');
|
||||
$('#button_copy').attr('disabled','disabled');
|
||||
$('#button_delete').attr('disabled','disabled');
|
||||
@ -68,6 +125,7 @@ $(document).ready(function () {
|
||||
$('#button_dup').attr('disabled','disabled');
|
||||
$('#button_copy').attr('disabled','disabled');
|
||||
$('#button_edit').attr('disabled','disabled');
|
||||
$('#button_edit_stratvars').attr('disabled','disabled');
|
||||
$('#button_delete').attr('disabled','disabled');
|
||||
$('#button_run').attr('disabled','disabled');
|
||||
} else {
|
||||
@ -76,6 +134,7 @@ $(document).ready(function () {
|
||||
$('#button_dup').attr('disabled',false);
|
||||
$('#button_copy').attr('disabled',false);
|
||||
$('#button_edit').attr('disabled',false);
|
||||
$('#button_edit_stratvars').attr('disabled',false);
|
||||
$('#button_delete').attr('disabled',false);
|
||||
$('#button_run').attr('disabled',false);
|
||||
}
|
||||
@ -446,6 +505,9 @@ $(document).ready(function () {
|
||||
//edit button
|
||||
$('#button_edit').click(function () {
|
||||
row = stratinRecords.row('.selected').data();
|
||||
if (row== undefined) {
|
||||
return
|
||||
}
|
||||
window.$('#recordModal').modal('show');
|
||||
$('#id').val(row.id);
|
||||
$('#id2').val(row.id2);
|
||||
@ -462,22 +524,6 @@ $(document).ready(function () {
|
||||
$('.modal-title').html(" Edit Records");
|
||||
$('#action').val('updateRecord');
|
||||
$('#save').val('Save');
|
||||
//code for toml editor
|
||||
// Initialize Monaco Editor
|
||||
|
||||
// require.config({ paths: { vs: 'monaco-editor/min/vs' } });
|
||||
// require(['vs/editor/editor.main'], function () {
|
||||
// var editor = $("#editor").monacoEditor({
|
||||
// language: "toml",
|
||||
// value: row.stratvars_conf
|
||||
// });
|
||||
// // Get content from Monaco Editor and set it to the textarea using jQuery
|
||||
// editor.getModels()[0].onDidChangeContent(function() {
|
||||
// var tomlContent = monaco.editor.getModels()[0].getValue();
|
||||
// $('#stratvars_conf').val(tomlContent);
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
});
|
||||
//delete button
|
||||
@ -493,9 +539,28 @@ $(document).ready(function () {
|
||||
$('#button_add_json').click(function () {
|
||||
window.$('#jsonModal').modal('show');
|
||||
});
|
||||
|
||||
$('#button_edit_stratvars').click(function () {
|
||||
row = stratinRecords.row('.selected').data();
|
||||
if (row== undefined) {
|
||||
return
|
||||
}
|
||||
$('#stratvar_id').val(row.id);
|
||||
require(["vs/editor/editor.main"], () => {
|
||||
editor = monaco.editor.create(document.getElementById('stratvars_editor'), {
|
||||
value: row.stratvars_conf,
|
||||
language: 'toml',
|
||||
theme: 'tomlTheme-dark',
|
||||
automaticLayout: true
|
||||
});
|
||||
});
|
||||
window.$('#stratvarsModal').modal('show');
|
||||
//$('#stratvars_editor_val').val(row.stratvars_conf);
|
||||
});
|
||||
} );
|
||||
|
||||
|
||||
|
||||
//stratin table
|
||||
var stratinRecords =
|
||||
$('#stratinTable').DataTable( {
|
||||
@ -696,6 +761,81 @@ $("#runModal").on('submit','#runForm', function(event){
|
||||
})
|
||||
});
|
||||
|
||||
$('#stratvars_close').click(function () {
|
||||
console.log("disposed?")
|
||||
editor.dispose();
|
||||
window.$('#stratvarsModal').modal('hide');
|
||||
});
|
||||
|
||||
$('#stratvars_close_x').click(function () {
|
||||
editor.dispose();
|
||||
window.$('#stratvarsModal').modal('hide');
|
||||
});
|
||||
|
||||
//EDIT STRATVARS MONACO
|
||||
$('#stratvars_save').click(function () {
|
||||
save_stratvars(exit=false);
|
||||
});
|
||||
|
||||
$('#stratvars_save_exit').click(function () {
|
||||
save_stratvars(exit=true)
|
||||
});
|
||||
|
||||
function save_stratvars(exit) {
|
||||
row = stratinRecords.row('.selected').data();
|
||||
const rec = new Object()
|
||||
rec.id = $('#stratvar_id').val()
|
||||
if (row.id ==! rec.id) {
|
||||
window.alert("Overwrite check,. Pozor neco spatne, IDcka se nerovnaji")
|
||||
return
|
||||
}
|
||||
rec.id2 = row.id2
|
||||
rec.name =row.name
|
||||
rec.symbol =row.symbol
|
||||
rec.class_name =row.class_name
|
||||
rec.script =row.script
|
||||
rec.open_rush =row.open_rush
|
||||
rec.close_rush = row.close_rush
|
||||
rec.add_data_conf = row.add_data_conf
|
||||
rec.stratvars_conf = editor.getValue()
|
||||
rec.note = row.note
|
||||
rec.history = row.history
|
||||
|
||||
jsonString = JSON.stringify(rec, null, 2);
|
||||
console.log("pred odeslanim editu", jsonString)
|
||||
$('#stratvars_save').attr('disabled','disabled');
|
||||
$('#stratvars_save_exit').attr('disabled','disabled');
|
||||
|
||||
$.ajax({
|
||||
url:"/stratins/"+rec.id,
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader('X-API-Key',
|
||||
API_KEY); },
|
||||
method:"PATCH",
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
data: jsonString,
|
||||
success:function(data){
|
||||
$('#stratvars_save').attr('disabled',false);
|
||||
$('#stratvars_save_exit').attr('disabled',false);
|
||||
if (exit) {
|
||||
window.$('#stratvarsModal').modal('hide');
|
||||
editor.dispose();
|
||||
$('#stratvar_id').val("");
|
||||
stratinRecords.ajax.reload();
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
var err = eval("(" + xhr.responseText + ")");
|
||||
window.alert(JSON.stringify(xhr));
|
||||
console.log(JSON.stringify(xhr));
|
||||
$('#stratvars_save').attr('disabled',false);
|
||||
$('#stratvars_save_exit').attr('disabled',false);
|
||||
}
|
||||
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
//modal na add/edit
|
||||
$("#recordModal").on('submit','#recordForm', function(event){
|
||||
|
||||
@ -488,23 +488,26 @@ function set_timestamp(timestamp) {
|
||||
Mousetrap.bind('e', function() {
|
||||
$( "#button_edit" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('a', function() {
|
||||
$( "#button_add" ).trigger( "click" );
|
||||
});
|
||||
// Mousetrap.bind('a', function() {
|
||||
// $( "#button_add" ).trigger( "click" );
|
||||
// });
|
||||
Mousetrap.bind('d', function() {
|
||||
$( "#button_dup" ).trigger( "click" );
|
||||
$( "#button_delete_arch" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('c', function() {
|
||||
$( "#button_copy" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('r', function() {
|
||||
$( "#button_run" ).trigger( "click" );
|
||||
$( "#button_runagain_arch" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('p', function() {
|
||||
$( "#button_pause" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('s', function() {
|
||||
$( "#button_stop" ).trigger( "click" );
|
||||
$( "#button_edit_stratvars" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('a', function() {
|
||||
$( "#button_edit_arch" ).trigger( "click" );
|
||||
});
|
||||
Mousetrap.bind('j', function() {
|
||||
$( "#button_add_json" ).trigger( "click" );
|
||||
|
||||
Reference in New Issue
Block a user