Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: PLUVTECH-DM to Masters-Trading-Mine Dependencies - Add: User Defined Variables - Add: User Defined Code #925

Merged
merged 3 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Projects/Superalgos/Plugins/Trading-Mines/Masters.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/close-stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"name": "announcements",
"type": "array",
"childType": "Announcement"
},
{
"name": "userDefinedCode",
"type": "node",
"childType": "User Defined Code",
"autoAdd": false
}
],
"propertyNameAtParent": "closeStage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"code": "// Type you code"
},
"attachingRules": {
"compatibleTypes": "->Condition->"
"compatibleTypes": "->Condition->User Defined Code->"
},
"menuItems": [
{
Expand Down
6 changes: 6 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/manage-stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"name": "announcements",
"type": "array",
"childType": "Announcement"
},
{
"name": "userDefinedCode",
"type": "node",
"childType": "User Defined Code",
"autoAdd": false
}
],
"propertyNameAtParent": "manageStage"
Expand Down
6 changes: 6 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/open-stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"name": "announcements",
"type": "array",
"childType": "Announcement"
},
{
"name": "userDefinedCode",
"type": "node",
"childType": "User Defined Code",
"autoAdd": false
}
],
"propertyNameAtParent": "openStage"
Expand Down
6 changes: 6 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/trading-episode.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
"type": "node",
"childType": "Cycle",
"autoAdd": true
},
{
"name": "userVariables",
"type": "node",
"childType": "User Variables",
"autoAdd": false
}
]
}
6 changes: 6 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/trigger-stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"name": "announcements",
"type": "array",
"childType": "Announcement"
},
{
"name": "userDefinedCode",
"type": "node",
"childType": "User Defined Code",
"autoAdd": false
}
],
"propertyNameAtParent": "triggerStage"
Expand Down
55 changes: 55 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/user-defined-code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "User Defined Code",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"propertyToCheckFor": "javascriptCode",
"label": "Add Code",
"relatedUiObject": "Javascript Code",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"actionFunction": "payload.executeAction",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity"
},
{
"action": "Copy Node Path",
"label": "Copy Node Path",
"iconPathOn": "copy-path",
"iconPathOff": "copy-path",
"actionFunction": "payload.executeAction"
}
],
"addLeftIcons": true,
"initialValues": {
"config": "{ \n \"runWhenEnteringStage\": false, \n \"runWhenExitingStage\": false, \n \"runWhileAtStage\": false, \n \"WhileAtStage_whenToRun\": \"first|last\" \n}"
},
"editors": {
"config": true
},
"level": 2,
"attachingRules": {
"compatibleTypes": "->Trigger Stage->Open Stage->Manage Stage->Close Stage->"
},
"childrenNodesProperties": [
{
"name": "javascriptCode",
"type": "array",
"childType": "Javascript Code",
"autoAdd": true
}
],
"propertyNameAtParent": "userDefinedCode"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"type": "User Defined Variable",
"menuItems": [
{
"action": "Configure",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration",
"dontShowAtFullscreen": true,
"actionFunction": "uiObject.configEditor.activate"
},
{
"action": "Copy Node Path",
"label": "Copy Node Path",
"iconPathOn": "copy-path",
"iconPathOff": "copy-path",
"actionFunction": "payload.executeAction"
},
{
"action": "Copy Node Value",
"label": "Copy Node Value",
"iconPathOn": "copy-value",
"iconPathOff": "copy-value",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"addLeftIcons": true,
"level": 3,
"attachingRules": {
"compatibleTypes": "->User Variables->"
},
"propertyNameAtParent": "userDefinedVariable",
"editors": {
"config": true
},
"initialValues": {
"config": "{\n\"initialValue\": 0\n}"
}
}
34 changes: 34 additions & 0 deletions Projects/Superalgos/Schemas/App-Schema/user-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"type": "User Variables",
"menuItems": [
{
"action": "Add UI Object",
"label": "Add Variable",
"relatedUiObject": "User Defined Variable",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"addLeftIcons": true,
"level": 3,
"attachingRules": {
"compatibleTypes": "->Trading Episode->"
},
"propertyNameAtParent": "userVariables",
"childrenNodesProperties": [
{
"name": "userDefinedVariable",
"type": "array",
"childType": "User Defined Variable",
"autoAdd": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {

function checkTriggerOff() {
if (tradingEngine.tradingCurrent.strategyTriggerStage.status.value === 'Open') {
checkUserDefinedCode('Trigger Stage', 'Running', 'first');

let strategy = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value]
let triggerStage = strategy.triggerStage
Expand Down Expand Up @@ -246,6 +247,8 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
changeStageStatus('Trigger Stage', 'Closed', 'Position Taken')
changeStageStatus('Open Stage', 'Opening')
changeStageStatus('Manage Stage', 'Opening')
} else {
checkUserDefinedCode('Trigger Stage', 'Running', 'last');
}
}
}
Expand Down Expand Up @@ -299,7 +302,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
tradingPositionModuleObject.initialTargets(tradingSystemStage, tradingEngineStage)
initializeStageTargetSize()

/* From here on, the stage is officialy Open */
/* From here on, the stage is officially Open */
changeStageStatus('Open Stage', 'Open')
}
}
Expand All @@ -311,6 +314,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
While the Open Stage is Open, we do our regular stuff: place orders and check
what happened to the orders already placed.
*/
checkUserDefinedCode('Open Stage', 'Running', 'first');
let tradingSystemStage = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].openStage
let tradingEngineStage = tradingEngine.tradingCurrent.strategyOpenStage
let executionNode = tradingSystemStage.openExecution
Expand All @@ -324,6 +328,11 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
tradingEngineStage
)
checkIfStageNeedsToBeClosed(tradingEngineStage, tradingSystemStage, 'Open Stage')

/* User Defined Code if runWhileAtStage==true */
if (tradingEngine.tradingCurrent.strategyOpenStage.status.value === 'Open') {
checkUserDefinedCode('Open Stage', 'Running', 'last');
}
}
}

Expand Down Expand Up @@ -410,7 +419,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
if (tradingEngine.tradingCurrent.strategyManageStage.status.value === 'Opening') {
let strategy = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value]
let manageStage = strategy.manageStage

/*
The system allows the user not to define a Manage Stage, because the Manage Stage is optional.
Here we are going to see if that is the case and if it is, we will inmidiatelly consider
Expand All @@ -431,6 +440,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
function runWhenStatusIsOpen() {
/* Open Status Procedure */
if (tradingEngine.tradingCurrent.strategyManageStage.status.value === 'Open') {
checkUserDefinedCode('Manage Stage', 'Running', 'first');
let strategy = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value]
let manageStage = strategy.manageStage

Expand All @@ -450,6 +460,11 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {

/* Checking if Stop or Take Profit were hit */
checkStopLossOrTakeProfitWasHit()

/* If User Defined Code exists check for runWhileAtStage */
if (tradingEngine.tradingCurrent.strategyManageStage.status.value === 'Open') {
checkUserDefinedCode('Manage Stage', 'Running', 'last');
}
}

function calculateStopLoss() {
Expand Down Expand Up @@ -846,6 +861,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
/*
This will happen as long as the Close Stage is Open.
*/
checkUserDefinedCode('Close Stage', 'Running', 'first');
let tradingSystemStage = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].closeStage
let tradingEngineStage = tradingEngine.tradingCurrent.strategyCloseStage
let executionNode = tradingSystemStage.closeExecution
Expand All @@ -859,6 +875,10 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
)

checkIfStageNeedsToBeClosed(tradingEngineStage, tradingSystemStage, 'Close Stage')
/* If User Defined Code exists check for runWhileAtStage */
if (tradingEngine.tradingCurrent.strategyCloseStage.status.value === 'Open') {
checkUserDefinedCode('Close Stage', 'Running', 'last');
}
}
}

Expand Down Expand Up @@ -1122,9 +1142,11 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
}
if (stage.status.value === 'Open') {
openStage(stage)
checkUserDefinedCode(stageName, 'Open')
}
if (stage.status.value === 'Closed') {
closeStage(stage)
checkUserDefinedCode(stageName, 'Closed')
}

/*
Expand Down Expand Up @@ -1228,4 +1250,57 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
}
throw 'Error Already Recorded'
}
}

/* checkUserDefinedCode(): Checks if User Defined Code exists and processes if applicable. */
function checkUserDefinedCode(stage, status, when) {
let tradingSystemStage = getTradingSystemStage(stage);

if (tradingSystemStage.userDefinedCode !== undefined) {
if (status === 'Running' && when !== tradingSystemStage.userDefinedCode.config.WhileAtStage_whenToRun) { return; }

switch(status) {
case 'Open' : {
if (tradingSystemStage.userDefinedCode.config.runWhenEnteringStage) {
tradingSystem.evalUserCode(tradingSystemStage, 'User Defined Code');
}
break;
}
case 'Running' : {
if (tradingSystemStage.userDefinedCode.config.runWhileAtStage &&
tradingSystemStage.userDefinedCode.config.WhileAtStage_whenToRun === when) {
tradingSystem.evalUserCode(tradingSystemStage, 'User Defined Code');
}
break;
}
case 'Closed' : {
if (tradingSystemStage.userDefinedCode.config.runWhenExitingStage) {
tradingSystem.evalUserCode(tradingSystemStage, 'User Defined Code');
}
break;
}
}
}
}

/* getTradingSystemStage(): takes stage name returns stage object. */
function getTradingSystemStage(stage) {
switch(stage) {
case 'Trigger Stage' : {
return tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].triggerStage;
break;
}
case 'Open Stage' : {
return tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].openStage;
break;
}
case 'Manage Stage' : {
return tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].manageStage;
break
}
case 'Close Stage' : {
return tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].closeStage;
break;
}
}
}
}
Loading