ABSOLUTE_DUST implementation to better control when stage should close.
This commit is contained in:
1 parent
5966d92669
commit
91d7af66e3
6 files changed
+112
-42
No files matched your search
@@ -1 +1 @@
|
||||
{"type":"Trading System","name":"Lightning Strike","config":"{ \n\"codeName\": \"Lightning Strike\"\n}","project":"Superalgos","tradingStrategies":[{"type":"Trading Strategy","name":"My Trading Strategy","project":"Superalgos","triggerStage":{"type":"Trigger Stage","project":"Superalgos","triggerOn":{"type":"Trigger On Event","project":"Superalgos","situations":[{"type":"Situation","name":"Inmediate Trigger On","project":"Superalgos","conditions":[{"type":"Condition","name":"New Condition","project":"Superalgos","javascriptCode":{"type":"Javascript Code","name":"New Javascript Code","code":"true","project":"Superalgos","id":"e2ea7ded-2be1-43a3-a7fa-de3d9b8eeec4","savedPayload":{"position":{"x":29614.345537114667,"y":29686.264363248512},"targetPosition":{"x":30059.096259318965,"y":29912.85964671243},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"e693623c-e11f-49e3-99da-1897c7a47563","savedPayload":{"position":{"x":30059.096259318965,"y":29912.85964671243},"targetPosition":{"x":30503.948096117412,"y":30139.527093006473},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"9135663f-deeb-4b3f-8855-91750810a406","savedPayload":{"position":{"x":30503.948096117412,"y":30139.527093006473},"targetPosition":{"x":30949.606420886405,"y":30366.48888962723},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"announcements":[],"id":"05f2f6b7-15ab-4386-a299-91a949de634e","savedPayload":{"position":{"x":30949.606420886405,"y":30366.48888962723},"targetPosition":{"x":31395.222935590078,"y":30593.406010951592},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"triggerOff":{"type":"Trigger Off Event","project":"Superalgos","situations":[{"type":"Situation","name":"Never Trigger Off","project":"Superalgos","conditions":[{"type":"Condition","name":"Close Above MA","project":"Superalgos","javascriptCode":{"type":"Javascript Code","code":"false","project":"Superalgos","id":"0eb59e3b-ccc8-4eab-a1f2-a7c8dea28949","savedPayload":{"position":{"x":30777.836612408217,"y":28692.647426362768},"targetPosition":{"x":30932.059454816794,"y":29167.31041310742},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"31ab47dd-fe2d-47ac-9a77-08ec8beee068","savedPayload":{"position":{"x":30932.059454816794,"y":29167.31041310742},"targetPosition":{"x":31086.31006690743,"y":29642.1636542021},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"fa93a965-e836-42b3-9784-79acda1468dd","savedPayload":{"position":{"x":31086.31006690743,"y":29642.1636542021},"targetPosition":{"x":31240.740280232243,"y":30117.847206458973},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"announcements":[],"id":"8a46ebed-4ed4-4b70-882b-416ffa1b37f6","savedPayload":{"position":{"x":31240.740280232243,"y":30117.847206458973},"targetPosition":{"x":31395.222935590078,"y":30593.406010951592},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"takePosition":{"type":"Take Position Event","project":"Superalgos","situations":[{"type":"Situation","name":"Inmediate Take Position","project":"Superalgos","conditions":[{"type":"Condition","name":"New Condition","project":"Superalgos","javascriptCode":{"type":"Javascript Code","name":"New Javascript Code","code":"true","project":"Superalgos","id":"90dda64b-17fd-469c-8066-3855596795ab","savedPayload":{"position":{"x":32310.303575265214,"y":28785.226973794255},"targetPosition":{"x":32083.882547130008,"y":29230.01160391372},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"4054a522-7863-4ac2-9eab-26db2a6f037f","savedPayload":{"position":{"x":32083.882547130008,"y":29230.01160391372},"targetPosition":{"x":31848.83631252263,"y":29702.20922965271},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"0b8d71ab-6430-4e3f-840a-162745ab8d22","savedPayload":{"position":{"x":31848.83631252263,"y":29702.20922965271},"targetPosition":{"x":31622.00489673196,"y":30147.8015863614},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollaLine truncated
|
||||
{"type":"Trading System","name":"Lightning Strike","config":"{ \n\"codeName\": \"Lightning Strike\"\n}","project":"Superalgos","tradingStrategies":[{"type":"Trading Strategy","name":"My Trading Strategy","project":"Superalgos","triggerStage":{"type":"Trigger Stage","project":"Superalgos","triggerOn":{"type":"Trigger On Event","project":"Superalgos","situations":[{"type":"Situation","name":"Inmediate Trigger On","project":"Superalgos","conditions":[{"type":"Condition","name":"New Condition","project":"Superalgos","javascriptCode":{"type":"Javascript Code","name":"New Javascript Code","code":"true","project":"Superalgos","id":"e2ea7ded-2be1-43a3-a7fa-de3d9b8eeec4","savedPayload":{"position":{"x":29614.345537114667,"y":29686.264363248512},"targetPosition":{"x":30059.096259318965,"y":29912.85964671243},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"e693623c-e11f-49e3-99da-1897c7a47563","savedPayload":{"position":{"x":30059.096259318965,"y":29912.85964671243},"targetPosition":{"x":30503.948096117412,"y":30139.527093006473},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"9135663f-deeb-4b3f-8855-91750810a406","savedPayload":{"position":{"x":30503.948096117412,"y":30139.527093006473},"targetPosition":{"x":30949.606420886405,"y":30366.48888962723},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"announcements":[],"id":"05f2f6b7-15ab-4386-a299-91a949de634e","savedPayload":{"position":{"x":30949.606420886405,"y":30366.48888962723},"targetPosition":{"x":31395.222935590078,"y":30593.406010951592},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"triggerOff":{"type":"Trigger Off Event","project":"Superalgos","situations":[{"type":"Situation","name":"Never Trigger Off","project":"Superalgos","conditions":[{"type":"Condition","name":"Close Above MA","project":"Superalgos","javascriptCode":{"type":"Javascript Code","code":"false","project":"Superalgos","id":"0eb59e3b-ccc8-4eab-a1f2-a7c8dea28949","savedPayload":{"position":{"x":30777.836612408217,"y":28692.647426362768},"targetPosition":{"x":30932.059454816794,"y":29167.31041310742},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"31ab47dd-fe2d-47ac-9a77-08ec8beee068","savedPayload":{"position":{"x":30932.059454816794,"y":29167.31041310742},"targetPosition":{"x":31086.31006690743,"y":29642.1636542021},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"fa93a965-e836-42b3-9784-79acda1468dd","savedPayload":{"position":{"x":31086.31006690743,"y":29642.1636542021},"targetPosition":{"x":31240.740280232243,"y":30117.847206458973},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"announcements":[],"id":"8a46ebed-4ed4-4b70-882b-416ffa1b37f6","savedPayload":{"position":{"x":31240.740280232243,"y":30117.847206458973},"targetPosition":{"x":31395.222935590078,"y":30593.406010951592},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"takePosition":{"type":"Take Position Event","project":"Superalgos","situations":[{"type":"Situation","name":"Inmediate Take Position","project":"Superalgos","conditions":[{"type":"Condition","name":"New Condition","project":"Superalgos","javascriptCode":{"type":"Javascript Code","name":"New Javascript Code","code":"true","project":"Superalgos","id":"90dda64b-17fd-469c-8066-3855596795ab","savedPayload":{"position":{"x":32310.303575265214,"y":28785.226973794255},"targetPosition":{"x":32083.882547130008,"y":29230.01160391372},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"4054a522-7863-4ac2-9eab-26db2a6f037f","savedPayload":{"position":{"x":32083.882547130008,"y":29230.01160391372},"targetPosition":{"x":31848.83631252263,"y":29702.20922965271},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"0b8d71ab-6430-4e3f-840a-162745ab8d22","savedPayload":{"position":{"x":31848.83631252263,"y":29702.20922965271},"targetPosition":{"x":31622.00489673196,"y":30147.8015863614},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollaLine truncated
|
||||
@@ -13105,7 +13105,7 @@
|
||||
}
|
||||
],
|
||||
"initialValues": {
|
||||
"config": "{\n\"roundingErrorCorrectionFactor\": 1.01 \n}"
|
||||
"config": "{\n\"roundingErrorCorrectionFactor\": 1.01, \n\"absoluteDustInBaseAsset\": 0,\n\"absoluteDustInQuotedAsset\": 0 \n}"
|
||||
},
|
||||
"editors": {
|
||||
"config": true
|
||||
@@ -14380,7 +14380,7 @@
|
||||
}
|
||||
],
|
||||
"initialValues": {
|
||||
"config": "{\n\"roundingErrorCorrectionFactor\": 1.01 \n}"
|
||||
"config": "{\n\"roundingErrorCorrectionFactor\": 1.01, \n\"absoluteDustInBaseAsset\": 0,\n\"absoluteDustInQuotedAsset\": 0 \n}"
|
||||
},
|
||||
"editors": {
|
||||
"config": true
|
||||
|
||||
@@ -21,20 +21,9 @@
|
||||
"text": "For example, in the open stage, you probably defined the target size as a function of the capital allocated to the trading system. In the close stage, you will likely want to define the target size as a function of the size filled, that is, the amount of the orders placed that was filled during the open stage."
|
||||
},
|
||||
{
|
||||
"style": "Subtitle",
|
||||
"text": "The Stage Does Not Close"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "One common issue users have while dealing with stages is that they do not get closed after their orders get filled. This usually happens because there are several adjustments on rate that happens during trading, specially if trading live. The reason a Stage does not get closed automatically is because the total filled for the whole stage is not close enough to the Stage Target Size defined by users. In order to avoid this situation there is a configurable factor that can be applied to the stage filled at runtime in order to force it to reach the Stage Target Size. The default value for this factor is:"
|
||||
},
|
||||
{
|
||||
"style": "Json",
|
||||
"text": " const ROUNDING_ERROR_CORRECTION_FACTOR = 1.001"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "This value is overwritted by whatever users config at the Stage node under the roundingErrorCorrectionFactor property."
|
||||
"style": "Include",
|
||||
"text": "Superalgos->Topic->Why My Stage is not Closing?->The Stage Does Not Close",
|
||||
"updated": 1615054694042
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -37,23 +37,9 @@
|
||||
"text": "the take profit or stop loss targets are hit."
|
||||
},
|
||||
{
|
||||
"style": "Subtitle",
|
||||
"text": "The Stage Does Not Close"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "One common issue users have while dealing with stages is that they do not get closed after their orders get filled. This usually happens because there are several adjustments on rate that happens during trading, specially if trading live. The reason a Stage does not get closed automatically is because the total filled for the whole stage is not close enough to the Stage Target Size defined by users. In order to avoid this situation there is a configurable factor that can be applied to the stage filled at runtime in order to force it to reach the Stage Target Size. The default value for this factor is:",
|
||||
"updated": 1615031649791
|
||||
},
|
||||
{
|
||||
"style": "Json",
|
||||
"text": "const ROUNDING_ERROR_CORRECTION_FACTOR = 1.001",
|
||||
"updated": 1615031657820
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "This value is overwritted by whatever users config at the Stage node under the roundingErrorCorrectionFactor property.",
|
||||
"updated": 1615031668876
|
||||
"style": "Include",
|
||||
"text": "Superalgos->Topic->Why My Stage is not Closing?->The Stage Does Not Close",
|
||||
"updated": 1615054619090
|
||||
}
|
||||
]
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"topic": "Frequently Asked Questions",
|
||||
"pageNumber": 1,
|
||||
"type": "Why My Stage is not Closing?",
|
||||
"definition": {
|
||||
"text": "One of the most common questions asked by users is why the open or close stage are not closing after the order was filled?",
|
||||
"updated": 1615053580910
|
||||
},
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Note",
|
||||
"text": "The shot answer is becasue the Stage Filled Size did not reach the value of the Stage Target Size. ",
|
||||
"updated": 1615053684185
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "There are many reason why this can happen, but they all have to do with syncronization between the system and the exchange, and dust getting accumulated in decimal places.",
|
||||
"updated": 1615053796132
|
||||
},
|
||||
{
|
||||
"style": "Block",
|
||||
"text": "The Stage Does Not Close",
|
||||
"updated": 1615054499809
|
||||
},
|
||||
{
|
||||
"style": "Subtitle",
|
||||
"text": "The Stage Does Not Close"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "One common issue users have while dealing with stages is that they do not get closed after their orders get filled. This usually happens because there are several adjustments on rate that happens during trading, specially during live trading. The reason a Stage does not get closed automatically is because the total filled for the whole stage is not close enough to the Stage Target Size defined by users. In order to avoid this situation there are three configurations at the Stage node you can use:",
|
||||
"updated": 1615053929853
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "ROUNDING_ERROR_CORRECTION_FACTOR : is a configurable factor that can be applied to the stage filled at runtime in order to force it to reach the Stage Target Size. The default value for this factor is:"
|
||||
},
|
||||
{
|
||||
"style": "Javascript",
|
||||
"text": "ROUNDING_ERROR_CORRECTION_FACTOR = 1.001",
|
||||
"updated": 1615053956943
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "This value is overwritten by whatever users config at the Stage node under the roundingErrorCorrectionFactor property."
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "A value of 1.01 would mean that when the Filled amount is at 1% distance from the Stage Target, the stage will be closed."
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "ABSOLUTE_DUST_IN_BASE_ASSET: is a numeric value that represents the distance that you allow to be between the Size Filled and the Target Side for a stage, measured in Base Asset. It's default value is Zero and you can define it at the config of a Stage node using the absoluteDustInBaseAsset property.",
|
||||
"updated": 1615054114048
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "ABSOLUTE_DUST_IN_QUOTED_ASSET: is a numeric value that represents the distance that you allow to be between the Size Filled and the Target Side for a stage, measured in Base Asset. It's default value is Zero and you can define it at the config of a Stage node using the absoluteDustInQuotedAsset property.",
|
||||
"updated": 1615054151393
|
||||
},
|
||||
{
|
||||
"style": "Note",
|
||||
"text": "The parameter that will actually be used from the two previous ones will depend on how you dedined your Target Size, either in Base Asset or Quoted Asset.",
|
||||
"updated": 1615054261790
|
||||
},
|
||||
{
|
||||
"style": "Subtitle",
|
||||
"text": "Implementation",
|
||||
"updated": 1615054281409
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Here you can see how these parameters are implemented in the Low Frequency Trading Bot code:"
|
||||
},
|
||||
{
|
||||
"style": "Javascript",
|
||||
"text": "switch (tradingEngineStage.stageDefinedIn.value) {\n case 'Base Asset': {\n if (\n tradingEngineStage.stageBaseAsset.sizeFilled.value\n * \n ROUNDING_ERROR_CORRECTION_FACTOR\n +\n ABSOLUTE_DUST_IN_BASE_ASSET\n >=\n tradingEngineStage.stageBaseAsset.targetSize.value\n ) {\n positionFilled()\n } else {\n checkCloseStageEvent(tradingSystemStage)\n }\n break\n }\n case 'Quoted Asset': {\n if (\n tradingEngineStage.stageQuotedAsset.sizeFilled.value\n * \n ROUNDING_ERROR_CORRECTION_FACTOR\n +\n ABSOLUTE_DUST_IN_QUOTED_ASSET\n >=\n tradingEngineStage.stageQuotedAsset.targetSize.value\n ) {\n positionFilled()\n } else {\n checkCloseStageEvent(tradingSystemStage)\n }\n break\n }\n }",
|
||||
"updated": 1615054391439
|
||||
}
|
||||
]
|
||||
}
|
||||
+22
-8
@@ -962,14 +962,27 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
|
||||
if (tradingSystemStage.config.roundingErrorCorrectionFactor !== undefined) {
|
||||
ROUNDING_ERROR_CORRECTION_FACTOR = tradingSystemStage.config.roundingErrorCorrectionFactor
|
||||
}
|
||||
/*
|
||||
We will also implement a mechanism to allow users declare an absolute value to add
|
||||
to the Size Filled before checking it againt the Stage Target Size.
|
||||
*/
|
||||
let ABSOLUTE_DUST_IN_BASE_ASSET = 0
|
||||
if (tradingSystemStage.config.absoluteDustInBaseAsset !== undefined) {
|
||||
ABSOLUTE_DUST_IN_BASE_ASSET = tradingSystemStage.config.absoluteDustInBaseAsset
|
||||
}
|
||||
let ABSOLUTE_DUST_IN_QUOTED_ASSET = 0
|
||||
if (tradingSystemStage.config.absoluteDustInQuotedAsset !== undefined) {
|
||||
ABSOLUTE_DUST_IN_QUOTED_ASSET = tradingSystemStage.config.absoluteDustInQuotedAsset
|
||||
}
|
||||
|
||||
switch (tradingEngineStage.stageDefinedIn.value) {
|
||||
case 'Base Asset': {
|
||||
if (
|
||||
(
|
||||
tradingEngineStage.stageBaseAsset.sizeFilled.value
|
||||
)
|
||||
* ROUNDING_ERROR_CORRECTION_FACTOR
|
||||
tradingEngineStage.stageBaseAsset.sizeFilled.value
|
||||
*
|
||||
ROUNDING_ERROR_CORRECTION_FACTOR
|
||||
+
|
||||
ABSOLUTE_DUST_IN_BASE_ASSET
|
||||
>=
|
||||
tradingEngineStage.stageBaseAsset.targetSize.value
|
||||
) {
|
||||
@@ -981,10 +994,11 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) {
|
||||
}
|
||||
case 'Quoted Asset': {
|
||||
if (
|
||||
(
|
||||
tradingEngineStage.stageQuotedAsset.sizeFilled.value
|
||||
)
|
||||
* ROUNDING_ERROR_CORRECTION_FACTOR
|
||||
tradingEngineStage.stageQuotedAsset.sizeFilled.value
|
||||
*
|
||||
ROUNDING_ERROR_CORRECTION_FACTOR
|
||||
+
|
||||
ABSOLUTE_DUST_IN_QUOTED_ASSET
|
||||
>=
|
||||
tradingEngineStage.stageQuotedAsset.targetSize.value
|
||||
) {
|
||||
|
||||
Reference in new issue
Block a user