refaktor gui jdeme na live
This commit is contained in:
32
testy/tinyDBselect.py
Normal file
32
testy/tinyDBselect.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
from typing import Any, List
|
||||||
|
from uuid import UUID, uuid4
|
||||||
|
import pickle
|
||||||
|
from alpaca.data.historical import StockHistoricalDataClient
|
||||||
|
from alpaca.data.requests import StockTradesRequest, StockBarsRequest
|
||||||
|
from alpaca.data.enums import DataFeed
|
||||||
|
from alpaca.data.timeframe import TimeFrame
|
||||||
|
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account
|
||||||
|
from v2realbot.common.model import StrategyInstance, Runner, RunRequest, RunArchive, RunArchiveDetail, RunArchiveChange
|
||||||
|
from v2realbot.utils.utils import AttributeDict, zoneNY, dict_replace_value, Store, parse_toml_string, json_serial
|
||||||
|
from datetime import datetime
|
||||||
|
from threading import Thread, current_thread, Event, enumerate
|
||||||
|
from v2realbot.config import STRATVARS_UNCHANGEABLES, ACCOUNT1_LIVE_API_KEY, ACCOUNT1_LIVE_SECRET_KEY, DATA_DIR
|
||||||
|
import importlib
|
||||||
|
from queue import Queue
|
||||||
|
from tinydb import TinyDB, Query, where
|
||||||
|
from tinydb.operations import set
|
||||||
|
import json
|
||||||
|
from rich import print
|
||||||
|
|
||||||
|
arch_header_file = DATA_DIR + "/arch_header.json"
|
||||||
|
arch_detail_file = DATA_DIR + "/arch_detail.json"
|
||||||
|
#db layer to store runner archive
|
||||||
|
db_arch_h = TinyDB(arch_header_file, default=json_serial)
|
||||||
|
db_arch_d = TinyDB(arch_detail_file, default=json_serial)
|
||||||
|
|
||||||
|
|
||||||
|
# res = db_arch_h.update(set('note', "ahoj"), where('id') == "74aa524e-3ed4-41fb-8166-f20946520344")
|
||||||
|
# print(res)
|
||||||
|
res = db_arch_d.all()
|
||||||
|
print(res)
|
||||||
Binary file not shown.
Binary file not shown.
@ -153,6 +153,11 @@ class TradeUpdate(BaseModel):
|
|||||||
cash: Optional[float]
|
cash: Optional[float]
|
||||||
pos_avg_price: Optional[float]
|
pos_avg_price: Optional[float]
|
||||||
|
|
||||||
|
|
||||||
|
class RunArchiveChange(BaseModel):
|
||||||
|
id: UUID
|
||||||
|
note: str
|
||||||
|
|
||||||
#Contains archive of running strategies (runner) - master
|
#Contains archive of running strategies (runner) - master
|
||||||
class RunArchive(BaseModel):
|
class RunArchive(BaseModel):
|
||||||
#unique id of algorun
|
#unique id of algorun
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from v2realbot.enums.enums import Mode, Account, FillCondition
|
|||||||
from appdirs import user_data_dir
|
from appdirs import user_data_dir
|
||||||
|
|
||||||
#no print in console
|
#no print in console
|
||||||
QUIET_MODE = True
|
QUIET_MODE = False
|
||||||
#how many consecutive trades with the fill price are necessary for LIMIT fill to happen in backtesting
|
#how many consecutive trades with the fill price are necessary for LIMIT fill to happen in backtesting
|
||||||
#0 - optimistic, every knot high will fill the order
|
#0 - optimistic, every knot high will fill the order
|
||||||
#N - N consecutive trades required
|
#N - N consecutive trades required
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from alpaca.data.requests import StockTradesRequest, StockBarsRequest
|
|||||||
from alpaca.data.enums import DataFeed
|
from alpaca.data.enums import DataFeed
|
||||||
from alpaca.data.timeframe import TimeFrame
|
from alpaca.data.timeframe import TimeFrame
|
||||||
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account
|
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account
|
||||||
from v2realbot.common.model import StrategyInstance, Runner, RunRequest, RunArchive, RunArchiveDetail
|
from v2realbot.common.model import StrategyInstance, Runner, RunRequest, RunArchive, RunArchiveDetail, RunArchiveChange
|
||||||
from v2realbot.utils.utils import AttributeDict, zoneNY, dict_replace_value, Store, parse_toml_string, json_serial
|
from v2realbot.utils.utils import AttributeDict, zoneNY, dict_replace_value, Store, parse_toml_string, json_serial
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Thread, current_thread, Event, enumerate
|
from threading import Thread, current_thread, Event, enumerate
|
||||||
@ -37,10 +37,10 @@ def get_all_runners():
|
|||||||
if len(db.runners) > 0:
|
if len(db.runners) > 0:
|
||||||
#print(db.runners)
|
#print(db.runners)
|
||||||
for i in db.runners:
|
for i in db.runners:
|
||||||
i.run_profit = round(i.run_instance.state.profit,2)
|
i.run_profit = round(float(i.run_instance.state.profit),2)
|
||||||
i.run_trade_count = len(i.run_instance.state.tradeList)
|
i.run_trade_count = len(i.run_instance.state.tradeList)
|
||||||
i.run_positions = i.run_instance.state.positions
|
i.run_positions = i.run_instance.state.positions
|
||||||
i.run_avgp = round(i.run_instance.state.avgp,3)
|
i.run_avgp = round(float(i.run_instance.state.avgp),3)
|
||||||
return (0, db.runners)
|
return (0, db.runners)
|
||||||
else:
|
else:
|
||||||
return (0, [])
|
return (0, [])
|
||||||
@ -419,10 +419,10 @@ def archive_runner(runner: Runner, strat: StrategyInstance):
|
|||||||
bt_from=bp_from,
|
bt_from=bp_from,
|
||||||
bt_to = bp_to,
|
bt_to = bp_to,
|
||||||
stratvars = strat.state.vars,
|
stratvars = strat.state.vars,
|
||||||
profit=round(strat.state.profit,2),
|
profit=round(float(strat.state.profit),2),
|
||||||
trade_count=len(strat.state.tradeList),
|
trade_count=len(strat.state.tradeList),
|
||||||
end_positions=strat.state.positions,
|
end_positions=strat.state.positions,
|
||||||
end_positions_avgp=round(strat.state.avgp,3),
|
end_positions_avgp=round(float(strat.state.avgp),3),
|
||||||
open_orders=9999
|
open_orders=9999
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ def archive_runner(runner: Runner, strat: StrategyInstance):
|
|||||||
print("archive runner finished")
|
print("archive runner finished")
|
||||||
return 0, str(resh) + " " + str(resd)
|
return 0, str(resh) + " " + str(resd)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print("Exception in archive_runner: " + str(e))
|
||||||
return -2, str(e)
|
return -2, str(e)
|
||||||
|
|
||||||
def get_all_archived_runners():
|
def get_all_archived_runners():
|
||||||
@ -454,13 +454,23 @@ def delete_archived_runners_byID(id: UUID):
|
|||||||
return 0, str(resh) + " " + str(resd)
|
return 0, str(resh) + " " + str(resd)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return -2, str(e)
|
return -2, str(e)
|
||||||
|
|
||||||
|
#edit archived runner note
|
||||||
|
def edit_archived_runners(runner_id: UUID, archChange: RunArchiveChange):
|
||||||
|
try:
|
||||||
|
res = db_arch_h.update(set('note', archChange.note), where('id') == str(runner_id))
|
||||||
|
if len(res) == 0:
|
||||||
|
return -1, "not found "+str(runner_id)
|
||||||
|
return 0, runner_id
|
||||||
|
except Exception as e:
|
||||||
|
return -2, str(e)
|
||||||
|
|
||||||
def get_all_archived_runners_detail():
|
def get_all_archived_runners_detail():
|
||||||
res = db_arch_d.all()
|
res = db_arch_d.all()
|
||||||
return 0, res
|
return 0, res
|
||||||
|
|
||||||
def get_archived_runner_details_byID(id: UUID):
|
def get_archived_runner_details_byID(id: UUID):
|
||||||
res = db_arch_d.get(where('id') == id)
|
res = db_arch_d.get(where('id') == str(id))
|
||||||
if res==None:
|
if res==None:
|
||||||
return -2, "not found"
|
return -2, "not found"
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from fastapi.security import APIKeyHeader
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
import v2realbot.controller.services as cs
|
import v2realbot.controller.services as cs
|
||||||
from v2realbot.common.model import StrategyInstance, RunnerView, RunRequest, Trade, RunArchive, RunArchiveDetail, Bar
|
from v2realbot.common.model import StrategyInstance, RunnerView, RunRequest, Trade, RunArchive, RunArchiveDetail, Bar, RunArchiveChange
|
||||||
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Depends, HTTPException, status, WebSocketException, Cookie, Query
|
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Depends, HTTPException, status, WebSocketException, Cookie, Query
|
||||||
from fastapi.responses import HTMLResponse, FileResponse
|
from fastapi.responses import HTMLResponse, FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
@ -282,6 +282,16 @@ def _delete_archived_runners_byID(runner_id):
|
|||||||
elif res < 0:
|
elif res < 0:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Error: {res}:{id}")
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Error: {res}:{id}")
|
||||||
|
|
||||||
|
#edit archived runner ("note",..)
|
||||||
|
@app.patch("/archived_runners/{runner_id}", dependencies=[Depends(api_key_auth)])
|
||||||
|
def _edit_archived_runners(archChange: RunArchiveChange, runner_id: UUID):
|
||||||
|
res, id = cs.edit_archived_runners(runner_id=runner_id, archChange=archChange)
|
||||||
|
if res == 0: return runner_id
|
||||||
|
elif res == -1:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Error not found: {res}:{runner_id}")
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error not changed: {res}:{runner_id}")
|
||||||
|
|
||||||
#get all archived runners detail
|
#get all archived runners detail
|
||||||
@app.get("/archived_runners_detail/", dependencies=[Depends(api_key_auth)])
|
@app.get("/archived_runners_detail/", dependencies=[Depends(api_key_auth)])
|
||||||
def _get_all_archived_runners_detail() -> list[RunArchiveDetail]:
|
def _get_all_archived_runners_detail() -> list[RunArchiveDetail]:
|
||||||
|
|||||||
@ -149,8 +149,9 @@
|
|||||||
<div class="legend" id="legendArchive"></div>
|
<div class="legend" id="legendArchive"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
<button id="button_show_arch" class="btn btn-outline-success btn-sm">Show</button>
|
<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_delete_arch" class="btn btn-outline-success btn-sm">Delete</button>
|
||||||
|
<button id="button_show_arch" class="btn btn-outline-success btn-sm">Show</button>
|
||||||
<!-- <button id="button_stopall" class="btn btn-outline-success btn-sm">Stop All</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> -->
|
<button id="button_refresh" class="btn btn-outline-success btn-sm">Refresh</button> -->
|
||||||
</div>
|
</div>
|
||||||
@ -194,13 +195,44 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<input type="submit" name="delete" id="deletearchive" class="btn btn-primary" value="Delete" />
|
<input type="submit" name="delete" id="deletearchive" class="btn btn-primary" value="Delete" />
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="editModalArchive" class="modal fade">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<form method="post" id="editFormArchive">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title"><i class="fa fa-plus"></i> Edit Archive</h4>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="editidarchive" class="form-label">Id</label>
|
||||||
|
<input type="text" class="form-control" id="editidarchive" name="id" placeholder="id" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="note" class="form-label">note</label>
|
||||||
|
<textarea class="form-control" rows="2" id="editnote" name="note"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="stratvars" class="form-label">Stratvars</label>
|
||||||
|
<textarea class="form-control" rows="4" id="editstratvars" name="stratvars"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<input type="submit" name="delete" id="editarchive" class="btn btn-primary" value="Edit" />
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="stratin-table" class="flex-items">
|
<div id="stratin-table" class="flex-items">
|
||||||
<label data-bs-toggle="collapse" data-bs-target="#stratin-table-inner">
|
<label data-bs-toggle="collapse" data-bs-target="#stratin-table-inner">
|
||||||
<h4><span class="badge secondary-bg">Strategies</span></h4>
|
<h4><span class="badge secondary-bg">Strategies</span></h4>
|
||||||
@ -297,7 +329,7 @@
|
|||||||
<!--<input type="hidden" name="id" id="id" />-->
|
<!--<input type="hidden" name="id" id="id" />-->
|
||||||
<!--<input type="hidden" name="action" id="action" value="" />-->
|
<!--<input type="hidden" name="action" id="action" value="" />-->
|
||||||
<input type="submit" name="save" id="save" class="btn btn-primary" value="Save" />
|
<input type="submit" name="save" id="save" class="btn btn-primary" value="Save" />
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -319,7 +351,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<input type="submit" name="delete" id="delete" class="btn btn-primary" value="Delete" />
|
<input type="submit" name="delete" id="delete" class="btn btn-primary" value="Delete" />
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -341,7 +373,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<input type="submit" name="json_add" id="json_add" class="btn btn-primary" value="Add" />
|
<input type="submit" name="json_add" id="json_add" class="btn btn-primary" value="Add" />
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -375,11 +407,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="bt_from" class="form-label">bt_from</label>
|
<label for="bt_from" class="form-label">bt_from</label>
|
||||||
<input type="datetime-local" class="form-control" id="bt_from" name="bt_from" placeholder="2023-04-06T09:00:00Z">
|
<input type="datetime-local" class="form-control" id="bt_from" name="bt_from" placeholder="2023-04-06T09:00:00Z" step="1">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="bt_to" class="form-label">bt_to</label>
|
<label for="bt_to" class="form-label">bt_to</label>
|
||||||
<input type="datetime-local" class="form-control" id="bt_to" name="bt_to" placeholder="2023-04-06T09:00:00Z">
|
<input type="datetime-local" class="form-control" id="bt_to" name="bt_to" placeholder="2023-04-06T09:00:00Z" step="1">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="cash" class="form-label">cash</label>
|
<label for="cash" class="form-label">cash</label>
|
||||||
@ -394,7 +426,7 @@
|
|||||||
<!--<input type="hidden" name="id" id="id" />-->
|
<!--<input type="hidden" name="id" id="id" />-->
|
||||||
<!--<input type="hidden" name="action" id="action" value="" />-->
|
<!--<input type="hidden" name="action" id="action" value="" />-->
|
||||||
<input type="submit" name="run" id="run" class="btn btn-primary" value="Run" />
|
<input type="submit" name="run" id="run" class="btn btn-primary" value="Run" />
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
var tradeDetails = new Map();
|
var tradeDetails = new Map();
|
||||||
var toolTip = null
|
var toolTip = null
|
||||||
|
var CHART_SHOW_TEXT = false
|
||||||
//TRANSFORM object returned from RESTA PI get_arch_run_detail
|
//TRANSFORM object returned from RESTA PI get_arch_run_detail
|
||||||
//to series and markers required by lightweigth chart
|
//to series and markers required by lightweigth chart
|
||||||
//input array object bars = { high: [1,2,3], time: [1,2,3], close: [2,2,2]...}
|
//input array object bars = { high: [1,2,3], time: [1,2,3], close: [2,2,2]...}
|
||||||
@ -46,19 +47,23 @@ function transform_data(data) {
|
|||||||
a_markers = {}
|
a_markers = {}
|
||||||
timestamp = Date.parse(trade.order.filled_at)/1000
|
timestamp = Date.parse(trade.order.filled_at)/1000
|
||||||
if (trade.order.side == "buy") {
|
if (trade.order.side == "buy") {
|
||||||
//line pro avgp markers
|
//avgp lajnu vytvarime jen pokud je v tradeventu prumerna cena
|
||||||
obj["time"] = timestamp;
|
if (trade.pos_avg_price !== null) {
|
||||||
obj["value"] = trade.pos_avg_price;
|
//line pro avgp markers
|
||||||
avgp_buy_line.push(obj)
|
obj["time"] = timestamp;
|
||||||
|
obj["value"] = trade.pos_avg_price;
|
||||||
|
avgp_buy_line.push(obj)
|
||||||
|
|
||||||
//avgp markers pro prumernou cenu aktualnich pozic
|
//avgp markers pro prumernou cenu aktualnich pozic
|
||||||
a_markers["time"] = timestamp
|
a_markers["time"] = timestamp
|
||||||
a_markers["position"] = "aboveBar"
|
a_markers["position"] = "aboveBar"
|
||||||
a_markers["color"] = "#e8c76d"
|
a_markers["color"] = "#e8c76d"
|
||||||
a_markers["shape"] = "arrowDown"
|
a_markers["shape"] = "arrowDown"
|
||||||
// a_markers["text"] = trade.position_qty + " " + parseFloat(trade.pos_avg_price).toFixed(3)
|
if (CHART_SHOW_TEXT)
|
||||||
a_markers["text"] = trade.position_qty
|
// a_markers["text"] = trade.position_qty + " " + parseFloat(trade.pos_avg_price).toFixed(3)
|
||||||
avgp_markers.push(a_markers)
|
a_markers["text"] = CHART_SHOW_TEXT ? trade.position_qty + "/" + parseFloat(trade.pos_avg_price).toFixed(3) :trade.position_qty
|
||||||
|
avgp_markers.push(a_markers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//buy sell markery
|
//buy sell markery
|
||||||
@ -66,11 +71,11 @@ function transform_data(data) {
|
|||||||
marker["time"] = timestamp;
|
marker["time"] = timestamp;
|
||||||
// marker["position"] = (trade.order.side == "buy") ? "belowBar" : "aboveBar"
|
// marker["position"] = (trade.order.side == "buy") ? "belowBar" : "aboveBar"
|
||||||
marker["position"] = (trade.order.side == "buy") ? "inBar" : "aboveBar"
|
marker["position"] = (trade.order.side == "buy") ? "inBar" : "aboveBar"
|
||||||
marker["color"] = (trade.order.side == "buy") ? "blue" : "red"
|
marker["color"] = (trade.order.side == "buy") ? "#cfcbc2" : "red"
|
||||||
//marker["shape"] = (trade.order.side == "buy") ? "arrowUp" : "arrowDown"
|
//marker["shape"] = (trade.order.side == "buy") ? "arrowUp" : "arrowDown"
|
||||||
marker["shape"] = (trade.order.side == "buy") ? "circle" : "arrowDown"
|
marker["shape"] = (trade.order.side == "buy") ? "circle" : "arrowDown"
|
||||||
//marker["text"] = trade.qty + " " + trade.price
|
//marker["text"] = trade.qty + "/" + trade.price
|
||||||
marker["text"] = trade.qty
|
marker["text"] = CHART_SHOW_TEXT ? trade.qty + "/" + trade.price : trade.qty
|
||||||
markers.push(marker)
|
markers.push(marker)
|
||||||
|
|
||||||
//prevedeme iso data na timestampy
|
//prevedeme iso data na timestampy
|
||||||
@ -107,8 +112,16 @@ function transform_data(data) {
|
|||||||
function prepare_data(archRunner, timeframe_amount, timeframe_unit, archivedRunnerDetail) {
|
function prepare_data(archRunner, timeframe_amount, timeframe_unit, archivedRunnerDetail) {
|
||||||
req = {}
|
req = {}
|
||||||
req["symbol"] = archRunner.symbol
|
req["symbol"] = archRunner.symbol
|
||||||
req["datetime_object_from"] = archRunner.bt_from
|
|
||||||
req["datetime_object_to"] = archRunner.bt_to
|
if (archRunner.mode == "backtest") {
|
||||||
|
req["datetime_object_from"] = archRunner.bt_from
|
||||||
|
req["datetime_object_to"] = archRunner.bt_to
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
req["datetime_object_from"] = archRunner.started
|
||||||
|
req["datetime_object_to"] = archRunner.stopped
|
||||||
|
}
|
||||||
req["timeframe_amount"] = timeframe_amount
|
req["timeframe_amount"] = timeframe_amount
|
||||||
req["timeframe_unit"] = timeframe_unit
|
req["timeframe_unit"] = timeframe_unit
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -120,13 +133,13 @@ function prepare_data(archRunner, timeframe_amount, timeframe_unit, archivedRunn
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
data: req,
|
data: req,
|
||||||
success:function(data){
|
success:function(data){
|
||||||
//console.log("bars", JSON.stringify(data))
|
console.log("one minute bars", JSON.stringify(data))
|
||||||
data.map((el)=>{
|
data.map((el)=>{
|
||||||
cas = new Date(el.timestamp)
|
cas = new Date(el.timestamp)
|
||||||
el.time = cas.getTime()/1000;
|
el.time = cas.getTime()/1000;
|
||||||
delete el.timestamp
|
delete el.timestamp
|
||||||
});
|
});
|
||||||
//console.log("bars_after_transformation", JSON.stringify(data))
|
console.log("one min bars_after_transformation", JSON.stringify(data))
|
||||||
oneMinuteBars = data
|
oneMinuteBars = data
|
||||||
chart_archived_run(archRunner, archivedRunnerDetail, oneMinuteBars);
|
chart_archived_run(archRunner, archivedRunnerDetail, oneMinuteBars);
|
||||||
//call function to continue
|
//call function to continue
|
||||||
@ -151,6 +164,7 @@ function chart_archived_run(archRecord, data, oneMinuteBars) {
|
|||||||
toolTip.style.display = 'none';
|
toolTip.style.display = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var transformed_data = transform_data(data)
|
var transformed_data = transform_data(data)
|
||||||
|
|
||||||
//initialize resolutions
|
//initialize resolutions
|
||||||
@ -262,16 +276,20 @@ function chart_archived_run(archRecord, data, oneMinuteBars) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("avgp_buy_line",transformed_data["avgp_buy_line"])
|
||||||
|
console.log("avgp_markers",transformed_data["avgp_markers"])
|
||||||
|
|
||||||
var avgBuyLine = chart.addLineSeries({
|
if (transformed_data["avgp_buy_line"].length > 0) {
|
||||||
// title: "avgpbuyline",
|
var avgBuyLine = chart.addLineSeries({
|
||||||
color: '#e8c76d',
|
// title: "avgpbuyline",
|
||||||
// color: 'transparent',
|
color: '#e8c76d',
|
||||||
lineWidth: 1,
|
// color: 'transparent',
|
||||||
lastValueVisible: false
|
lineWidth: 1,
|
||||||
});
|
lastValueVisible: false
|
||||||
avgBuyLine.setData(transformed_data["avgp_buy_line"]);
|
});
|
||||||
avgBuyLine.setMarkers(transformed_data["avgp_markers"])
|
avgBuyLine.setData(transformed_data["avgp_buy_line"]);
|
||||||
|
avgBuyLine.setMarkers(transformed_data["avgp_markers"])
|
||||||
|
}
|
||||||
|
|
||||||
var markersLine = chart.addLineSeries({
|
var markersLine = chart.addLineSeries({
|
||||||
// title: "avgpbuyline",
|
// title: "avgpbuyline",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ $(document).ready(function () {
|
|||||||
//disable buttons (enable on row selection)
|
//disable buttons (enable on row selection)
|
||||||
$('#button_show_arch').attr('disabled','disabled');
|
$('#button_show_arch').attr('disabled','disabled');
|
||||||
$('#button_delete_arch').attr('disabled','disabled');
|
$('#button_delete_arch').attr('disabled','disabled');
|
||||||
|
$('#button_edit_arch').attr('disabled','disabled');
|
||||||
|
|
||||||
|
|
||||||
//selectable rows in archive table
|
//selectable rows in archive table
|
||||||
@ -13,11 +14,13 @@ $(document).ready(function () {
|
|||||||
$(this).removeClass('selected');
|
$(this).removeClass('selected');
|
||||||
$('#button_show_arch').attr('disabled','disabled');
|
$('#button_show_arch').attr('disabled','disabled');
|
||||||
$('#button_delete_arch').attr('disabled','disabled');
|
$('#button_delete_arch').attr('disabled','disabled');
|
||||||
|
$('#button_edit_arch').attr('disabled','disabled');
|
||||||
} else {
|
} else {
|
||||||
stratinRecords.$('tr.selected').removeClass('selected');
|
stratinRecords.$('tr.selected').removeClass('selected');
|
||||||
$(this).addClass('selected');
|
$(this).addClass('selected');
|
||||||
$('#button_show_arch').attr('disabled',false);
|
$('#button_show_arch').attr('disabled',false);
|
||||||
$('#button_delete_arch').attr('disabled',false);
|
$('#button_delete_arch').attr('disabled',false);
|
||||||
|
$('#button_edit_arch').attr('disabled',false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,6 +31,13 @@ $(document).ready(function () {
|
|||||||
$('#delidarchive').val(row.id);
|
$('#delidarchive').val(row.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//edit button
|
||||||
|
$('#button_edit_arch').click(function () {
|
||||||
|
row = archiveRecords.row('.selected').data();
|
||||||
|
window.$('#editModalArchive').modal('show');
|
||||||
|
$('#editidarchive').val(row.id);
|
||||||
|
$('#editstratvars').val(JSON.stringify(row.stratvars,null,2));
|
||||||
|
});
|
||||||
|
|
||||||
//show button
|
//show button
|
||||||
$('#button_show_arch').click(function () {
|
$('#button_show_arch').click(function () {
|
||||||
@ -44,6 +54,8 @@ $(document).ready(function () {
|
|||||||
success:function(data){
|
success:function(data){
|
||||||
$('#button_show_arch').attr('disabled',false);
|
$('#button_show_arch').attr('disabled',false);
|
||||||
$('#chartContainerInner').addClass("show");
|
$('#chartContainerInner').addClass("show");
|
||||||
|
$("#lines").html("<pre>"+JSON.stringify(row.stratvars,null,2)+"</pre>")
|
||||||
|
|
||||||
//$('#chartArchive').append(JSON.stringify(data,null,2));
|
//$('#chartArchive').append(JSON.stringify(data,null,2));
|
||||||
console.log(JSON.stringify(data,null,2));
|
console.log(JSON.stringify(data,null,2));
|
||||||
//if lower res is required call prepare_data otherwise call chart_archived_run()
|
//if lower res is required call prepare_data otherwise call chart_archived_run()
|
||||||
@ -60,6 +72,43 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//edit modal
|
||||||
|
$("#editModalArchive").on('submit','#editFormArchive', function(event){
|
||||||
|
event.preventDefault();
|
||||||
|
$('#editarchive').attr('disabled','disabled');
|
||||||
|
trow = archiveRecords.row('.selected').data();
|
||||||
|
note = $('#editnote').val()
|
||||||
|
var formData = $(this).serializeJSON();
|
||||||
|
row = {}
|
||||||
|
row["id"] = trow.id
|
||||||
|
row["note"] = note
|
||||||
|
jsonString = JSON.stringify(row);
|
||||||
|
console.log("pred odeslanim json string", jsonString)
|
||||||
|
$.ajax({
|
||||||
|
url:"/archived_runners/"+trow.id,
|
||||||
|
beforeSend: function (xhr) {
|
||||||
|
xhr.setRequestHeader('X-API-Key',
|
||||||
|
API_KEY); },
|
||||||
|
method:"PATCH",
|
||||||
|
contentType: "application/json",
|
||||||
|
// dataType: "json",
|
||||||
|
data: jsonString,
|
||||||
|
success:function(data){
|
||||||
|
$('#editFormArchive')[0].reset();
|
||||||
|
window.$('#editModalArchive').modal('hide');
|
||||||
|
$('#editarchive').attr('disabled', false);
|
||||||
|
archiveRecords.ajax.reload();
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
var err = eval("(" + xhr.responseText + ")");
|
||||||
|
window.alert(JSON.stringify(xhr));
|
||||||
|
console.log(JSON.stringify(xhr));
|
||||||
|
$('#editarchive').attr('disabled', false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
//delete modal
|
//delete modal
|
||||||
$("#delModalArchive").on('submit','#delFormArchive', function(event){
|
$("#delModalArchive").on('submit','#delFormArchive', function(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -121,12 +170,12 @@ var archiveRecords =
|
|||||||
{data: 'end_positions_avgp', visible: true},
|
{data: 'end_positions_avgp', visible: true},
|
||||||
{data: 'open_orders', visible: true}
|
{data: 'open_orders', visible: true}
|
||||||
],
|
],
|
||||||
columnDefs: [{
|
// columnDefs: [{
|
||||||
targets: [4,5,8,9],
|
// targets: [4,5,8,9],
|
||||||
render: function ( data, type, row ) {
|
// render: function ( data, type, row ) {
|
||||||
return format_date(data)
|
// return format_date(data)
|
||||||
},
|
// },
|
||||||
}],
|
// }],
|
||||||
order: [[5, 'desc']],
|
order: [[5, 'desc']],
|
||||||
paging: true,
|
paging: true,
|
||||||
lengthChange: false,
|
lengthChange: false,
|
||||||
|
|||||||
@ -115,7 +115,7 @@ function connect(event) {
|
|||||||
|
|
||||||
|
|
||||||
logcnt++;
|
logcnt++;
|
||||||
row = '<div data-toggle="collapse" onclick="set_timestamp(' + logLine.time + ')" data-target="#rec'+logcnt+'">'+logLine.time + " " + logLine.event + ' - '+ (logLine.message == undefined ? "" : logLine.message) +'</div>'
|
row = '<div data-bs-toggle="collapse" onclick="set_timestamp(' + logLine.time + ')" data-bs-target="#rec'+logcnt+'">'+logLine.time + " " + logLine.event + ' - '+ (logLine.message == undefined ? "" : logLine.message) +'</div>'
|
||||||
str_row = JSON.stringify(logLine.details, null, 2)
|
str_row = JSON.stringify(logLine.details, null, 2)
|
||||||
//row_detail = '<div id="rec'+logcnt+'" data-toggle="collapse" data-target="#rec'+logcnt+'"class="collapse pidi"><pre>' + str_row + '</pre></div>'
|
//row_detail = '<div id="rec'+logcnt+'" data-toggle="collapse" data-target="#rec'+logcnt+'"class="collapse pidi"><pre>' + str_row + '</pre></div>'
|
||||||
|
|
||||||
|
|||||||
@ -8,26 +8,26 @@ function populate_real_time_chart() {
|
|||||||
|
|
||||||
$('#chartContainerInner').addClass("show");
|
$('#chartContainerInner').addClass("show");
|
||||||
//const chartOptions = { layout: { textColor: 'black', background: { type: 'solid', color: 'white' } } };
|
//const chartOptions = { layout: { textColor: 'black', background: { type: 'solid', color: 'white' } } };
|
||||||
//var chartOptions = { width: 1045, height: 600, leftPriceScale: {visible: true}}
|
var chartOptions = { width: 1045, height: 600, leftPriceScale: {visible: true}}
|
||||||
var chartOptions = { width: 1045,
|
// var chartOptions = { width: 1045,
|
||||||
height: 600,
|
// height: 600,
|
||||||
leftPriceScale: {visible: true},
|
// leftPriceScale: {visible: true},
|
||||||
layout: {
|
// layout: {
|
||||||
background: {
|
// background: {
|
||||||
type: 'solid',
|
// type: 'solid',
|
||||||
color: '#000000',
|
// color: '#000000',
|
||||||
},
|
// },
|
||||||
textColor: '#d1d4dc',
|
// textColor: '#d1d4dc',
|
||||||
},
|
// },
|
||||||
grid: {
|
// grid: {
|
||||||
vertLines: {
|
// vertLines: {
|
||||||
visible: false,
|
// visible: false,
|
||||||
},
|
// },
|
||||||
horzLines: {
|
// horzLines: {
|
||||||
color: 'rgba(42, 46, 57, 0.5)',
|
// color: 'rgba(42, 46, 57, 0.5)',
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
chart = LightweightCharts.createChart(document.getElementById('chart'), chartOptions);
|
chart = LightweightCharts.createChart(document.getElementById('chart'), chartOptions);
|
||||||
|
|||||||
@ -127,7 +127,7 @@ pre {
|
|||||||
font-size: normal;
|
font-size: normal;
|
||||||
/* font-weight: bold; */
|
/* font-weight: bold; */
|
||||||
display: -webkit-inline-box;
|
display: -webkit-inline-box;
|
||||||
background-color: #128faf;
|
background-color: #dfe4e6;
|
||||||
/* color: white; */
|
/* color: white; */
|
||||||
padding: 1px;
|
padding: 1px;
|
||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
|
|||||||
Reference in New Issue
Block a user