Fix dynamic currencies in the initialization

This commit is contained in:
Joe Tretter
2021-01-09 21:43:29 -06:00
parent 468124421d
commit 8c464795b0

View File

@@ -3525,8 +3525,8 @@
"t": "set", "t": "set",
"p": "coinBalance", "p": "coinBalance",
"pt": "flow", "pt": "flow",
"to": "$number(payload.balance)", "to": "payload.balance",
"tot": "jsonata" "tot": "msg"
} }
], ],
"action": "", "action": "",
@@ -3566,11 +3566,11 @@
"type": "switch", "type": "switch",
"z": "791ce869.901798", "z": "791ce869.901798",
"name": "", "name": "",
"property": "payload.XXMR", "property": "payload.balance",
"propertyType": "msg", "propertyType": "msg",
"rules": [ "rules": [
{ {
"t": "nempty" "t": "nnull"
}, },
{ {
"t": "else" "t": "else"
@@ -3586,7 +3586,8 @@
"ff1341d.17ca8c" "ff1341d.17ca8c"
], ],
[ [
"5da3780b.7006f8" "5da3780b.7006f8",
"55955668.3c3f18"
] ]
] ]
}, },
@@ -3969,7 +3970,7 @@
"type": "function", "type": "function",
"z": "791ce869.901798", "z": "791ce869.901798",
"name": "Determine Action", "name": "Determine Action",
"func": "//$number(payload.XMRUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet multiplier = flow.get('multiplier');\nlet pair=flow.get(\"pair\");\nlet askPrice=Number(msg.payload[pair].a[0]);\nlet bidPrice=Number(msg.payload[pair].b[0]);\nflow.set(\"askPrice\",Number(askPrice));\nflow.set(\"bidPrice\",Number(bidPrice));\n\nlet lastExecPrice=flow.get('lastExecPrice',\"file\");\n\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',Number(lastExecPrice),\"file\");\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n // when selling I am going with the floor, that is a bit more conservative; \n // buying fast selling slow\n let jumpSize = Math.floor(Math.abs(lastExecPrice-bidPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n let jumpSize = Math.round(Math.abs(lastExecPrice-askPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;", "func": "//$number(payload.XMRUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet multiplier = flow.get('multiplier');\nlet pair=flow.get(\"pair\");\nlet askPrice=Number(msg.payload[pair].a[0]);\nlet bidPrice=Number(msg.payload[pair].b[0]);\nflow.set(\"askPrice\",Number(askPrice));\nflow.set(\"bidPrice\",Number(bidPrice));\n\nlet lastExecPrice=flow.get('lastExecPrice',\"file\");\n\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',Number(lastExecPrice),\"file\");\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nflow.set(\"orderVolume\",0);\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n // when selling I am going with the floor, that is a bit more conservative; \n // buying fast selling slow\n let jumpSize = Math.floor(Math.abs(lastExecPrice-bidPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n let jumpSize = Math.floor(Math.abs(lastExecPrice-askPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"x": 910, "x": 910,
@@ -4539,7 +4540,7 @@
"type": "function", "type": "function",
"z": "791ce869.901798", "z": "791ce869.901798",
"name": "dynamic Currency To fix Key", "name": "dynamic Currency To fix Key",
"func": "let currency=flow.get('currency');\n\nif (msg.payload[currency]!==undefined) {\n msg.payload.balance=msg.payload[currency];\n}\n\nreturn msg;", "func": "let currency=flow.get('currency');\n\nif (msg.payload[currency]!==undefined) {\n msg.payload.balance=Number(msg.payload[currency]);\n}\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"x": 820, "x": 820,
@@ -5915,8 +5916,8 @@
"t": "set", "t": "set",
"p": "coinBalance", "p": "coinBalance",
"pt": "flow", "pt": "flow",
"to": "$number(payload.balance)", "to": "payload.balance",
"tot": "jsonata" "tot": "msg"
} }
], ],
"action": "", "action": "",
@@ -5924,7 +5925,7 @@
"from": "", "from": "",
"to": "", "to": "",
"reg": false, "reg": false,
"x": 1420, "x": 1440,
"y": 80, "y": 80,
"wires": [ "wires": [
[ [
@@ -5956,11 +5957,11 @@
"type": "switch", "type": "switch",
"z": "9d5ee7b4.680b68", "z": "9d5ee7b4.680b68",
"name": "", "name": "",
"property": "payload.XXMR", "property": "payload.balance",
"propertyType": "msg", "propertyType": "msg",
"rules": [ "rules": [
{ {
"t": "nempty" "t": "nnull"
}, },
{ {
"t": "else" "t": "else"
@@ -5969,14 +5970,15 @@
"checkall": "true", "checkall": "true",
"repair": false, "repair": false,
"outputs": 2, "outputs": 2,
"x": 1010, "x": 1050,
"y": 80, "y": 80,
"wires": [ "wires": [
[ [
"8ee0d04e.612b5" "8ee0d04e.612b5"
], ],
[ [
"11b75c20.bed614" "11b75c20.bed614",
"5797473.ba4dbb8"
] ]
] ]
}, },
@@ -5999,7 +6001,7 @@
"from": "", "from": "",
"to": "", "to": "",
"reg": false, "reg": false,
"x": 1190, "x": 1230,
"y": 120, "y": 120,
"wires": [ "wires": [
[ [
@@ -6018,7 +6020,7 @@
"tostatus": false, "tostatus": false,
"complete": "payload", "complete": "payload",
"targetType": "msg", "targetType": "msg",
"x": 1610, "x": 1650,
"y": 80, "y": 80,
"wires": [] "wires": []
}, },
@@ -6359,7 +6361,7 @@
"type": "function", "type": "function",
"z": "9d5ee7b4.680b68", "z": "9d5ee7b4.680b68",
"name": "Determine Action", "name": "Determine Action",
"func": "//$number(payload.XMRUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet multiplier = flow.get('multiplier');\nlet pair=flow.get(\"pair\");\nlet askPrice=Number(msg.payload[pair].a[0]);\nlet bidPrice=Number(msg.payload[pair].b[0]);\nflow.set(\"askPrice\",Number(askPrice));\nflow.set(\"bidPrice\",Number(bidPrice));\n\nlet lastExecPrice=flow.get('lastExecPrice',\"file\");\n\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',Number(lastExecPrice),\"file\");\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n // when selling I am going with the floor, that is a bit more conservative; \n // buying fast selling slow\n let jumpSize = Math.floor(Math.abs(lastExecPrice-bidPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n let jumpSize = Math.round(Math.abs(lastExecPrice-askPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;", "func": "//$number(payload.XMRUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet multiplier = flow.get('multiplier');\nlet pair=flow.get(\"pair\");\nlet askPrice=Number(msg.payload[pair].a[0]);\nlet bidPrice=Number(msg.payload[pair].b[0]);\nflow.set(\"askPrice\",Number(askPrice));\nflow.set(\"bidPrice\",Number(bidPrice));\n\nlet lastExecPrice=flow.get('lastExecPrice',\"file\");\n\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',Number(lastExecPrice),\"file\");\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nflow.set(\"orderVolume\",0);\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n // when selling I am going with the floor, that is a bit more conservative; \n // buying fast selling slow\n let jumpSize = Math.floor(Math.abs(lastExecPrice-bidPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n let jumpSize = Math.floor(Math.abs(lastExecPrice-askPrice)/delta);\n flow.set(\"orderVolume\",jumpSize * multiplier);\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"x": 910, "x": 910,
@@ -6929,7 +6931,7 @@
"type": "function", "type": "function",
"z": "9d5ee7b4.680b68", "z": "9d5ee7b4.680b68",
"name": "dynamic Currency To fix Key", "name": "dynamic Currency To fix Key",
"func": "let currency=flow.get('currency');\n\nif (msg.payload[currency]!==undefined) {\n msg.payload.balance=msg.payload[currency];\n}\n\nreturn msg;", "func": "let currency=flow.get('currency');\n\nif (msg.payload[currency]!==undefined) {\n msg.payload.balance=Number(msg.payload[currency]);\n}\n\nreturn msg;",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"x": 820, "x": 820,
@@ -6954,5 +6956,33 @@
"x": 1060, "x": 1060,
"y": 40, "y": 40,
"wires": [] "wires": []
},
{
"id": "5797473.ba4dbb8",
"type": "debug",
"z": "9d5ee7b4.680b68",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1400,
"y": 180,
"wires": []
},
{
"id": "55955668.3c3f18",
"type": "debug",
"z": "791ce869.901798",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1380,
"y": 160,
"wires": []
} }
] ]