Bye bye Restart Button
This commit is contained in:
1 parent
19df7c6835
commit
5f2d8f0c1d
2 files changed
-349
No files matched your search
@@ -1,332 +0,0 @@
|
||||
|
||||
function newRestartSimulation () {
|
||||
const MODULE_NAME = 'Restart Simulation'
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
let thisObject = {
|
||||
visible: true,
|
||||
container: undefined,
|
||||
status: undefined,
|
||||
startOrStop: startOrStop,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
thisObject.container.isDraggeable = false
|
||||
thisObject.container.isWheelable = false
|
||||
thisObject.container.isClickeable = true
|
||||
thisObject.container.detectMouseOver = true
|
||||
|
||||
let selfMouseOverEventSubscriptionId
|
||||
let selfMouseClickEventSubscriptionId
|
||||
let selfMouseNotOverEventSubscriptionId
|
||||
|
||||
let isMouseOver = false
|
||||
let counterTillNextState = 0
|
||||
|
||||
let productCardsToTurnOn = []
|
||||
|
||||
let executionFocusExists = false
|
||||
let idleLabel = ''
|
||||
let isRunning = false
|
||||
|
||||
let eventSubscriptionIdProcessStopped
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize () {
|
||||
thisObject.container.eventHandler.stopListening(selfMouseOverEventSubscriptionId)
|
||||
thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId)
|
||||
thisObject.container.eventHandler.stopListening(selfMouseNotOverEventSubscriptionId)
|
||||
|
||||
systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionIdProcessStopped)
|
||||
systemEventHandler.deleteEventHandler('Cockpit-Restart-Button')
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
}
|
||||
|
||||
function initialize () {
|
||||
thisObject.container.frame.width = 250
|
||||
thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12
|
||||
|
||||
selfMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
|
||||
selfMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
|
||||
|
||||
thisObject.status = 'Ready'
|
||||
|
||||
systemEventHandler.createEventHandler('Cockpit-Restart-Button')
|
||||
|
||||
systemEventHandler.listenToEvent('Jason-Multi-Period', 'Process Stopped', undefined, 'Cockpit-Restart-Button', onResponse, onProcessStopped)
|
||||
|
||||
function onResponse (message) {
|
||||
eventSubscriptionIdProcessStopped = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onProcessStopped (message) {
|
||||
thisObject.status = 'Ready'
|
||||
isRunning = false
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point, purpose) {
|
||||
if (
|
||||
thisObject.visible !== true ||
|
||||
(thisObject.status !== 'Ready' && thisObject.status !== 'Backtesting' && thisObject.status !== 'Live Trading') ||
|
||||
executionFocusExists === false) { return }
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return thisObject.container
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseOver (point) {
|
||||
if (thisObject.container.frame.isThisPointHere(point, true, false) === true) {
|
||||
isMouseOver = true
|
||||
} else {
|
||||
isMouseOver = false
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseNotOver (point) {
|
||||
isMouseOver = false
|
||||
}
|
||||
|
||||
function onMouseClick (event) {
|
||||
startOrStop()
|
||||
}
|
||||
|
||||
async function startOrStop () {
|
||||
try {
|
||||
if (isRunning === false) {
|
||||
thisObject.status = 'Saving'
|
||||
let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer(getUICurrentValues())
|
||||
if (result === false) {
|
||||
thisObject.status = 'Error'
|
||||
counterTillNextState = 500
|
||||
} else {
|
||||
callServer('', 'ResetLogsAndData', onSaved)
|
||||
function onSaved (err) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
logger.write('[ERROR] Restart Simulation -> Can not delete Logs and Simulation data. err = ' + err.messsage)
|
||||
}
|
||||
}
|
||||
if (idleLabel === 'START LIVE TRADING') {
|
||||
let event = {
|
||||
definition: getDefinition()
|
||||
}
|
||||
systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Live-Trading Started', event)
|
||||
thisObject.status = 'Live Trading'
|
||||
} else {
|
||||
let event = {
|
||||
definition: getDefinition()
|
||||
}
|
||||
systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Backstesting Started', event)
|
||||
thisObject.status = 'Backtesting'
|
||||
}
|
||||
|
||||
isRunning = true
|
||||
}
|
||||
} else {
|
||||
/* isRunning === true */
|
||||
systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Stop Requested')
|
||||
isRunning = false
|
||||
thisObject.status = 'Stopping'
|
||||
}
|
||||
} catch (err) {
|
||||
thisObject.status = 'Error'
|
||||
counterTillNextState = 500
|
||||
}
|
||||
}
|
||||
|
||||
function getDefinition () {
|
||||
let definitionNode = canvas.strategySpace.workspace.getProtocolDefinitionNode()
|
||||
definitionNode.uiCurrentValues = getUICurrentValues()
|
||||
return JSON.stringify(definitionNode)
|
||||
}
|
||||
|
||||
function turnOffProductCards () {
|
||||
let productCardsToTurnOff = ['Trading-Simulation', 'Simulation-Conditions', 'Simulation-Strategies', 'Simulation-Trades', 'Live Trading History']
|
||||
for (let i = 0; i < canvas.panelsSpace.panels.length; i++) {
|
||||
let panel = canvas.panelsSpace.panels[i]
|
||||
if (panel.name === 'Products Panel') {
|
||||
for (j = 0; j < panel.productCards.length; j++) {
|
||||
let productCard = panel.productCards[j]
|
||||
if (productCardsToTurnOff.includes(productCard.product.codeName) && productCard.status !== PRODUCT_CARD_STATUS.OFF) {
|
||||
productCard.turnOff()
|
||||
productCardsToTurnOn.push(productCard)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function turnOnProductCards () {
|
||||
for (let i = 0; i < productCardsToTurnOn.length; i++) {
|
||||
let productCard = productCardsToTurnOn[i]
|
||||
productCard.turnOn()
|
||||
}
|
||||
productCardsToTurnOn = []
|
||||
}
|
||||
|
||||
function physics () {
|
||||
labelPhysics()
|
||||
|
||||
if (counterTillNextState > 0) {
|
||||
counterTillNextState--
|
||||
|
||||
if (counterTillNextState === 0) {
|
||||
switch (thisObject.status) {
|
||||
case 'Ready':
|
||||
|
||||
break
|
||||
case 'Saving':
|
||||
|
||||
break
|
||||
case 'Stopping':
|
||||
|
||||
break
|
||||
case 'Error':
|
||||
thisObject.status = 'Ready'
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionPhysics()
|
||||
executionFocusPhysics()
|
||||
}
|
||||
|
||||
function labelPhysics () {
|
||||
idleLabel = 'START BACKTESTING'
|
||||
if (canvas.strategySpace.workspace.definition) {
|
||||
let definition = canvas.strategySpace.workspace.definition
|
||||
if (definition.personalData) {
|
||||
if (definition.personalData.exchangeAccounts) {
|
||||
if (definition.personalData.exchangeAccounts.length > 0) {
|
||||
let exchangeAccount = definition.personalData.exchangeAccounts[0]
|
||||
if (exchangeAccount.keys) {
|
||||
if (exchangeAccount.keys.length > 0) {
|
||||
let key = exchangeAccount.keys[0]
|
||||
idleLabel = 'START LIVE TRADING'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function executionFocusPhysics () {
|
||||
if (canvas.strategySpace.workspace.definition !== undefined) {
|
||||
executionFocusExists = true
|
||||
} else {
|
||||
executionFocusExists = false
|
||||
}
|
||||
}
|
||||
|
||||
function positionPhysics () {
|
||||
thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width - thisObject.container.frame.width - 50
|
||||
thisObject.container.frame.position.y = 6
|
||||
}
|
||||
|
||||
function draw () {
|
||||
if (thisObject.visible !== true || executionFocusExists === false) { return }
|
||||
drawBackground()
|
||||
drawText()
|
||||
}
|
||||
|
||||
function drawBackground () {
|
||||
let params = {
|
||||
cornerRadius: 3,
|
||||
lineWidth: 0.01,
|
||||
container: thisObject.container,
|
||||
borderColor: UI_COLOR.DARK,
|
||||
castShadow: false,
|
||||
opacity: 1
|
||||
}
|
||||
|
||||
switch (thisObject.status) {
|
||||
case 'Ready': {
|
||||
if (isMouseOver === true) {
|
||||
params.backgroundColor = UI_COLOR.TURQUOISE
|
||||
} else {
|
||||
params.backgroundColor = UI_COLOR.DARK_TURQUOISE
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Saving':
|
||||
params.backgroundColor = UI_COLOR.GREY
|
||||
break
|
||||
case 'Backtesting':
|
||||
params.backgroundColor = UI_COLOR.GREEN
|
||||
break
|
||||
case 'Live Trading':
|
||||
params.backgroundColor = UI_COLOR.TITANIUM_YELLOW
|
||||
break
|
||||
case 'Stopping':
|
||||
params.backgroundColor = UI_COLOR.GOLDEN_ORANGE
|
||||
break
|
||||
case 'Error':
|
||||
params.backgroundColor = UI_COLOR.RUSTED_RED
|
||||
break
|
||||
}
|
||||
|
||||
roundedCornersBackground(params)
|
||||
}
|
||||
|
||||
function drawText () {
|
||||
let fontSize
|
||||
let label
|
||||
let xOffset
|
||||
let yOffset
|
||||
|
||||
const OPACITY = 1
|
||||
|
||||
/* We put the params.VALUE in the middle */
|
||||
|
||||
fontSize = 15
|
||||
|
||||
browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
|
||||
switch (thisObject.status) {
|
||||
case 'Ready':
|
||||
label = idleLabel
|
||||
break
|
||||
case 'Saving':
|
||||
label = 'SAVING STRATEGIES CHANGES...'
|
||||
break
|
||||
case 'Backtesting':
|
||||
label = 'STOP BACKTESTING'
|
||||
break
|
||||
case 'Live Trading':
|
||||
label = 'STOP LIVE TRADING'
|
||||
break
|
||||
case 'Stopping':
|
||||
label = 'STOPPING...'
|
||||
break
|
||||
case 'Error':
|
||||
label = 'ERROR, RETRY LATER'
|
||||
break
|
||||
}
|
||||
|
||||
let labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 25,
|
||||
y: thisObject.container.frame.height - 9
|
||||
}
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
container: undefined,
|
||||
status: 'BOTTOM',
|
||||
assetBalances: undefined,
|
||||
restartSimulation: undefined,
|
||||
fullscreen: undefined,
|
||||
toTop: toTop,
|
||||
toBottom: toBottom,
|
||||
@@ -39,7 +38,6 @@
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
thisObject.assetBalances = undefined
|
||||
thisObject.restartSimulation = undefined
|
||||
thisObject.fullscreen = undefined
|
||||
}
|
||||
|
||||
@@ -67,10 +65,6 @@
|
||||
thisObject.assetBalances = newAssetBalances()
|
||||
thisObject.assetBalances.initialize()
|
||||
|
||||
thisObject.restartSimulation = newRestartSimulation()
|
||||
thisObject.restartSimulation.container.connectToParent(thisObject.container)
|
||||
thisObject.restartSimulation.initialize()
|
||||
|
||||
thisObject.fullscreen = newFullScreen()
|
||||
thisObject.fullscreen.container.connectToParent(thisObject.container)
|
||||
thisObject.fullscreen.initialize()
|
||||
@@ -99,9 +93,6 @@
|
||||
}
|
||||
|
||||
function childrenPhysics () {
|
||||
if (canvas.strategySpace.workspace.enabled === true) {
|
||||
thisObject.restartSimulation.physics()
|
||||
}
|
||||
thisObject.fullscreen.physics()
|
||||
}
|
||||
function thisObjectPhysics () {
|
||||
@@ -144,11 +135,6 @@
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
if (canvas.strategySpace.workspace.enabled === true) {
|
||||
container = thisObject.restartSimulation.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
}
|
||||
|
||||
container = thisObject.fullscreen.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
@@ -165,9 +151,6 @@
|
||||
drawBackground()
|
||||
|
||||
thisObject.assetBalances.draw()
|
||||
if (canvas.strategySpace.workspace.enabled === true) {
|
||||
thisObject.restartSimulation.draw()
|
||||
}
|
||||
thisObject.fullscreen.draw()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user