#135 -> BT same period button
This commit is contained in:
@ -1859,13 +1859,13 @@ def get_alpaca_history_bars(symbol: str, datetime_object_from: datetime, datetim
|
||||
"""Returns Bar object
|
||||
"""
|
||||
try:
|
||||
result = []
|
||||
client = StockHistoricalDataClient(ACCOUNT1_LIVE_API_KEY, ACCOUNT1_LIVE_SECRET_KEY, raw_data=False)
|
||||
#datetime_object_from = datetime(2023, 2, 27, 18, 51, 38, tzinfo=datetime.timezone.utc)
|
||||
#datetime_object_to = datetime(2023, 2, 27, 21, 51, 39, tzinfo=datetime.timezone.utc)
|
||||
bar_request = StockBarsRequest(symbol_or_symbols=symbol,timeframe=timeframe, start=datetime_object_from, end=datetime_object_to, feed=ACCOUNT1_LIVE_FEED)
|
||||
#print("before df")
|
||||
bars = client.get_stock_bars(bar_request)
|
||||
result = []
|
||||
##pridavame pro jistotu minutu z obou stran kvuli frontendu
|
||||
business_hours = {
|
||||
# monday = 0, tuesday = 1, ... same pattern as date.weekday()
|
||||
@ -1896,11 +1896,17 @@ def get_alpaca_history_bars(symbol: str, datetime_object_from: datetime, datetim
|
||||
#bars.data[symbol]
|
||||
return 0, result
|
||||
except Exception as e:
|
||||
print(str(e) + format_exc())
|
||||
if OFFLINE_MODE:
|
||||
print("OFFLINE MODE ENABLED")
|
||||
return 0, []
|
||||
return -2, str(e)
|
||||
# Workaround of error when no data foun d AttributeError and has the specific message
|
||||
if isinstance(e, AttributeError) and str(e) == "'NoneType' object has no attribute 'items'":
|
||||
print("Caught the specific AttributeError: 'NoneType' object has no attribute 'items' means NO DATA FOUND")
|
||||
#print(str(e) + format_exc())
|
||||
return 0, result
|
||||
else:
|
||||
print(str(e) + format_exc())
|
||||
if OFFLINE_MODE:
|
||||
print("OFFLINE MODE ENABLED")
|
||||
return 0, []
|
||||
return -2, str(e)
|
||||
# change_archived_runner
|
||||
# delete_archived_runner_details
|
||||
|
||||
|
||||
@ -561,6 +561,7 @@
|
||||
<button id="button_refresh" class="refresh btn btn-outline-success btn-sm">Refresh</button>
|
||||
<button title="Compare selected days" id="button_compare_arch" class="refresh btn btn-outline-success btn-sm">Compare</button>
|
||||
<button title="Run selected day" id="button_runagain_arch" class="refresh btn btn-outline-success btn-sm">Run Again(r)</button>
|
||||
<button title="Runs LIVE/PAPER in BT mode with same dates" id="button_runbt_arch" class="refresh btn btn-outline-success btn-sm">Backtest same period</button>
|
||||
<button title="Select all days on the page" id="button_selpage" class="btn btn-outline-success btn-sm">Select all</button>
|
||||
<button title="Export selected days to XML" id="button_export_xml" class="btn btn-outline-success btn-sm">Export xml</button>
|
||||
<button title="Export selected days to CSV" id="button_export_csv" class="btn btn-outline-success btn-sm">Export csv</button>
|
||||
@ -1150,7 +1151,7 @@
|
||||
|
||||
<!-- <script src="/static/js/utils.js?v=1.01"></script> -->
|
||||
<!-- new util structure and exports and colors -->
|
||||
<script src="/static/js/utils/utils.js?v=1.05"></script>
|
||||
<script src="/static/js/utils/utils.js?v=1.06"></script>
|
||||
<script src="/static/js/utils/exports.js?v=1.04"></script>
|
||||
<script src="/static/js/utils/colors.js?v=1.04"></script>
|
||||
|
||||
@ -1160,10 +1161,10 @@
|
||||
|
||||
<!-- <script src="/static/js/archivetables.js?v=1.05"></script> -->
|
||||
<!-- archiveTables split into separate files -->
|
||||
<script src="/static/js/tables/archivetable/init.js?v=1.11"></script>
|
||||
<script src="/static/js/tables/archivetable/functions.js?v=1.09"></script>
|
||||
<script src="/static/js/tables/archivetable/init.js?v=1.12"></script>
|
||||
<script src="/static/js/tables/archivetable/functions.js?v=1.10"></script>
|
||||
<script src="/static/js/tables/archivetable/modals.js?v=1.07"></script>
|
||||
<script src="/static/js/tables/archivetable/handlers.js?v=1.07"></script>
|
||||
<script src="/static/js/tables/archivetable/handlers.js?v=1.08"></script>
|
||||
|
||||
<!-- Runmanager functionality -->
|
||||
<script src="/static/js/tables/runmanager/init.js?v=1.1"></script>
|
||||
|
||||
@ -78,10 +78,11 @@ function get_detail_and_chart(row) {
|
||||
})
|
||||
}
|
||||
|
||||
//rerun stratin
|
||||
function run_day_again() {
|
||||
//rerun stratin (use to rerun strategy and also to rerun live/paper as bt on same period)
|
||||
function run_day_again(turnintobt=false) {
|
||||
row = archiveRecords.row('.selected').data();
|
||||
$('#button_runagain_arch').attr('disabled',true);
|
||||
var button_name = turnintobt ? '#button_runbt_arch' : '#button_runagain_arch'
|
||||
$(button_name).attr('disabled',true)
|
||||
|
||||
var record1 = new Object()
|
||||
//console.log(JSON.stringify(rows))
|
||||
@ -142,7 +143,7 @@ function run_day_again() {
|
||||
//console.log("Result from second request:", result2);
|
||||
|
||||
//console.log("calling compare")
|
||||
rerun_strategy(result1, result2)
|
||||
rerun_strategy(result1, result2, turnintobt)
|
||||
// Perform your action with the results from both requests
|
||||
// Example:
|
||||
|
||||
@ -154,13 +155,22 @@ function run_day_again() {
|
||||
});
|
||||
|
||||
|
||||
function rerun_strategy(archRunner, stratData) {
|
||||
function rerun_strategy(archRunner, stratData, turnintobt) {
|
||||
record1 = archRunner
|
||||
//console.log(record1)
|
||||
|
||||
var note_prefix = "RERUN "
|
||||
if ((turnintobt) && ((record1.mode == 'live') || (record1.mode == 'paper'))) {
|
||||
record1.mode = 'backtest'
|
||||
record1.bt_from = record1.started
|
||||
record1.bt_to = record1.stopped
|
||||
note_prefix = "BT SAME PERIOD "
|
||||
}
|
||||
|
||||
record1.note = note_prefix + record1.note
|
||||
//nebudeme muset odstanovat pri kazdem pridani noveho atributu v budoucnu
|
||||
//smazeneme nepotrebne a pridame potrebne
|
||||
//do budoucna predelat na vytvoreni noveho objektu
|
||||
//nebudeme muset odstanovat pri kazdem pridani noveho atributu v budoucnu
|
||||
delete record1["end_positions"];
|
||||
delete record1["end_positions_avgp"];
|
||||
delete record1["profit"];
|
||||
@ -172,8 +182,6 @@ function run_day_again() {
|
||||
delete record1["settings"];
|
||||
delete record1["stratvars"];
|
||||
|
||||
record1.note = "RERUN " + record1.note
|
||||
|
||||
if (record1.bt_from == "") {delete record1["bt_from"];}
|
||||
if (record1.bt_to == "") {delete record1["bt_to"];}
|
||||
|
||||
@ -212,7 +220,7 @@ function run_day_again() {
|
||||
contentType: "application/json",
|
||||
data: jsonString,
|
||||
success:function(data){
|
||||
$('#button_runagain_arch').attr('disabled',false);
|
||||
$(button_name).attr('disabled',false);
|
||||
setTimeout(function () {
|
||||
runnerRecords.ajax.reload();
|
||||
stratinRecords.ajax.reload();
|
||||
@ -222,7 +230,7 @@ function run_day_again() {
|
||||
var err = eval("(" + xhr.responseText + ")");
|
||||
window.alert(JSON.stringify(xhr));
|
||||
//console.log(JSON.stringify(xhr));
|
||||
$('#button_runagain_arch').attr('disabled',false);
|
||||
$(button_name).attr('disabled',false);
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -541,6 +549,7 @@ function generateStorageKey(batchId) {
|
||||
function disable_arch_buttons() {
|
||||
//disable buttons (enable on row selection)
|
||||
$('#button_runagain_arch').attr('disabled','disabled');
|
||||
$('#button_runbt_arch').attr('disabled','disabled');
|
||||
$('#button_show_arch').attr('disabled','disabled');
|
||||
$('#button_delete_arch').attr('disabled','disabled');
|
||||
$('#button_delete_batch').attr('disabled','disabled');
|
||||
@ -563,4 +572,10 @@ function enable_arch_buttons() {
|
||||
$('#button_report').attr('disabled',false);
|
||||
$('#button_export_xml').attr('disabled',false);
|
||||
$('#button_export_csv').attr('disabled',false);
|
||||
|
||||
//Backtest same period button is displayed only when row with mode paper/live is selected
|
||||
row = archiveRecords.row('.selected').data();
|
||||
if ((row.mode == 'paper') || (row.mode == 'live')) {
|
||||
$('#button_runbt_arch').attr('disabled',false);
|
||||
}
|
||||
}
|
||||
@ -462,6 +462,11 @@ $(document).ready(function () {
|
||||
//run again button
|
||||
$('#button_runagain_arch').click(run_day_again)
|
||||
|
||||
//run in bt mode
|
||||
$('#button_runbt_arch').click(function() {
|
||||
run_day_again(true);
|
||||
});
|
||||
|
||||
//workaround pro spatne oznacovani selectu i pro group-headery
|
||||
// $('#archiveTable tbody').on('click', 'tr.group-header', function(event) {
|
||||
// var $row = $(this);
|
||||
|
||||
@ -82,7 +82,7 @@ function initialize_archiveRecords() {
|
||||
})
|
||||
|
||||
if (isToday(date)) {
|
||||
console.log("volame isToday s", date)
|
||||
//console.log("volame isToday s", date)
|
||||
//return local time only
|
||||
return '<div title="'+tit+'">'+ 'dnes ' + format_date(data,true,true)+'</div>'
|
||||
}
|
||||
|
||||
@ -994,8 +994,8 @@ JSON.safeStringify = (obj, indent = 2) => {
|
||||
function isToday(someDate) {
|
||||
// Convert input date to Eastern Time
|
||||
var dateInEastern = new Date(someDate.toLocaleString('en-US', { timeZone: 'America/New_York' }));
|
||||
console.log("vstupuje ",someDate)
|
||||
console.log("americky ",dateInEastern)
|
||||
//console.log("vstupuje ",someDate)
|
||||
//console.log("americky ",dateInEastern)
|
||||
// Get today's date in Eastern Time
|
||||
var todayInEastern = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user