Mariam Tested and Running
This commit is contained in:
1 parent
a42174b233
commit
c9e3528cec
8 files changed
+117
-129
No files matched your search
Binary file not shown.
+68
-65
@@ -256,7 +256,7 @@
|
||||
let sumAssetA = 0;
|
||||
let sumAssetB = 0;
|
||||
|
||||
for (k = 0; k < pTrades.length; k++) {
|
||||
for (let k = 0; k < pTrades.length; k++) {
|
||||
|
||||
sumAssetA = sumAssetA + pTrades[k].amountA;
|
||||
sumAssetB = sumAssetB + pTrades[k].amountB;
|
||||
@@ -312,6 +312,73 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function confirmOrderWasExecuted(pTrades) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Entering function."); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> pTrades = " + JSON.stringify(pTrades)); }
|
||||
|
||||
/*
|
||||
|
||||
To confirm everything is ok, we will add all the amounts on trades asociated to the order and
|
||||
they must be equal to the one on file. Otherwise something very strange could have happened,
|
||||
in which case we will halt the bot execution.
|
||||
|
||||
*/
|
||||
|
||||
let sumAssetA = 0;
|
||||
let sumAssetB = 0;
|
||||
|
||||
for (let k = 0; k < pTrades.length; k++) {
|
||||
|
||||
sumAssetA = sumAssetA + pTrades[k].amountA;
|
||||
sumAssetB = sumAssetB + pTrades[k].amountB;
|
||||
|
||||
}
|
||||
|
||||
/* We add the fees */
|
||||
|
||||
sumAssetA = sumAssetA + exchangePositions[j].fee;
|
||||
|
||||
if (
|
||||
position.amountA !== sumAssetA ||
|
||||
position.amountB !== sumAssetB
|
||||
) {
|
||||
logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Cannot be confirmed that the order was executed. It must be manually cancelled by the user or cancelled by the exchange itself.");
|
||||
logger.write("[HINT] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Verify also that you were not running under a Exchange Simulation and you turned it off without deleting the Status Report file.");
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Confirmed that order was executed. Next thing to do is to remember the trades and change its status.
|
||||
|
||||
*/
|
||||
|
||||
position.status = "executed";
|
||||
|
||||
applyTradesToContext(pTrades);
|
||||
|
||||
let newTransaction = {
|
||||
type: position.type + " executed",
|
||||
position: position
|
||||
};
|
||||
|
||||
context.executionContext.transactions.push(newTransaction);
|
||||
|
||||
/* All done. */
|
||||
|
||||
next();
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Position not found: we need to know if the order was executed. */
|
||||
@@ -366,71 +433,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function confirmOrderWasExecuted(pTrades) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Entering function."); }
|
||||
if (FULL_LOG === true) { logger.write("[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> pTrades = " + JSON.stringify(pTrades)); }
|
||||
|
||||
/*
|
||||
|
||||
To confirm everything is ok, we will add all the amounts on trades asociated to the order and
|
||||
they must be equal to the one on file. Otherwise something very strange could have happened,
|
||||
in which case we will halt the bot execution.
|
||||
|
||||
*/
|
||||
|
||||
let sumAssetA = 0;
|
||||
let sumAssetB = 0;
|
||||
|
||||
for (k = 0; k < pTrades.length; k++) {
|
||||
|
||||
sumAssetA = sumAssetA + pTrades[k].amountA;
|
||||
sumAssetB = sumAssetB + pTrades[k].amountB;
|
||||
|
||||
}
|
||||
|
||||
/* We add the fees */
|
||||
|
||||
sumAssetA = sumAssetA + exchangePositions[j].fee;
|
||||
|
||||
if (
|
||||
position.amountA !== sumAssetA ||
|
||||
position.amountB !== sumAssetB
|
||||
) {
|
||||
logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Cannot be confirmed that the order was executed. It must be manually cancelled by the user or cancelled by the exchange itself.");
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Confirmed that order was executed. Next thing to do is to remember the trades and change its status.
|
||||
|
||||
*/
|
||||
|
||||
position.status = "executed";
|
||||
|
||||
applyTradesToContext(pTrades);
|
||||
|
||||
let newTransaction = {
|
||||
type: position.type + " executed",
|
||||
position: position
|
||||
};
|
||||
|
||||
context.executionContext.transactions.push(newTransaction);
|
||||
|
||||
/* All done. */
|
||||
|
||||
next();
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] ordersExecutionCheck -> loopBody -> err = " + err.message);
|
||||
|
||||
+11
-36
@@ -76,14 +76,17 @@
|
||||
|
||||
let cloudStorage = FILE_STORAGE.newFileStorage(bot);
|
||||
|
||||
let dependencies;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function initialize(pDependencies, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
|
||||
dependencies = pDependencies;
|
||||
/*
|
||||
|
||||
Here we get the positions the bot did and that are recorded at the bot storage account. We will use them through out the rest
|
||||
@@ -148,46 +151,18 @@
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> getStatusReport -> Entering function."); }
|
||||
|
||||
statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES);
|
||||
statusReportModule.initialize(bot, onInitilized);
|
||||
let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion;
|
||||
|
||||
function onInitilized(err) {
|
||||
statusReportModule = dependencies.statusReports.get(key);
|
||||
thisObject.statusReport = statusReportModule.file;
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
logger.write("[ERROR] initialize -> getStatusReport -> onInitilized -> err = " + err.message);
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
if (thisObject.statusReport.lastExecution !== undefined) {
|
||||
|
||||
statusReportModule.load(onLoad);
|
||||
}
|
||||
getExecutionHistory(callBack); // Happens when the Status Report exists.
|
||||
|
||||
function onLoad(err) {
|
||||
} else {
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
logger.write("[INFO] initialize -> getStatusReport -> onLoad -> Execution finished well. :-)");
|
||||
thisObject.statusReport = statusReportModule.file;
|
||||
getExecutionHistory(callBack);
|
||||
return;
|
||||
}
|
||||
case global.CUSTOM_OK_RESPONSE.result: { // We need to see if we can handle this.
|
||||
logger.write("[ERROR] initialize -> getStatusReport -> onLoad -> err.message = " + err.message);
|
||||
|
||||
if (err.message === "Status Report was never created.") {
|
||||
createConext(callBack);
|
||||
} else {
|
||||
callBackFunction(err); // we cant handle this here.
|
||||
}
|
||||
return;
|
||||
}
|
||||
default:
|
||||
{
|
||||
logger.write("[ERROR] initialize -> getStatusReport -> onLoad -> Operation Failed.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
createConext(callBack); // Happens when the Status Report does NOT exists.
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@
|
||||
|
||||
function write(Message) {
|
||||
|
||||
if (firstCall === true) { createFolders();}
|
||||
if (firstCall === true) { createFolders(); }
|
||||
|
||||
if (global.loopCointer !== loopCounter) {
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>Project</Name>
|
||||
<ScriptArguments>Poloniex-Live-Trades</ScriptArguments>
|
||||
<ScriptArguments>Trading-Process</ScriptArguments>
|
||||
<NodeExePath>C:\Program Files\nodejs\node.exe</NodeExePath>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
|
||||
+34
-23
@@ -70,6 +70,7 @@
|
||||
const DATASOURCE = require(ROOT_DIR + 'Datasource');
|
||||
const ASSISTANT = require(ROOT_DIR + 'Assistant');
|
||||
const STATUS_REPORT = require(ROOT_DIR + 'Status Report');
|
||||
const DEPENDENCIES = require(ROOT_DIR + 'Dependencies');
|
||||
|
||||
/* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */
|
||||
|
||||
@@ -86,14 +87,45 @@
|
||||
|
||||
let nextWaitTime;
|
||||
|
||||
initializeContext();
|
||||
initializeDependencies();
|
||||
|
||||
function initializeDependencies() {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); }
|
||||
|
||||
dependencies = DEPENDENCIES.newDependencies(bot, DEBUG_MODULE, STATUS_REPORT, FILE_STORAGE, UTILITIES);
|
||||
|
||||
dependencies.initialize(processConfig.dependencies, undefined, undefined, onInizialized);
|
||||
|
||||
function onInizialized(err) {
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)");
|
||||
initializeContext();
|
||||
return;
|
||||
}
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeDependencies -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeDependencies -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeContext() {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); }
|
||||
|
||||
context = CONTEXT.newContext(bot, DEBUG_MODULE, FILE_STORAGE, UTILITIES, STATUS_REPORT);
|
||||
context.initialize(onInizialized);
|
||||
context.initialize(dependencies, onInizialized);
|
||||
|
||||
function onInizialized(err) {
|
||||
|
||||
@@ -103,20 +135,17 @@
|
||||
initializeDatasource();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,20 +165,17 @@
|
||||
initializeExchangeAPI();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeDatasource -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeDatasource -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,20 +195,17 @@
|
||||
initializeAssistant();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,20 +225,17 @@
|
||||
initializeUserBot();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,20 +261,17 @@
|
||||
startUserBot();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,20 +290,17 @@
|
||||
saveContext();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry.");
|
||||
nextWaitTime = 'Retry';
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,19 +320,16 @@
|
||||
loopControl(nextWaitTime);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Can not retry at this point.");
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Operation Failed. Aborting the process.");
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
"patch": 0
|
||||
},
|
||||
"bot": {
|
||||
"path": "../Bots/AAMasters/AACharly-Extraction-Bot"
|
||||
"path": "../Bots/AAMasters/AAMariam-Trading-Bot"
|
||||
},
|
||||
"stopGracefully": "false",
|
||||
"exchangeSimulationMode": "false",
|
||||
"storageConnStringFolder": "Mixed",
|
||||
"storageConnStringFolder": "Production",
|
||||
"maxLogLoops": 10
|
||||
}
|
||||
Reference in new issue
Block a user