Srtoring the lastExecPrice -- this also needs to be in the config file to define the name of the target (in this case "file")
This commit is contained in:
@@ -1338,7 +1338,7 @@
|
||||
"t": "set",
|
||||
"p": "maxBuyPrice",
|
||||
"pt": "flow",
|
||||
"to": "5",
|
||||
"to": "6",
|
||||
"tot": "num"
|
||||
}
|
||||
],
|
||||
@@ -1780,7 +1780,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "Determine Action",
|
||||
"func": "//$number(payload.XETCZUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet askPrice=msg.payload.XETCZUSD.a[0];\nlet bidPrice=msg.payload.XETCZUSD.b[0];\nlet lastExecPrice=flow.get('lastExecPrice');\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',lastExecPrice);\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;",
|
||||
"func": "//$number(payload.XETCZUSD.a[0]) - $number($flowContext('lastExecPrice'))\n\nconst delta=flow.get('delta'); // how much price move to take action?\nlet askPrice=msg.payload.XETCZUSD.a[0];\nlet bidPrice=msg.payload.XETCZUSD.b[0];\nlet lastExecPrice=flow.get('lastExecPrice',\"file\");\nif (lastExecPrice === undefined) { \n lastExecPrice=askPrice; \n flow.set('lastExecPrice',lastExecPrice,\"file\");\n}\n\nmsg.lastExecPrice=lastExecPrice;\n\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=bidPrice;\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=askPrice;\n} else {\n msg.action=\"nothing\";\n}\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 910,
|
||||
@@ -1796,7 +1796,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "BuyAction",
|
||||
"func": "let coinBalance = flow.get('coinBalance');\nlet delta = flow.get('delta');\nlet multiplier = Number(flow.get('multiplier'));\nlet buyPrice = Number(msg.payload.XETCZUSD.a[0]);\n\ncoinBalance += multiplier;\n\nflow.set('coinBalance',coinBalance);\nflow.set('lastExecPrice',buyPrice);\n\nmsg.payload={\n\tpair : 'XETCZUSD',\n\ttype : 'buy',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
|
||||
"func": "let coinBalance = flow.get('coinBalance');\nlet delta = flow.get('delta');\nlet multiplier = Number(flow.get('multiplier'));\nlet buyPrice = Number(msg.payload.XETCZUSD.a[0]);\n\ncoinBalance += multiplier;\n\nflow.set('coinBalance',coinBalance);\nflow.set('lastExecPrice',buyPrice,\"file\");\n\nmsg.payload={\n\tpair : 'XETCZUSD',\n\ttype : 'buy',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1940,
|
||||
@@ -1813,7 +1813,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "NoSellAction",
|
||||
"func": "let sellPrice = Number(msg.payload.XETCZUSD.b[0]);\n\nflow.set('lastExecPrice',sellPrice);\n\nreturn msg;",
|
||||
"func": "let sellPrice = Number(msg.payload.XETCZUSD.b[0]);\n\nflow.set('lastExecPrice',sellPrice,\"file\");\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1770,
|
||||
@@ -1829,7 +1829,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "NoBuyAction",
|
||||
"func": "let buyPrice = Number(msg.payload.XETCZUSD.a[0]);\n\nflow.set('lastExecPrice',buyPrice);\n\nreturn msg;",
|
||||
"func": "let buyPrice = Number(msg.payload.XETCZUSD.a[0]);\n\nflow.set('lastExecPrice',buyPrice,\"file\");\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1890,
|
||||
@@ -1845,7 +1845,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "SellAction",
|
||||
"func": "let coinBalance = flow.get('coinBalance');\nlet delta = flow.get('delta');\nlet multiplier = Number(flow.get('multiplier'));\n\nlet sellPrice = Number(msg.payload.XETCZUSD.b[0]);\n\ncoinBalance -= multiplier;\n\nflow.set('coinBalance',coinBalance);\nflow.set('lastExecPrice',sellPrice);\n\nmsg.payload={\n\tpair : 'XETCZUSD',\n\ttype : 'sell',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
|
||||
"func": "let coinBalance = flow.get('coinBalance');\nlet delta = flow.get('delta');\nlet multiplier = Number(flow.get('multiplier'));\n\nlet sellPrice = Number(msg.payload.XETCZUSD.b[0]);\n\ncoinBalance -= multiplier;\n\nflow.set('coinBalance',coinBalance);\nflow.set('lastExecPrice',sellPrice,\"file\");\n\nmsg.payload={\n\tpair : 'XETCZUSD',\n\ttype : 'sell',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1760,
|
||||
@@ -2035,7 +2035,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "FlowContext2msg",
|
||||
"func": "msg.flowContext = {};\nflow.keys().forEach(ele=>{\n msg.flowContext[ele]=flow.get(ele);\n});\nreturn msg;",
|
||||
"func": "msg.flowContext = {};\nflow.keys(\"file\").forEach(ele=>{\n msg.flowContext[\"(File)\"+ele]=flow.get(ele,\"file\");\n});\nflow.keys().forEach(ele=>{\n msg.flowContext[\"(Mem)\"+ele]=flow.get(ele);\n});\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1550,
|
||||
@@ -2051,7 +2051,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "FlowContext2msg",
|
||||
"func": "msg.flowContext = {};\nflow.keys().forEach(ele=>{\n msg.flowContext[ele]=flow.get(ele);\n});\nreturn msg;",
|
||||
"func": "msg.flowContext = {};\nflow.keys(\"file\").forEach(ele=>{\n msg.flowContext[\"(File)\"+ele]=flow.get(ele,\"file\");\n});\nflow.keys().forEach(ele=>{\n msg.flowContext[\"(Mem)\"+ele]=flow.get(ele);\n});\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1510,
|
||||
@@ -2067,7 +2067,7 @@
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "FlowContext2msg",
|
||||
"func": "msg.flowContext = {};\nflow.keys().forEach(ele=>{\n msg.flowContext[ele]=flow.get(ele);\n});\nreturn msg;",
|
||||
"func": "msg.flowContext = {};\nflow.keys(\"file\").forEach(ele=>{\n msg.flowContext[\"(File)\"+ele]=flow.get(ele,\"file\");\n});\nflow.keys().forEach(ele=>{\n msg.flowContext[\"(Mem)\"+ele]=flow.get(ele);\n});\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1550,
|
||||
@@ -2153,5 +2153,56 @@
|
||||
"x": 2040,
|
||||
"y": 780,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "d733ac19.e8d0b",
|
||||
"type": "function",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "FlowContext2msg",
|
||||
"func": "msg.flowContext = {};\nflow.keys(\"file\").forEach(ele=>{\n msg.flowContext[\"(File)\"+ele]=flow.get(ele,\"file\");\n});\nflow.keys().forEach(ele=>{\n msg.flowContext[\"(Mem)\"+ele]=flow.get(ele);\n});\n\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 190,
|
||||
"y": 340,
|
||||
"wires": [
|
||||
[
|
||||
"4c0a2364.56ae8c"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "4c0a2364.56ae8c",
|
||||
"type": "debug",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "true",
|
||||
"targetType": "full",
|
||||
"x": 310,
|
||||
"y": 280,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "53c12592.9e0d9c",
|
||||
"type": "inject",
|
||||
"z": "75185287.024c5c",
|
||||
"name": "",
|
||||
"topic": "",
|
||||
"payload": "",
|
||||
"payloadType": "date",
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": 0.1,
|
||||
"x": 100,
|
||||
"y": 280,
|
||||
"wires": [
|
||||
[
|
||||
"d733ac19.e8d0b"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user