Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Superalgos/Superalgos in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
Smidy13 committed Jun 17, 2022
2 parents d7b4319 + f6d9070 commit afc09a6
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 32 deletions.
109 changes: 106 additions & 3 deletions Bitcoin-Factory/Test-Server/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,110 @@

## To run a Test Case Server you need to setup two workspaces

Random Notes:
Server Mining workspace.

1. You can not turn off the minimun 3 labels: Candle Close, Max, Min and 1 Feature: Candle Open. At the Test Server config all this must be ON.
2. Remember that the Test Cases Array JSON file is generated once the first time the Test Server run and does not detect that this file exists. If you change the config adding or removing ON / OFF switches for indicators, you need to manually delete this file and the FForecast Cases Array file so that the Test Server generates it again. Failing to do so will produce errors executing the tests at the Docker container, since dimensions for reshapes will not match, since they were calculated at the moment this file was generated but the changed config produces datasets with other amount of data.
Test Case Server.


For best results and to help keep things organised it is recommended to create a mining workspace.

## Create the Server Mining Workspace

1. Load up the getting started tutorials workspace
2. Rename the workspace to something related to the server eg: yourusername-mining-servername
3. Delete the 3 tutorials
4. Locate the Plugins/Data-Mining node and "Add specified plugin data mine"
5. Add the specified data mine you plan to enable within the test server sensor bot, along with candles and masters.
6. Save and reload the workspace.
7. Locate the Crypto Ecosystem node and expand then find Exchange Markets, Hover over BTC/USDT and select "Install Market".
8. Locate the data tasks node inside my computer node, then continue and expand BTC/USDT/Candles/Candles/Exchange Raw Data/Exchange Raw Data Sensor Bot and configure as follows:

```
{
"startDate": "2017-06-01"
}
```
9. Delete every "resistances and supports Multi-Time-Frame-Daily" node leaving only "resistances and supports Multi-Time-Frame-Market" nodes on each data mine task node. This will help reduce unnecessary processing.
10. Run all project data tasks from the Data Tasks node.
11. Save the workspace you are finished with the Mining workspace.


## Server Workspace

**The server workspace can be accessed by requesting a default template from the machine learning telegram group.**

1. Edit Test-Server Sensor Bot Instance with the following and replace YOUR-SERVER-NAME with the name of your server:

```
{
"networkCodeName": "Testnet",
"targetSuperalgosHost": "localhost",
"targetSuperalgosHttpPort": 34248,
"pythonScriptName": "Bitcoin_Factory_LSTM.py",
"serverInstanceName": "YOUR-SERVER-NAME",
"timeSeriesFile": {
"labels": [
```

2. If you are running multiple instances of Superalgos and require data transfer from instance then input the IP address of the Superalgos instance in the "targetSuperalgosHost": "IP-ADDRESS-HERE",
3. Edit each indicator you wish to activate like below.
Indicator with range "ON" must be mining and up-to-date (from mining workspace preferably)
```
{
"dataMine": "Delta",
"indicator": "MFI",
"product": "MFI",
"objectName": "mfi",
"propertyName": "value",
"range": [
"ON"
]
},
```
4. Create Task-Server-App from within your User Profile/User Apps. (If haven't done already)
5. Use the Profile Constructor to Install Signing Accounts. (If haven't done already)
6. If you have signed your account don't forget you need to save your profile and merge it with the plugins/governance/user-profiles develop branch on github.com
7. Reference Task Server App Reference to the task server app in your profile.
8. Start the Test-Server Task and check the console you should see something like this:
```
Superalgos TaskServer is Running!
Websockets Client will try to Connect to Network Node via Web Sockets ........ Trying to Connect to devosonder -> P2P Network Node #1 -> 99.81.83.180:18042
Websockets Client Connected to Network Node via Web Sockets .................. Connected to devosonder -> P2P Network Node #1 -> 99.81.83.180:18042
2022-06-15T10:23:12.605Z Working with these Parameter Ranges:
┌────────────────────────────────────┬─────────────┐
│ (index) │ 0 │
├────────────────────────────────────┼─────────────┤
│ LIST_OF_ASSETS │ [ 'BTC' ] │
│ LIST_OF_TIMEFRAMES │ [ '01-hs' ] │
│ NUMBER_OF_LAG_TIMESTEPS │ 10 │
│ PERCENTAGE_OF_DATASET_FOR_TRAINING │ 80 │
│ NUMBER_OF_EPOCHS │ 750 │
│ NUMBER_OF_LSTM_NEURONS │ 50 │
└────────────────────────────────────┴─────────────┘
2022-06-15T10:23:12.638Z Binance BTC/USDT Bitcoin-Factory Test-Server Test-Server Main Loop # 1
2022-06-15T10:23:13.339Z Starting Network "Testnet" with these Test Clients:
┌─────────┬────────────────────────┬────────────────────────────┬───────────────────────────────────────────────────────────────────────┬──────────────┬────────────────────────────────────────┬──────────────┬─────────────────────────┐
│ (index) │ type │ name │ config │ project │ id │ savedPayload │ userProfile │
├─────────┼────────────────────────┼────────────────────────────┼───────────────────────────────────────────────────────────────────────┼──────────────┼────────────────────────────────────────┼──────────────┼─────────────────────────┤
│ 0 │ 'Test Client Instance' │ 'New Test Client Instance' │ '{\n "codeName": "WorkFromHome"\n}' │ 'Governance' │ '43bc2026-c743-4896-a706-c54e187162a4' │ undefined │ 'BastianMuc' │
│ 1 │ 'Test Client Instance' │ 'rx300-1' │ '{\r\n "codeName": "rx300-1"\r\n}' │ 'Governance' │ 'f182a3c3-ebc0-4200-b2e3-2da85e77b104' │ undefined │ 'BlaaSwe' │
│ 2 │ 'Test Client Instance' │ 'rx300-2' │ '{\r\n "codeName": "rx300-2"\r\n}' │ 'Governance' │ 'd0a97fe3-7b0b-4466-8783-9d91557c4412' │ undefined │ 'BlaaSwe' │
│ 3 │ 'Test Client Instance' │ 'rx300-3' │ '{\r\n "codeName": "rx300-3"\r\n}' │ 'Governance' │ '17d39be6-1c6a-445f-88b9-1dab4b1eb84b' │ undefined │ 'BlaaSwe' │
Congratulations the test server is now running !
```


## Governance

Machine learning test cases are deployed to users and all test data is stored within your Bitcoin-Factory/Test-Server/YOUR-SERVER-NAME
It is important to note that you are required to keep this data and provide it in a report to allow the system to accurately account for all test cases solved by each user. Test reports are to be combined into a single report then merged into the Bitcoin-Factory/Reports folder with the naming style as follows:

Testnet-2022-05-27.csv


### Random Notes:

1. You can not turn off the minimun 3 labels: Candle Close, Max, Min and 1 Feature: Candle Open. At the Test Server config all this must be ON.
2. Remember that the Test Cases Array JSON file is generated once the first time the Test Server run and does not detect that this file exists. If you change the config adding or removing ON / OFF switches for indicators, you need to manually delete this file and the Forecast Cases Array file so that the Test Server generates it again. Failing to do so will produce errors executing the tests at the Docker container, since dimensions for reshapes will not match, since they were calculated at the moment this file was generated but the changed config produces datasets with other amount of data.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
}

const REPORT_NAME = networkCodeName + '-' + (new Date()).toISOString().substring(0, 16).replace("T", "-").replace(":", "-").replace(":", "-") + '-00'
const MUST_BE_ON_PARAMS = [
'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_MAX', 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_MIN',
'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_CLOSE', 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_OPEN'
]

let parametersRanges = TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.parametersRanges
let timeSeriesFileFeatures = TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.timeSeriesFile.features
Expand Down Expand Up @@ -43,6 +47,42 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
saveTestCasesFile()
}

/*
Creates a list of those whose value is "ON" except MUST_BE_ON_PARAMS.
*/
function getParametersIsON() {
let parametersIsON = []

for (const key of Object.keys(parametersRanges)) {
if (!MUST_BE_ON_PARAMS.includes(key) && parametersRanges[key][0] === "ON") {
parametersIsON.push(key)
}
}
return parametersIsON
}

/*
Creates all combinations with parameters whose value is "ON".
*/
function getAllCombinations() {
const parametersIsON = getParametersIsON()
const AMOUNT_OF_VARIABLES = parametersIsON.length

let combinations = []
for (let i = 0; i < (1 << AMOUNT_OF_VARIABLES); i++) {
let combination = []
//Increasing or decreasing depending on which direction
for (let j = AMOUNT_OF_VARIABLES - 1; j >= 0; j--) {
let key = parametersIsON[j]
let parameter = { key: key, value: Boolean(i & (1 << j))?"ON":"OFF" }
combination.push(parameter)
}
combinations.push(combination);

}
return combinations
}

function generateTestCases() {
let preParameters = {}

Expand All @@ -69,32 +109,47 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
/*
Generate Cases based on Param Ranges
*/
addParamRangesRecursively(0)

function addParamRangesRecursively(index) {
// List of all case combinations
let allCombinations = getAllCombinations()

// Parameters are being set.
setPreparameters(0)

// The values of the parameters are set according to their combinations.
for (let i = 0; i < allCombinations.length; i++) {
const combination = allCombinations[i];
for (const combinationElement of combination) {
preParameters[combinationElement.key] = combinationElement.value
}
addToCaseList()
}

function setPreparameters(index) {
let propertyName = Object.keys(parametersRanges)[index]
if (propertyName !== undefined) {
for (let i = 0; i < parametersRanges[propertyName].length; i++) {
preParameters[propertyName] = parametersRanges[propertyName][i]
addParamRangesRecursively(index + 1)
}
} else {
let parameters = getTestParameters(preParameters)
let parametersHash = TS.projects.foundations.globals.taskConstants.TEST_SERVER.utilities.hash(JSON.stringify(parameters))
let testCase = {
id: thisObject.testCasesArray.length + 1,
mainAsset: preParameters.LIST_OF_ASSETS[0],
mainTimeFrame: preParameters.LIST_OF_TIMEFRAMES[0],
parameters: parameters,
parametersHash: parametersHash,
status: 'Never Tested'
setPreparameters(index + 1)
}
}
}
function addToCaseList() {
let parameters = getTestParameters(preParameters)
let parametersHash = TS.projects.foundations.globals.taskConstants.TEST_SERVER.utilities.hash(JSON.stringify(parameters))
let testCase = {
id: thisObject.testCasesArray.length + 1,
mainAsset: preParameters.LIST_OF_ASSETS[0],
mainTimeFrame: preParameters.LIST_OF_TIMEFRAMES[0],
parameters: parameters,
parametersHash: parametersHash,
status: 'Never Tested'
}

let existingTestCase = thisObject.testCasesMap.get(parametersHash)
if (existingTestCase === undefined) {
thisObject.testCasesArray.push(testCase)
thisObject.testCasesMap.set(parametersHash, testCase)
}
let existingTestCase = thisObject.testCasesMap.get(parametersHash)
if (existingTestCase === undefined) {
thisObject.testCasesArray.push(testCase)
thisObject.testCasesMap.set(parametersHash, testCase)
}
}

Expand Down Expand Up @@ -164,20 +219,20 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
// definition of how the raw dataset is going to be divided between a Traing Dataset and a Test Dataset.
parameters.PERCENTAGE_OF_DATASET_FOR_TRAINING = preParameters.PERCENTAGE_OF_DATASET_FOR_TRAINING

// TODO: this calculation is incomplete. If you had multiple time frames it might not work at some point.
// TODO: this calculation is incomplete. If you had multiple time frames it might not work at some point.
parameters.NUMBER_OF_FEATURES = 0
for (let i = 0; i < parameters.LIST_OF_TIMEFRAMES.length; i++) {
parameters.NUMBER_OF_FEATURES = parameters.NUMBER_OF_FEATURES + (i + 1) * parameters.NUMBER_OF_INDICATORS_PROPERTIES * parameters.NUMBER_OF_ASSETS
}
// NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 12*5
// NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 8*5 + 12*5 + 24*5
// NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 12*5
// NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 8*5 + 12*5 + 24*5

// hyper-parameters
parameters.NUMBER_OF_EPOCHS = preParameters.NUMBER_OF_EPOCHS
parameters.NUMBER_OF_LSTM_NEURONS = preParameters.NUMBER_OF_LSTM_NEURONS

/*
Add Labels
Add Labels
*/
for (let q = 0; q < timeSeriesFileLabels.length; q++) {
let label = timeSeriesFileLabels[q].parameter
Expand All @@ -187,7 +242,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
parameters[label] = preParameters[label]
}
/*
Add Features
Add Features
*/
for (let q = 0; q < timeSeriesFileFeatures.length; q++) {
let feature = timeSeriesFileFeatures[q].parameter
Expand All @@ -208,7 +263,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network

async function getNextTestCase(currentClientInstance) {
/*
The first thing we will try to do is to see if this Test Client Instance was not already assigned a Test case for which it never
The first thing we will try to do is to see if this Test Client Instance was not already assigned a Test case for which it never
reported back. This is a common situation when some kind of error occured and the whole cycle was not closed.
*/
for (let i = 0; i < thisObject.testCasesArray.length; i++) {
Expand All @@ -233,7 +288,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
}
}
/*
The second thing we will try to do is to see if there are assigned test cases that have not been tested in more than 24 hours.
The second thing we will try to do is to see if there are assigned test cases that have not been tested in more than 24 hours.
If we find one of those, we will re assign them.
*/
for (let i = 0; i < thisObject.testCasesArray.length; i++) {
Expand Down Expand Up @@ -445,4 +500,4 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network
let fileContent = JSON.stringify(thisObject.testCasesArray, undefined, 4)
SA.nodeModules.fs.writeFileSync(global.env.PATH_TO_BITCOIN_FACTORY + "/Test-Server/" + TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.serverInstanceName + "/StateData/TestCases/Test-Cases-Array-" + networkCodeName + ".json", fileContent)
}
}
}
Loading

0 comments on commit afc09a6

Please sign in to comment.