Merge pull request #838 from Smidy13/develop
Bug Fix: 'Closing' state of Close Stage, Trading Session getting stuck on Run Request Sent & Improvement: Telegram Bot Test Function
This commit is contained in:
9 files changed
+221
-3
No files matched your search
@@ -120,6 +120,11 @@
|
||||
"name": "Workspace Functions",
|
||||
"propertyName": "workspaceFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryWorkspaceFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Social Bots Functions",
|
||||
"propertyName": "socialBotsFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibrarySocialBotsFunctions"
|
||||
}
|
||||
],
|
||||
"utilities": [
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
fill: #181d04;
|
||||
filter: url(#filter);
|
||||
}
|
||||
|
||||
.cls-2, .cls-3 {
|
||||
fill: #d4ef5c;
|
||||
fill-rule: evenodd;
|
||||
}
|
||||
|
||||
.cls-2 {
|
||||
filter: url(#filter-2);
|
||||
}
|
||||
|
||||
.cls-3 {
|
||||
filter: url(#filter-3);
|
||||
}
|
||||
</style>
|
||||
<filter id="filter" x="133" y="134" width="246" height="246" filterUnits="userSpaceOnUse">
|
||||
<feFlood result="flood" flood-color="#e6eaea"/>
|
||||
<feComposite result="composite" operator="in" in2="SourceGraphic"/>
|
||||
<feBlend result="blend" in2="SourceGraphic"/>
|
||||
</filter>
|
||||
<filter id="filter-2" x="163.531" y="175.594" width="185.469" height="157.844" filterUnits="userSpaceOnUse">
|
||||
<feFlood result="flood" flood-color="#365558"/>
|
||||
<feComposite result="composite" operator="in" in2="SourceGraphic"/>
|
||||
<feBlend result="blend" in2="SourceGraphic"/>
|
||||
</filter>
|
||||
<filter id="filter-3" x="7" y="2" width="503" height="507" filterUnits="userSpaceOnUse">
|
||||
<feFlood result="flood" flood-color="#4acfd9"/>
|
||||
<feComposite result="composite" operator="in" in2="SourceGraphic"/>
|
||||
<feBlend result="blend" in2="SourceGraphic"/>
|
||||
</filter>
|
||||
</defs>
|
||||
<circle class="cls-1" cx="256" cy="257" r="123"/>
|
||||
<path class="cls-2" d="M348.994,226.194L273.46,301.727h0l-31.7,31.7-78.228-78.229,50.318-50.318,27.635,27.635L298.4,175.6Z"/>
|
||||
<path class="cls-3" d="M510,218.377v76.368H461.733a207.728,207.728,0,0,1-32.068,77.672l34.648,34.63-54.027,54-34.233-34.217a207.954,207.954,0,0,1-81.473,34.128V509h-76.4V460.959a207.953,207.953,0,0,1-80.808-33.667l-34.9,34.881-54.026-54,35.108-35.091a207.734,207.734,0,0,1-32.528-78.336H7V218.377H50.616a207.7,207.7,0,0,1,32.028-79.122l-35.319-35.3,54.026-54,34.691,34.674a207.982,207.982,0,0,1,82.133-34.585V2h76.4V50.041a208,208,0,0,1,82.8,35.047L411.4,51.079l54.026,54-34.872,34.855a207.662,207.662,0,0,1,31.581,78.442H510ZM415.555,255.5c0-84.94-71.266-153.8-159.177-153.8S97.2,170.56,97.2,255.5s71.267,153.8,159.178,153.8S415.555,340.44,415.555,255.5Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -14879,6 +14879,13 @@
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration"
|
||||
},
|
||||
{
|
||||
"action": "Send Telegram Test Message",
|
||||
"label": "Send Telegram Test Message",
|
||||
"iconPathOn": "test-entity",
|
||||
"iconPathOff": "test-entity",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
|
||||
@@ -800,6 +800,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
|
||||
|
||||
runWhenStatusIsOpening()
|
||||
await runWhenStatusIsOpen()
|
||||
await runWhenStatusIsClosing()
|
||||
|
||||
function runWhenStatusIsOpening() {
|
||||
|
||||
@@ -861,6 +862,58 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
async function runWhenStatusIsClosing() {
|
||||
/* Closing Status Procedure */
|
||||
if (tradingEngine.tradingCurrent.strategyCloseStage.status.value === 'Closing') {
|
||||
/*
|
||||
During the closing stage status, we do not place new orders, just check
|
||||
if the ones placed were filled, and cancel the ones not filled.
|
||||
*/
|
||||
let tradingSystemStage = tradingSystem.tradingStrategies[tradingEngine.tradingCurrent.strategy.index.value].closeStage
|
||||
let executionNode = tradingSystemStage.closeExecution
|
||||
|
||||
/*
|
||||
Check if there are unfilled orders, we will check if they were executed,
|
||||
and cancel the ones that were not.
|
||||
*/
|
||||
tradingSystem.evalConditions(tradingSystemStage, 'Close Execution')
|
||||
tradingSystem.evalFormulas(tradingSystemStage, 'Close Execution')
|
||||
|
||||
await tradingExecutionModuleObject.runExecution(
|
||||
executionNode,
|
||||
tradingEngine.tradingCurrent.strategyCloseStage
|
||||
)
|
||||
|
||||
/*
|
||||
The Closing is finished when the sizeFilled + feesPaid reaches the sizePlaced.
|
||||
This can happens either because we update the sizeFilled value when we see
|
||||
at the exchange that orders were filled, or we reduce the sizePlaced when
|
||||
we cancel not yet filled orders. Here it does not matter the targetSize since
|
||||
this status represent a force closure of this stage.
|
||||
*/
|
||||
switch (tradingEngine.tradingCurrent.strategyCloseStage.stageDefinedIn.value) {
|
||||
case 'Base Asset': {
|
||||
if (
|
||||
tradingEngine.tradingCurrent.strategyCloseStage.stageBaseAsset.sizeFilled.value >=
|
||||
tradingEngine.tradingCurrent.strategyCloseStage.stageBaseAsset.sizePlaced.value
|
||||
) {
|
||||
changeStageStatus('Close Stage', 'Closed')
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Quoted Asset': {
|
||||
if (
|
||||
tradingEngine.tradingCurrent.strategyCloseStage.stageQuotedAsset.sizeFilled.value >=
|
||||
tradingEngine.tradingCurrent.strategyCloseStage.stageQuotedAsset.sizePlaced.value
|
||||
) {
|
||||
changeStageStatus('Close Stage', 'Closed')
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeStageTargetSize() {
|
||||
/*
|
||||
Validations that all needed nodes are there.
|
||||
@@ -887,6 +940,7 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
|
||||
initialized to their defualts.
|
||||
*/
|
||||
if (tradingEngine.tradingCurrent.position.status.value !== 'Open' && tradingEngine.tradingCurrent.position.status.value !== 'Closing') { return }
|
||||
if (tradingEngine.tradingCurrent.position.status.value !== 'Close' && tradingEngine.tradingCurrent.position.status.value !== 'Closing') { return }
|
||||
if (
|
||||
(
|
||||
tradingEngine.tradingCurrent.strategyTriggerStage.status.value === 'Closed' ||
|
||||
|
||||
@@ -712,6 +712,11 @@ function newSuperalgosActionSwitch() {
|
||||
UI.projects.superalgos.spaces.floatingSpace.uiObjectConstructor.createUiObject(true, action.node.payload)
|
||||
}
|
||||
break
|
||||
case 'Send Telegram Test Message':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.socialBotsFunctions.sendTelegramTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
function newSuperalgosFunctionLibrarySocialBotsFunctions() {
|
||||
thisObject = {
|
||||
sendTelegramTestMessage: sendTelegramTestMessage
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function sendTelegramTestMessage(node, callBackFunction) {
|
||||
|
||||
let botToken = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'botToken')
|
||||
let chatId = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'chatId')
|
||||
|
||||
if (botToken === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('botToken parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
if (chatId === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('chatId parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let params = {
|
||||
text: "Test Message from Superalgos",
|
||||
chat_id: chatId
|
||||
}
|
||||
|
||||
httpRequestJSON(JSON.stringify(params),"https://api.telegram.org/bot" + botToken + "/sendMessage", onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setInfoMessage('Telegram message sent.')
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.setErrorMessage('Could not send Telegram message. Error Response: ' + err.message)
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function httpRequestJSON(pContentToSend, pPath, callBackFunction) {
|
||||
let xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText);
|
||||
return;
|
||||
} else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) {
|
||||
callBackFunction({
|
||||
result: "Fail",
|
||||
message: JSON.parse(xmlHttpRequest.responseText).description,
|
||||
code: JSON.parse(xmlHttpRequest.responseText).error_code
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (pContentToSend === undefined) {
|
||||
xmlHttpRequest.open("GET", pPath, true);
|
||||
xmlHttpRequest.send();
|
||||
} else {
|
||||
try {
|
||||
let blob = new Blob([pContentToSend], { type: 'application/json' });
|
||||
xmlHttpRequest.open("POST", pPath, true);
|
||||
xmlHttpRequest.send(blob);
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); }
|
||||
callBackFunction({ result: "Fail", message: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,36 @@ function newSuperalgosFunctionLibraryTradingSessionFunctions() {
|
||||
|
||||
let eventsServerClient = UI.projects.superalgos.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
/* Setup Listener to check Parent Task Status of the Session */
|
||||
let eventSubscriptionIdOnStatus
|
||||
let eventHandlerKey = "Task Client - " + node.payload.parentNode.payload.parentNode.payload.parentNode.id
|
||||
|
||||
eventsServerClient.listenToEvent(eventHandlerKey, 'Task Status', undefined, node.id, onResponse, onStatus)
|
||||
|
||||
function onResponse(message) {
|
||||
eventSubscriptionIdOnStatus = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(eventHandlerKey, eventSubscriptionIdOnStatus, node.id)
|
||||
|
||||
/* If Task is Not Running Display Error */
|
||||
if (message.event.status === 'Task Process Not Running') {
|
||||
node.payload.uiObject.setErrorMessage('Parent Task Not Running.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
}
|
||||
}
|
||||
|
||||
/* Raise Event to Check Task Status */
|
||||
let eventKey = {}
|
||||
eventKey.taskId = node.payload.parentNode.payload.parentNode.payload.parentNode.id
|
||||
|
||||
eventsServerClient.raiseEvent("Task Manager", 'Task Status', eventKey)
|
||||
|
||||
let lightingPath = '' +
|
||||
'Trading System->' +
|
||||
'Dynamic Indicators->Indicator Function->Formula->' +
|
||||
|
||||
@@ -112,12 +112,16 @@ function newWorkspace() {
|
||||
|
||||
function onIndexingFinished() {
|
||||
setupEventsServerClients()
|
||||
setTimeout(runTasksAndSessions, 10000)
|
||||
runTasksAndSessions()
|
||||
|
||||
thisObject.enabled = true
|
||||
UI.projects.superalgos.spaces.cockpitSpace.initializePosition()
|
||||
CAN_SPACES_DRAW = true
|
||||
|
||||
thisObject.isInitialized = true
|
||||
|
||||
playTutorials()
|
||||
|
||||
savingWorkspaceIntervalId = setInterval(saveWorkspace, 60000)
|
||||
UI.projects.superalgos.utilities.statusBar.changeStatus("Displaying the UI...")
|
||||
}
|
||||
@@ -132,6 +136,9 @@ function newWorkspace() {
|
||||
executeAction({ name: 'Syncronize Tasks', project: 'Superalgos' })
|
||||
executeAction({ name: 'Syncronize Trading Sessions', project: 'Superalgos' })
|
||||
executeAction({ name: 'Syncronize Learning Sessions', project: 'Superalgos' })
|
||||
}
|
||||
|
||||
function playTutorials() {
|
||||
executeAction({ name: 'Play Tutorials', project: 'Superalgos' })
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user