misc fixes in volume calc

This commit is contained in:
Joe Tretter
2021-01-07 16:39:14 -06:00
parent b20a141daf
commit 468124421d

View File

@@ -3969,7 +3969,7 @@
"type": "function",
"z": "791ce869.901798",
"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 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\nlet jumpPrice=undefined;\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=jumpPrice=bidPrice;\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=jumpPrice=askPrice;\n} else {\n msg.action=\"nothing\";\n}\n\n// if there is a bigger gap we might need to order multiple \"packages\"\n// this is for example if the market violently jumps or a bigger down move is \n// happening due to server offline.\nif (jumpPrice!==undefined){\n let multiplier = flow.get('multiplier');\n let jumpSize = Math.round(Math.abs(lastExecPrice-jumpPrice)/delta);\n \n flow.set(\"orderVolume\",jumpSize * multiplier);\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\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;",
"outputs": 1,
"noerr": 0,
"x": 910,
@@ -6359,7 +6359,7 @@
"type": "function",
"z": "9d5ee7b4.680b68",
"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 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\nlet jumpPrice=undefined;\nif (bidPrice>lastExecPrice+delta) {\n msg.action=\"sell\";\n msg.price=jumpPrice=bidPrice;\n} else if (askPrice<lastExecPrice-delta) {\n msg.action=\"buy\";\n msg.price=jumpPrice=askPrice;\n} else {\n msg.action=\"nothing\";\n}\n\n// if there is a bigger gap we might need to order multiple \"packages\"\n// this is for example if the market violently jumps or a bigger down move is \n// happening due to server offline.\nif (jumpPrice!==undefined){\n let multiplier = flow.get('multiplier');\n let jumpSize = Math.round(Math.abs(lastExecPrice-jumpPrice)/delta);\n flow.set('debugjumpPrice',jumpPrice);\n flow.set('debugjumpSize',jumpSize);\n \n flow.set(\"orderVolume\",jumpSize * multiplier);\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\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;",
"outputs": 1,
"noerr": 0,
"x": 910,