Skip to content

Commit

Permalink
Update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
djkazic committed Nov 26, 2023
1 parent 1cecbec commit 00c0b52
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ async function loadModules() {
let profitableBuys = 0;
let sellPl = 0;
let buyPl = 0;
let changedPos = false;
let buyOrders = 0;
let sellOrders = 0;
let buyAvgPl = 0;
Expand All @@ -271,8 +270,7 @@ async function loadModules() {
sendTelegramMessage(
`Closed profitable short on LNM: fee ${position.opening_fee}, price ${position.price}, pl ${position.pl}`
);
changedPos = true;
} else if (position.pl < -20) {
} else if (position.pl < -10) {
logger(
"error",
`CLOSING SHORT POSITION AT LOSS ${JSON.stringify(position)}`
Expand All @@ -281,7 +279,6 @@ async function loadModules() {
sendTelegramMessage(
`Closed short at a loss on LNM: fee ${position.opening_fee}, price ${position.price}, pl ${position.pl}`
);
changedPos = true;
}
} else if (position.side === "b") {
buyOrders++;
Expand All @@ -297,8 +294,7 @@ async function loadModules() {
sendTelegramMessage(
`Closed profitable long on LNM: fee ${position.opening_fee}, price ${position.price}, pl ${position.pl}`
);
changedPos = true;
} else if (position.pl < -20) {
} else if (position.pl < -10) {
logger(
"error",
`CLOSING LONG POSITION AT LOSS ${JSON.stringify(position)}`
Expand All @@ -307,19 +303,17 @@ async function loadModules() {
sendTelegramMessage(
`Closed long at a loss on LNM: fee ${position.opening_fee}, price ${position.price}, pl ${position.pl}`
);
changedPos = true;
}
}
});
if (buyOrders > 0) {
if (buyOrders > 2) {
buyAvgPl = buyPl / buyOrders;
}
if (sellOrders > 0) {
if (sellOrders > 2) {
sellAvgPl = sellPl / sellOrders;
}
logger("info", `BuyAvgPl: ${buyAvgPl}, SellAvgPl: ${sellAvgPl}`);
// Reread positions
// if (changedPos) {
totalSellExposure = 0;
totalBuyExposure = 0;
await sleep(1000);
Expand All @@ -329,7 +323,7 @@ async function loadModules() {
runningPositions.forEach((position) => {
if (position.side === "s") {
totalSellExposure += position.quantity;
if (sellAvgPl > 0 && position.pl > sellAvgPl) {
if (sellAvgPl > 5 && position.pl > sellAvgPl) {
logger(
"finance-profit",
`CLOSING SHORT POSITION ${JSON.stringify(position)}`
Expand All @@ -343,7 +337,7 @@ async function loadModules() {
}
} else if (position.side === "b") {
totalBuyExposure += position.quantity;
if (buyAvgPl > 0 && position.pl > buyAvgPl) {
if (buyAvgPl > 5 && position.pl > buyAvgPl) {
logger(
"finance-profit",
`CLOSING LONG POSITION ${JSON.stringify(position)}`
Expand Down

0 comments on commit 00c0b52

Please sign in to comment.