Coninbase Pro handling of cancelled orders

This commit is contained in:
Luis Fernando Molina committed 2021-04-08 23:32:35 +02:00
1 parent 6c75258291
commit bfc83b2e32
2 files changed
+107 -2

No files matched your search

@@ -0,0 +1,49 @@
{
"topic": "TS LF Trading Bot Warnings",
"pageNumber": "15",
"type": "TS LF Trading Bot Warning - Order Not Found at the Exchange",
"definition": {
"text": "The exchange returned null while checking an order. This usually happens at exchanges like Coinbase Pro that after an order cancellation the exchange deletes the order instead of changing it's status to cancelled.",
"updated": 1611922128136
},
"paragraphs": [
{
"style": "Success",
"text": "This is not an error and may be normal behavior. The trading bot created this warning to let you know that this happened so that you may keep track of all the details of the trade should you need to. This page provides information that should help you understand the context of the warning.",
"updated": 1611922148396
},
{
"style": "Warning",
"text": "Order Status Not Sync With Exchange"
},
{
"style": "Title",
"text": "Context Info"
},
{
"style": "Text",
"text": "Find below the values of variables relevant to the warning at the time the warning was created. They may prove of use to understand what happened."
},
{
"style": "Placeholder",
"text": "contextInfo"
},
{
"style": "Title",
"text": "Learn More"
},
{
"style": "Text",
"text": "To learn more about this topic, please read the following page:"
},
{
"style": "List",
"text": "Checking Exchange Events",
"updated": 1611921970650
},
{
"style": "List",
"text": "Syncing With the Exchange"
}
]
}
@@ -641,10 +641,13 @@ exports.newSuperalgosBotModulesTradingOrders = function (processIndex) {
let order = await exchangeAPIModuleObject.getOrder(tradingSystemOrder, tradingEngineOrder)
let message
let docs
if (order === undefined) {
const message = 'Order Status Not Sync With Exchange'
let docs = {
message = 'Order Status Not Sync With Exchange'
docs = {
project: 'Superalgos',
category: 'Topic',
type: 'TS LF Trading Bot Warning - ' + message,
@@ -661,6 +664,59 @@ exports.newSuperalgosBotModulesTradingOrders = function (processIndex) {
return false
}
if (order === null) {
/*
Some exchanges, like Coinbase Pro, deletes orders after being cancelled, and when we request information
about them, it returns null. We will interprate this as ORDER NOT FOUND.
*/
message = 'Order Not Found at the Exchange'
docs = {
project: 'Superalgos',
category: 'Topic',
type: 'TS LF Trading Bot Warning - ' + message,
placeholder: {}
}
tradingSystem.addWarning(
[
[tradingSystemOrder.id, tradingEngineOrder.id],
message,
docs
]
)
/* Close this Order */
tradingEngineOrder.status.value = 'Closed'
/*
We must be carefull here not to overide an already defined exitType. It can happen
for instance that the order was cancellerd from the but veryfing the cancellation
was not possible because of a connection to the exchange problem. In that case
the exit type was defined but the order was kept open until the verification could be done.
*/
if (tradingEngineOrder.exitType.value === tradingEngineOrder.exitType.config.initialValue) {
tradingEngineOrder.exitType.value = 'Not Found at the Exchange'
}
/* Initialize this */
tradingEngine.tradingCurrent.tradingEpisode.distanceToTradingEvent.closeOrder.value = 1
await updateEndsWithCycle(tradingEngineOrder)
let message = "Order Closed"
let docs = {
project: 'Superalgos',
category: 'Topic',
type: 'TS LF Trading Bot Info - ' + message,
placeholder: {}
}
contextInfo = {
exitType: tradingEngineOrder.exitType.value
}
TS.projects.superalgos.utilities.docsFunctions.buildPlaceholder(docs, undefined, undefined, undefined, undefined, undefined, contextInfo)
tradingSystem.addInfo([tradingSystemOrder.id, message, docs])
return
}
const AT_EXCHANGE_STATUS = {
OPEN: 'open',
CLOSED: 'closed',