Fix scaled trades for big jumps.

This commit is contained in:
Joe Tretter
2021-01-07 11:02:54 -06:00
parent 2164d63e96
commit 8693543bb2

View File

@@ -3840,7 +3840,7 @@
"type": "switch",
"z": "791ce869.901798",
"name": "MinVolReached?",
"property": "$flowContext('coinBalance') - $flowContext('multiplier') ",
"property": "$flowContext('coinBalance') - $flowContext('orderVolume') ",
"propertyType": "jsonata",
"rules": [
{
@@ -3916,7 +3916,7 @@
"type": "switch",
"z": "791ce869.901798",
"name": "MaxVolReached?",
"property": "$flowContext('coinBalance') + $flowContext('multiplier')",
"property": "$flowContext('coinBalance') + $flowContext('orderVolume')",
"propertyType": "jsonata",
"rules": [
{
@@ -3962,7 +3962,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\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.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\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\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.\nlet multiplier = Number(flow.get('multiplier'));\nlet jumpSize = Math.round(Math.abs(flow.get('lastExecPrice')-msg.price));\nflow.set(\"orderVolume\",jumpSize * multiplier);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 910,
@@ -3978,7 +3978,7 @@
"type": "function",
"z": "791ce869.901798",
"name": "BuildOrder (buy)",
"func": "let multiplier = Number(flow.get('multiplier'));\nlet pair = flow.get('pair');\n\nmsg.payload={\n\tpair : pair,\n\ttype : 'buy',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
"func": "msg.payload={\n\tpair : flow.get('pair'),\n\ttype : 'buy',\n\tordertype : 'market',\n\tvolume : flow.get('orderVolume')\n};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1960,
@@ -4023,7 +4023,7 @@
"type": "function",
"z": "791ce869.901798",
"name": "Buid Order (sell)",
"func": "let pair = flow.get('pair');\nlet multiplier = Number(flow.get('multiplier'));\n\nmsg.payload={\n\tpair : pair,\n\ttype : 'sell',\n\tordertype : 'market',\n\tvolume : multiplier\n};\n\nreturn msg;",
"func": "msg.payload={\n\tpair : flow.get('pair'),\n\ttype : 'sell',\n\tordertype : 'market',\n\tvolume : flow.get('orderVolume')\n};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1760,
@@ -4384,51 +4384,6 @@
]
]
},
{
"id": "90b1a878.2e9078",
"type": "inject",
"z": "791ce869.901798",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 100,
"y": 680,
"wires": [
[
"842629ff.39e1f8"
]
]
},
{
"id": "842629ff.39e1f8",
"type": "change",
"z": "791ce869.901798",
"name": "BUY",
"rules": [
{
"t": "set",
"p": "#:(file)::lastExecPrice",
"pt": "flow",
"to": "999",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 290,
"y": 680,
"wires": [
[]
]
},
{
"id": "f0e0540.34101b",
"type": "debug",
@@ -4603,139 +4558,6 @@
"y": 40,
"wires": []
},
{
"id": "a695a39b.f7902",
"type": "inject",
"z": "791ce869.901798",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 100,
"y": 760,
"wires": [
[
"5b6ededf.2ac89"
]
]
},
{
"id": "5b6ededf.2ac89",
"type": "change",
"z": "791ce869.901798",
"name": "Manual CoinBalance",
"rules": [
{
"t": "set",
"p": "coinBalance",
"pt": "flow",
"to": "6",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 760,
"wires": [
[]
]
},
{
"id": "a3d0d862.ac3b88",
"type": "inject",
"z": "791ce869.901798",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 100,
"y": 840,
"wires": [
[
"f6f269cb.ffcf18"
]
]
},
{
"id": "f6f269cb.ffcf18",
"type": "change",
"z": "791ce869.901798",
"name": "Manual LastExecPrice",
"rules": [
{
"t": "set",
"p": "#:(file)::lastExecPrice",
"pt": "flow",
"to": "154.96",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 840,
"wires": [
[]
]
},
{
"id": "d085c84b.b8d738",
"type": "inject",
"z": "791ce869.901798",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 100,
"y": 900,
"wires": [
[
"8253bf67.e626c"
]
]
},
{
"id": "8253bf67.e626c",
"type": "change",
"z": "791ce869.901798",
"name": "",
"rules": [
{
"t": "delete",
"p": "#:(file)::coinBalance",
"pt": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 900,
"wires": [
[]
]
},
{
"id": "322633db.979c1c",
"type": "inject",