Skip to content

Commit

Permalink
Beta long short states Callisto
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvilhelmsen committed Jan 15, 2024
1 parent 9b1d434 commit 06c8698
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
32 changes: 32 additions & 0 deletions strategies/callisto/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ class State extends BotState
// Return the backtracked candles volume relative to the average volume
return candles[1].volume / averageVolume * 100;
}

async targetHit(direction) {
this.setExitDetails(this.trade.targetPrice);

// Notify Slack that we hit the target
this.notifications.postSlackMessage(`:white_check_mark: Target Hit (${direction})!`, {
"Trade Reference": this.trade._id,
"Symbol": this.trade.symbol,
"Price": this.trade.targetPrice,
"P/L": `${this.calculateProfit(direction)}%`,
});

// Exit position
return await this.exitPosition();
}

async stoplossHit(direction, price, reason) {

this.setExitDetails(price, reason);

// Notify Slack that we hit the stoploss
this.notifications.postSlackMessage(`:x: Stoploss Hit (${direction})!`, {
"Trade Reference": this.trade._id,
"Symbol": this.trade.symbol,
"Price": price,
"P/L": `${this.calculateProfit(direction)}%`,
"Reason": reason
});

// Exit position
return await this.exitPosition();
}
}

module.exports = State;
18 changes: 17 additions & 1 deletion strategies/callisto/State_long.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@ class State_long extends State
}

// Fetch all indicators added both in this class and in State.js
await this.executeBulk().then( ta => {
await this.executeBulk().then( async ta => {

console.log("We're long!");

// Check target hit
if(this.isTargetHit(candles)) {

exitPositionResponse = await this.targetHit("long");
this.chainTrade();

}

// Check stoploss hit
else if(this.isStoplossHit(candles)) {

exitPositionResponse = await this.stoplossHit("long", this.trade.stoplossPrice, "Stoploss");
this.chainTrade();

}

});
}
}
Expand Down
19 changes: 17 additions & 2 deletions strategies/callisto/State_short.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ class State_short extends State
}

// Fetch all indicators added both in this class and in State.js
this.executeBulk().then( ta => {
this.executeBulk().then( async ta => {

console.log("We're short!");


// Check target hit
if(this.isTargetHit(candles)) {

exitPositionResponse = await this.targetHit("long");
this.chainTrade();

}

// Check stoploss hit
else if(this.isStoplossHit(candles)) {

exitPositionResponse = await this.stoplossHit("long", this.trade.stoplossPrice, "Stoploss");
this.chainTrade();

}
});
}
}
Expand Down

0 comments on commit 06c8698

Please sign in to comment.