Merge pull request #1001 from Luis-Fernando-Molina/develop

Contribution: API Data Fetcher feature parameters with default values at the API Map
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-05-27 20:31:35 -04:00
commit 3a603a067d
3 files changed
+137 -33

No files matched your search

@@ -16,8 +16,8 @@
},
{
"style": "List",
"text": "value: It is the value to be used at this parameter. The API Map can define the value, that would be considered a default value. The same parameter defined at the Data Mine will have the actual value to be used replacing the default.",
"updated": 1621022463369
"text": "value: It is the value to be used at this parameter. The API Map can define the value, that would be considered a default value. The same parameter defined at the Data Mine will have the actual value to be used replacing the default. If you are defining a API Map to be shared as a Plugin, you can avoid setting this property at the API Map level, and let the users set it at their Data Mine when they use your API Map. For completness, this parameter should be included at the the API Map even if the value property is not there.",
"updated": 1622160191941
}
]
}
@@ -0,0 +1,52 @@
{
"topic": "Troubleshooting",
"pageNumber": "18",
"type": "Problems With Computer Time",
"definition": {
"text": "Some exchanges force the computer that is running your bot to be highly syncronized with thier servers, and to achieve that you need that machine's time to keep itself syncronized with an Internet Time Server.",
"updated": 1622140103759
},
"paragraphs": [
{
"style": "Title",
"text": "How to identify this problem?",
"updated": 1622140152661
},
{
"style": "Text",
"text": "If you receive an error like this, you are having this type of problem:"
},
{
"style": "Javascript",
"text": "['2021-05-27T15:24:15.339Z',246,'Exchange API','[ERROR] createOrder -> \nError = binance {\"code\":-1021,\n\"msg\":\"Timestamp for this request is outside of the recvWindow.\"}'] \n@ Masters-Low-Frequency-Trading",
"updated": 1622140198558
},
{
"style": "Title",
"text": "How to solve this problem?",
"updated": 1622140378812
},
{
"style": "Text",
"text": "You can use the server time.nist.gov that has proven to work in this situation. Look for the place at your OS where you can change the Internet Time Settings and use that server there."
},
{
"style": "Subtitle",
"text": "Docker Users"
},
{
"style": "Text",
"text": "Sometimes Docker might not be in sync even though the underlaying OS it is. To fix this, you can run this command, which will force Docker to restart and wsl to pickup the correct time from the OS.",
"updated": 1622140496709
},
{
"style": "Javascript",
"text": "wsl --shutdown",
"updated": 1622140514881
},
{
"style": "Text",
"text": ""
}
]
}
@@ -305,23 +305,49 @@ exports.newSuperalgosBotModulesFetchingProcess = function (processIndex) {
/*
Parameters to the query of the API are all optional. Here we will see if
we need to place the API call with Parameters...
*/
let separator = ""
if (productDefinition.apiQueryParameters !== undefined) {
queryString = '?'
for (j = 0; j < productDefinition.apiQueryParameters.apiQueryParameters.length; j++) {
let apiQueryParameter = productDefinition.apiQueryParameters.apiQueryParameters[j]
/*
There is a special parameter which has a flag to indicate is a Page Number.
This will be treated differently since we will need to iterate to get each possible page.
The page number will no be added here to the query string.
*/
if (apiQueryParameter.config.isPageNumber === true) {
pageNumberParameter = apiQueryParameter
} else {
queryString = queryString + separator + apiQueryParameter.config.codeName + '=' + apiQueryParameter.config.value
separator = "&"
The Parameters defined at the API Map will be the default values that
can be overwritten by the ones at the Data Mine.
We will create parametersMap to handle this.
*/
let parametersMap = new Map()
if (endpointNode.apiQueryParameters !== undefined) {
for (let i = 0; i < endpointNode.apiQueryParameters.apiQueryParameters.length; i++) {
let apiQueryParameter = endpointNode.apiQueryParameters.apiQueryParameters[i]
addParameterToMap(apiQueryParameter)
}
}
/*
The parameters defined at the Data Mine will overwrite whatever is at the API Map
*/
if (productDefinition.apiQueryParameters !== undefined) {
for (let j = 0; j < productDefinition.apiQueryParameters.apiQueryParameters.length; j++) {
let apiQueryParameter = productDefinition.apiQueryParameters.apiQueryParameters[j]
addParameterToMap(apiQueryParameter)
}
}
let separator = ""
queryString = '?'
parametersMap.forEach(addParameterToQueryString)
function addParameterToQueryString(value, key, map) {
queryString = queryString + separator + key + '=' + value
separator = "&"
}
function addParameterToMap(apiQueryParameter) {
/*
There is a special parameter which has a flag to indicate is a Page Number.
This will be treated differently since we will need to iterate to get each possible page.
The page number will no be added here to the query string.
*/
if (apiQueryParameter.config.isPageNumber === true) {
pageNumberParameter = apiQueryParameter
} else {
if (apiQueryParameter.config.codeName !== undefined && apiQueryParameter.config.value !== undefined) {
parametersMap.set(apiQueryParameter.config.codeName, apiQueryParameter.config.value)
}
}
}
@@ -331,29 +357,55 @@ exports.newSuperalgosBotModulesFetchingProcess = function (processIndex) {
/*
Parameters to the path of the API are all optional. Here we will see if
we need to place the API call with Parameters...
The Parameters defined at the API Map will be the default values that
can be overwritten by the ones at the Data Mine.
We will create parametersMap to handle this.
*/
let parametersMap = new Map()
if (endpointNode.apiPathParameters !== undefined) {
for (let i = 0; i < endpointNode.apiPathParameters.apiPathParameters.length; i++) {
let apiPathParameter = endpointNode.apiPathParameters.apiPathParameters[i]
addParameterToMap(apiPathParameter)
}
}
/*
The parameters defined at the Data Mine will overwrite whatever is at the API Map
*/
let separator = ""
if (productDefinition.apiPathParameters !== undefined) {
pathString = '/'
for (let j = 0; j < productDefinition.apiPathParameters.apiPathParameters.length; j++) {
let apiPathParameter = productDefinition.apiPathParameters.apiPathParameters[j]
addParameterToMap(apiPathParameter)
}
}
let parameterValue = apiPathParameter.config.codeName // This is the default value
if (apiPathParameter.config.replaceBy !== undefined) {
switch (apiPathParameter.config.replaceBy) {
case '@BaseAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
break
}
case '@QuotedAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
break
}
function addParameterToMap(apiPathParameter) {
if (apiPathParameter.config.codeName !== undefined) {
parametersMap.set(apiPathParameter.config.codeName, apiPathParameter)
}
}
let separator = ""
pathString = '/'
parametersMap.forEach(addParameterToPath)
function addParameterToPath(value, key, map) {
let apiPathParameter = value
let parameterValue = key // This is the default value
if (apiPathParameter.config.replaceBy !== undefined) {
switch (apiPathParameter.config.replaceBy) {
case '@BaseAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
break
}
case '@QuotedAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
break
}
}
pathString = pathString + separator + parameterValue
separator = "/"
}
pathString = pathString + separator + parameterValue
separator = "/"
}
}